11 namespace accumulators {
21 struct copy_visitor:
public boost::static_visitor<> {
22 copy_visitor(detail::variant_type & s):
self(s) {}
23 template<
typename T>
void operator()(T
const & arg)
const {
24 const_cast<detail::variant_type &
>(
self) = T(arg->clone());
26 detail::variant_type &
self;
31 copy_visitor visitor(m_variant);
42 struct result_wrapper::assign_visitor:
public boost::static_visitor<> {
44 template<
typename T>
void operator()(T & arg)
const {
45 self->m_variant = arg;
58 struct count_visitor:
public boost::static_visitor<boost::uint64_t> {
59 template<
typename T> boost::uint64_t operator()(T
const & arg)
const {
64 count_visitor visitor;
72 struct save_visitor:
public boost::static_visitor<> {
74 template<
typename T>
void operator()(T & arg)
const { ar[
""] = *arg; }
85 struct load_visitor:
public boost::static_visitor<> {
87 template<
typename T>
void operator()(T
const & arg)
const { ar[
""] >> *arg; }
98 struct print_visitor:
public boost::static_visitor<> {
99 print_visitor(std::ostream & o,
bool t): os(o), terse(t) {}
100 template<
typename T>
void operator()(T
const & arg)
const { arg->print(os, terse); }
120 struct unary_add_visitor :
public boost::static_visitor<> {
121 template<
typename X>
void operator()(X & arg)
const {
127 unary_add_visitor visitor;
144 #define ALPS_ACCUMULATOR_OPERATOR_PROXY(OPNAME, AUGOPNAME, AUGOP, FUN) \ 145 template<typename LHSWT> struct FUN ## _arg_visitor: public boost::static_visitor<> { \ 146 FUN ## _arg_visitor(LHSWT & v): lhs_value(v) {} \ 147 template<typename RHSWT> \ 148 void apply(const RHSWT&, \ 149 typename std::enable_if<!detail::is_compatible_op<LHSWT,RHSWT>::value >::type* =0) const { \ 150 throw std::logic_error("only results with compatible value types are allowed in operators" \ 151 + ALPS_STACKTRACE); \ 153 template<typename RHSWT> \ 154 void apply(const RHSWT& rhs_value, \ 155 typename std::enable_if<detail::is_compatible_op<LHSWT,RHSWT>::value >::type* =0) { \ 156 lhs_value AUGOP rhs_value; \ 158 void apply(LHSWT const & rhs_value) { \ 159 lhs_value AUGOP rhs_value; \ 161 template<typename RHSPT> void operator()(RHSPT const & rhs_ptr) { \ 166 struct result_wrapper:: FUN ## _self_visitor: public boost::static_visitor<> { \ 167 FUN ## _self_visitor(result_wrapper const & v): rhs_value(v) {} \ 168 template<typename LHSPT> void operator()(LHSPT & self) const { \ 169 FUN ## _arg_visitor<typename LHSPT::element_type> visitor(*self); \ 170 boost::apply_visitor(visitor, rhs_value.m_variant); \ 172 result_wrapper const & rhs_value; \ 177 struct FUN ## _ldouble_visitor: public boost::static_visitor<> { \ 178 FUN ## _ldouble_visitor(long double v): value(v) {} \ 179 template<typename X> void operator()(X & arg) const { \ 185 result_wrapper & result_wrapper:: AUGOPNAME (result_wrapper const & rhs) { \ 186 FUN ## _self_visitor visitor(rhs); \ 187 boost::apply_visitor(visitor, m_variant); \ 191 result_wrapper & result_wrapper:: AUGOPNAME (long double arg) { \ 192 FUN ## _ldouble_visitor visitor(arg); \ 193 boost::apply_visitor(visitor, m_variant); \ 196 result_wrapper result_wrapper:: OPNAME (result_wrapper const & arg) const { \ 197 result_wrapper clone(*this); \ 202 result_wrapper result_wrapper:: OPNAME (long double arg) const { \ 203 result_wrapper clone(*this); \ 211 #undef ALPS_ACCUMULATOR_OPERATOR_PROXY 217 struct inverse_visitor:
public boost::static_visitor<> {
218 template<
typename T>
void operator()(T & arg)
const { arg->inverse(); }
230 #define ALPS_ACCUMULATOR_FUNCTION_PROXY(FUN) \ 231 struct FUN ## _visitor: public boost::static_visitor<> { \ 232 template<typename T> void operator()(T & arg) const { \ 236 result_wrapper result_wrapper:: FUN () const { \ 237 result_wrapper clone(*this); \ 238 boost::apply_visitor( FUN ## _visitor(), clone.m_variant); \ 256 #undef ALPS_ACCUMULATOR_FUNCTION_PROXY 262 #define EXTERNAL_FUNCTION(FUN) \ 263 result_wrapper FUN (result_wrapper const & arg) { \ 264 return arg. FUN (); \ 282 #undef EXTERNAL_FUNCTION 286 std::ostringstream ostr;
287 arg.
print(ostr,
true);
293 std::ostringstream ostr;
294 arg.
print(ostr,
false);
result_wrapper cosh() const
result_wrapper asin() const
#define ALPS_ACCUMULATOR_OPERATOR_PROXY(OPNAME, AUGOPNAME, AUGOP, FUN)
result_wrapper abs() const
detail::printable_type short_print(const result_wrapper &arg)
Return an "ostream-able" object to print result in a terse format.
result_wrapper sq() const
result_wrapper sin() const
F::result_type apply_visitor(F &visitor, dictionary::const_iterator it)
Const-access visitor to a value by an iterator.
#define ALPS_ACCUMULATOR_FUNCTION_PROXY(FUN)
result_wrapper sinh() const
result_wrapper cos() const
std::ostream & operator<<(std::ostream &os, const result_wrapper &arg)
detail::printable_type full_print(const result_wrapper &arg)
Return an "ostream-able" object to print result in a verbose format.
void load(hdf5::archive &ar)
void print(std::ostream &os, bool terse=false) const
result_wrapper tan() const
result_wrapper atan() const
#define EXTERNAL_FUNCTION(FUN)
result_wrapper sqrt() const
boost::uint64_t count() const
result_wrapper tanh() const
result_wrapper cbrt() const
result_wrapper log() const
void save(hdf5::archive &ar) const
result_wrapper & operator=(std::shared_ptr< result_wrapper > const &rhs)
result_wrapper cb() const
result_wrapper operator-() const
result_wrapper inverse() const
result_wrapper acos() const
result_wrapper operator+() const