45#if __cpp_explicit_this_parameter >= 202110L
46template <
typename Self,
typename... Args>
decltype(
auto)
operator()(
this Self &&self, Args &&...args) {
48template <
typename Self,
typename... Args>
static decltype(
auto)
call_impl(Self &&self, Args &&...args) {
50 if constexpr (
sizeof...(Args) == 0) {
51 if constexpr (std::is_const_v<std::remove_reference_t<Self>>)
52 return const_view_type{std::forward<Self>(self)};
54 return view_type{std::forward<Self>(self)};
56 static_assert((
sizeof...(Args) == n_variables<mesh_t>),
"Incorrect number of arguments");
57 if constexpr ((... or clef::is_any_lazy<Args>))
58 return clef::make_expr_call(std::forward<Self>(self), std::forward<Args>(args)...);
60 return gf_evaluator<mesh_t>{}(std::forward<Self>(self), std::forward<Args>(args)...);
63#if __cpp_explicit_this_parameter < 202110L
65template <
typename... Args>
decltype(
auto)
operator()(Args &&...args)
const & {
return call_impl(*
this, std::forward<Args>(args)...); }
67template <
typename... Args>
decltype(
auto)
operator()(Args &&...args) & {
return call_impl(*
this, std::forward<Args>(args)...); }
69template <
typename... Args>
decltype(
auto)
operator()(Args &&...args) && {
return call_impl(std::move(*
this), std::forward<Args>(args)...); }
75#ifdef NDA_ENFORCE_BOUNDCHECK
91template <
typename... T>
93 requires(
sizeof...(T) == arity)
95 return std::apply([
this](
auto &...x) ->
decltype(
auto) {
return this->
operator[](x...); }, tu);
99template <
typename... T>
101 requires(
sizeof...(T) == arity)
103 return std::apply([
this](
auto &...x) ->
decltype(
auto) {
return this->
operator[](x...); }, tu);
108template <Mesh MT,
typename X>
static auto call_to_data_index(MT
const &m, X
const &x) {
109 if constexpr (std::is_same_v<X, all_t>)
111 else if constexpr (std::is_same_v<X, typename MT::mesh_point_t>) {
112 static_assert(std::is_same_v<X, typename MT::mesh_point_t>,
"Incompatible mesh_point type passed to a gf via [] operator.");
113 EXPECTS_WITH_MESSAGE(m.mesh_hash() == x.mesh_hash(),
114 "Passing to a gf a mesh point of incompatible mesh (but correct type), e.g. different beta, or other parameter.");
115 return x.data_index();
117 return m.to_data_index(x);
123template <
typename Self,
typename... Arg>
124static decltype(
auto) _subscript_impl(Self &&self, Arg &&...arg)
125 requires(
sizeof...(Arg) == arity)
127 if constexpr ((clef::is_any_lazy<Arg> or ... or
false))
128 return clef::make_expr_subscript(std::forward<Self>(self), std::forward<Arg>(arg)...);
131 static constexpr auto mesh_filter = std::array<int,
sizeof...(Arg)>{std::is_same_v<range::all_t, std::decay_t<Arg>>...};
132 static constexpr auto n_all = std::accumulate(
begin(mesh_filter),
end(mesh_filter), 0);
134 decltype(
auto) new_data = [&self,
135 &arg...]<
size_t... Is>(std::index_sequence<Is...>) ->
decltype(
auto) {
136 return data_t::template call<(target_t::is_matrix and n_all == 0 ? 'M' : 'A'), false>(
137 std::forward<Self>(self)._data, this_t::call_to_data_index(get_mesh<Is>(self), std::forward<Arg>(arg))..., ellipsis{});
138 }(std::make_index_sequence<arity>{});
140 if constexpr (n_all == 0)
144 auto new_mesh = detail::filter_mesh<detail::compute_position<n_all>(mesh_filter)>(self.mesh());
145 using self_t = std::remove_reference_t<Self>;
146 if constexpr (self_t::is_const or std::is_const_v<self_t>)
147 return gf_const_view<
decltype(new_mesh),
typename self_t::target_t>{std::move(new_mesh), new_data};
149 return gf_view<
decltype(new_mesh),
typename self_t::target_t>{std::move(new_mesh), new_data};
168template <
typename... Arg>
170 requires(
sizeof...(Arg) == arity)
172 return _subscript_impl(*
this, std::forward<Arg>(arg)...);
176template <
typename... Arg>
178 requires(
sizeof...(Arg) == arity)
180 return _subscript_impl(*
this, std::forward<Arg>(arg)...);
184template <
typename... Arg>
186 requires(
sizeof...(Arg) == arity)
188 return _subscript_impl(std::move(*
this), std::forward<Arg>(arg)...);
200 return this_t::operator[]<
typename mesh_t::index_t
const &>(index);
212friend struct gf_h5_rw<M, Target>;
221friend void h5_write(h5::group fg, std::string
const &subgroup_name, this_t
const &g) {
222 auto gr = fg.create_group(subgroup_name);
223 write_hdf5_format(gr, g);
224 gf_h5_rw<M, Target>::write(gr, g);
236friend void h5_read(h5::group fg, std::string
const &subgroup_name, this_t &g) {
237 auto gr = fg.open_group(subgroup_name);
238 auto tag_file = read_hdf5_format(gr);
239 if (!(tag_file[0] ==
'G' and tag_file[1] ==
'f'))
240 TRIQS_RUNTIME_ERROR <<
"h5_read : For a Green function, the type tag should be Gf (or Gfxxxx for old archive) "
241 <<
" while I found " << tag_file;
242 gf_h5_rw<M, Target>::read(gr, g);
252friend std::ostream &
operator<<(std::ostream &out, this_t
const &) {
return out <<
"this_t"; }
iterator end()
Get an iterator past the last block.
iterator begin()
Get an iterator to the first block.
friend std::ostream & operator<<(std::ostream &out, this_t const &)
Write a Green's function to an output stream.
friend void h5_read(h5::group fg, std::string const &subgroup_name, this_t &g)
Read a Green's function from HDF5.
static constexpr bool has_no_boundcheck
Whether bound checking of the data array is disabled (controlled by NDA_ENFORCE_BOUNDCHECK).
friend void h5_write(h5::group fg, std::string const &subgroup_name, this_t const &g)
Write a Green's function to HDF5.
static std::string hdf5_format()
Get the HDF5 format tag of a Green's function.
static decltype(auto) call_impl(Self &&self, Args &&...1)
Evaluate the Green's function at the given arguments.
decltype(auto) operator[](std::tuple< T... > const &tu) const noexcept(has_no_boundcheck)
Access the Green's function at a mesh point/index passed as a tuple (const overload).
#define TRIQS_RUNTIME_ERROR
Throw a triqs::runtime_error with the current source location.