TRIQS/TRIQS 4.0.0
Researching Interacting Quantum Systems
Loading...
Searching...
No Matches
expression_template_tools.hpp
Go to the documentation of this file.
1// Copyright (c) 2013-2018 Commissariat à l'énergie atomique et aux énergies alternatives (CEA)
2// Copyright (c) 2013-2018 Centre national de la recherche scientifique (CNRS)
3// Copyright (c) 2018-2023 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: Olivier Parcollet, Nils Wentzell
19
24
25#pragma once
26
27#include "./macros.hpp"
28
29#include <complex>
30#include <type_traits>
31#include <utility>
32
33namespace triqs::utility {
34
39
48 template <class T> struct remove_rvalue_ref {
49 using type = T;
50 };
51 template <class T> struct remove_rvalue_ref<T &> {
52 using type = T const &;
53 };
54 template <class T> struct remove_rvalue_ref<T &&> {
55 using type = T;
56 };
57
59 template <class T> using remove_rvalue_ref_t = typename remove_rvalue_ref<T>::type;
60
62 namespace tags {
63
65 struct plus {};
66
68 struct minus {};
69
71 struct multiplies {};
72
74 struct divides {};
75
76 } // namespace tags
77
86 template <typename Tag> struct operation;
87
88 // Spezialization of triqs::utility::operation for plus operation: returns `l + r`.
89 template <> struct operation<tags::plus> {
90 static const char name = '+';
91 template <typename L, typename R> auto operator()(L &&l, R &&r) const DECL_AND_RETURN(std::forward<L>(l) + std::forward<R>(r))
92 };
93
94 // Spezialization of triqs::utility::operation for minus operation: returns `l - r`.
95 template <> struct operation<tags::minus> {
96 static const char name = '-';
97 template <typename L, typename R> auto operator()(L &&l, R &&r) const DECL_AND_RETURN(std::forward<L>(l) - std::forward<R>(r))
98 };
99
100 // Spezialization of triqs::utility::operation for multiplies operation: returns `l * r`.
101 template <> struct operation<tags::multiplies> {
102 static const char name = '*';
103 template <typename L, typename R> auto operator()(L &&l, R &&r) const DECL_AND_RETURN(std::forward<L>(l) * std::forward<R>(r))
104 };
105
106 // Spezialization of triqs::utility::operation for divides operation: returns `l / r`.
107 template <> struct operation<tags::divides> {
108 static const char name = '/';
109 template <typename L, typename R> auto operator()(L &&l, R &&r) const DECL_AND_RETURN(std::forward<L>(l) / std::forward<R>(r))
110 };
111
119 template <typename T> struct is_in_ZRC : std::is_arithmetic<T> {};
120 template <> struct is_in_ZRC<bool> : std::true_type {};
121 template <typename T> struct is_in_ZRC<std::complex<T>> : std::true_type {};
122 template <typename T> struct is_in_ZRC<T &> : is_in_ZRC<T> {};
123 template <typename T> struct is_in_ZRC<T &&> : is_in_ZRC<T> {};
124 template <typename T> struct is_in_ZRC<const T> : is_in_ZRC<T> {};
125
134 template <typename A, typename B> struct type_of_mult {
135 using type = decltype(std::declval<std::remove_reference_t<A>>() * std::declval<std::remove_reference_t<B>>());
136 };
137
139
140} // namespace triqs::utility
const_view_type operator()() const
Make a const view of *this.
#define DECL_AND_RETURN(...)
Trailing-return-type convenience: expands to -> decltype(...) { return ...; }.
Definition macros.hpp:41
typename remove_rvalue_ref< T >::type remove_rvalue_ref_t
Alias for the nested type in remove_rvalue_ref.
Common macros used in TRIQS.
Namespace for empty tag types identifying the four basic arithmetic operations used in expression tem...
Trait identifying types that lie in .
Callable wrapper that evaluates the operation identified by Tag on two operands.
Strip rvalue references from T while turning lvalue references into const &.
Trait whose nested type is decltype(a * b) with cv-/ref-qualifiers stripped from the operands.