TRIQS/TRIQS 4.0.0
Researching Interacting Quantum Systems
Loading...
Searching...
No Matches
mc_measure_aux_set.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-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: Michel Ferrero, Olivier Parcollet, Nils Wentzell
19
24
25#pragma once
26
27#include <concepts>
28#include <memory>
29
30namespace triqs::mc_tools {
31
45 private:
46 // Auxiliary MC measure concept defines the interface for auxiliary MC measures.
47 struct measure_aux_concept {
48 virtual ~measure_aux_concept() = default;
49 virtual void call() = 0;
50 };
51
52 // Auxiliary MC measure model implements the auxiliary MC measure concept by calling the appropriate methods of the
53 // type earased object.
54 template <typename T>
55 requires(std::invocable<T>)
56 struct measure_aux_model : public measure_aux_concept {
57 std::shared_ptr<T> ptr_;
58 measure_aux_model(std::shared_ptr<T> const &m_ptr) : ptr_{m_ptr} {}
59 void call() override { return (*ptr_)(); }
60 };
61
62 public:
69 template <typename T>
70 requires(std::invocable<T>)
71 measure_aux(std::shared_ptr<T> const &m_ptr) : ptr_{std::make_unique<measure_aux_model<T>>(m_ptr)} {}
72
74 void operator()() { ptr_->call(); }
75
76 private:
77 std::unique_ptr<measure_aux_concept> ptr_;
78 };
79
80} // namespace triqs::mc_tools
void operator()()
Function call operator performs the auxiliary measurement.
measure_aux(std::shared_ptr< T > const &m_ptr)
Constructor takes an object that is callable and erases its type.