TRIQS/TRIQS 4.0.0
Researching Interacting Quantum Systems
Loading...
Searching...
No Matches
variant_extensions.hpp
Go to the documentation of this file.
1// Copyright (c) 2018 Commissariat à l'énergie atomique et aux énergies alternatives (CEA)
2// Copyright (c) 2018 Centre national de la recherche scientifique (CNRS)
3// Copyright (c) 2018-2020 Simons Foundation
4//
5// This program is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// This program is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You may obtain a copy of the License at
16// https://www.gnu.org/licenses/gpl-3.0.txt
17//
18// Authors: Igor Krivenko, Nils Wentzell
19
24
25#pragma once
26
27#include <nda/stdutil/array.hpp>
28
29#include <sstream>
30#include <string>
31#include <variant>
32#include <vector>
33
34namespace triqs::utility {
35
44 template <typename... Fs> struct overloaded : Fs... {
45 using Fs::operator()...;
46 };
47
48} // namespace triqs::utility
49
50namespace std {
51
56
66 template <typename T, typename... Ts> std::ostream &operator<<(std::ostream &os, std::variant<T, Ts...> const &v) {
67 visit([&os](auto const &x) { os << x; }, v);
68 return os;
69 }
70
80 template <typename T, typename... Ts> std::ostream &operator<<(std::ostream &os, std::vector<std::variant<T, Ts...>> const &vec) {
81 int u = 0;
82 for (auto const &i : vec) {
83 if (u++) os << ",";
84 os << i;
85 }
86 return os;
87 }
88
90 inline string to_string(string const &str) { return str; }
91
102 template <typename T, typename... Ts> inline string to_string(variant<T, Ts...> const &var) {
103 stringstream ss;
104 ss << var;
105 return ss.str();
106 }
107
109
110} // namespace std
std::ostream & operator<<(std::ostream &os, std::tuple< T... > const &t)
Write a std::tuple to an output stream.
string to_string(string const &str)
Identity overload for std::string.
Lambda-overload helper for std::visit.