10 #include <boost/version.hpp> 27 class comparator2 :
public boost::static_visitor<int> {
28 template <
typename A,
typename B>
29 static bool cmp_(
const A& a,
const B& b) {
return (a==b)? 0 : (a<b)? -1:1; }
33 template <
typename LHS_T,
typename RHS_T>
34 int operator()(
const LHS_T& lhs,
const RHS_T& rhs)
const {
35 std::string lhs_name=detail::type_info<LHS_T>::pretty_name();
36 std::string rhs_name=detail::type_info<RHS_T>::pretty_name();
37 throw exception::type_mismatch(
"",
"Attempt to compare dictionary values containing " 38 "incompatible types "+
39 lhs_name +
"<=>" + rhs_name);
43 template <
typename LHS_RHS_T>
44 int operator()(
const LHS_RHS_T& lhs,
const LHS_RHS_T& rhs)
const {
62 class equals2 :
public boost::static_visitor<bool> {
65 template <
typename LHS_RHS_T>
66 bool operator()(
const LHS_RHS_T& lhs,
const LHS_RHS_T& rhs)
const {
71 template <
typename LHS_T,
typename RHS_T>
72 bool operator()(
const LHS_T& lhs,
const RHS_T& rhs)
const{
77 template <
typename RHS_T>
83 template <
typename LHS_T>
105 exc.
set_name(name_+
"<=>"+rhs.name_);
116 if (this->empty())
return;
117 alps::hdf5::write_variant<detail::dict_all_types>(ar, val_);
122 std::string::size_type slash_pos=context.find_last_of(
"/");
123 if (slash_pos==std::string::npos) slash_pos=0;
else ++slash_pos;
124 name_=context.substr(slash_pos);
125 val_=alps::hdf5::read_variant<detail::dict_all_types>(ar);
129 struct typestring_visitor :
public boost::static_visitor<std::string> {
130 template <
typename T>
131 std::string operator()(
const T& val)
const {
132 std::string ret=detail::type_info<T>::pretty_name();
139 template <
typename T>
140 inline std::ostream& operator<<(std::ostream& strm, const std::vector<T>& vec)
142 typedef std::vector<T> vtype;
143 typedef typename vtype::const_iterator itype;
146 itype it=vec.begin();
147 const itype end=vec.end();
151 for (++it; end!=it; ++it) {
160 struct print_visitor {
161 #if __cplusplus == 201402L && BOOST_VERSION == 105800 168 typedef std::ostream& result_type;
172 print_visitor(std::ostream& os) : os_(os) {}
174 template <
typename T>
175 std::ostream& operator()(
const T& val)
const {
180 throw std::logic_error(
"print_visitor: This is not expected to be called");
189 if (!terse) s <<
" (type: None)";
195 if (!terse) s <<
" (name='" << dv.name_ <<
"')";
204 broadcast<detail::dict_all_types>(comm, val_, root);
void set_name(const std::string &name)
void broadcast(C const &c, P &p, int r=0)
void save(alps::hdf5::archive &ar) const
Saves the value to an archive.
Exception for using uninitialized value.
Encapsulation of an MPI communicator and some communicator-related operations.
F::result_type apply_visitor(F &visitor, dictionary::const_iterator it)
Const-access visitor to a value by an iterator.
bool equals(const dict_value &rhs) const
Returns true if the objects hold the same type and value, false otherwise.
std::ostream & print(std::ostream &s, const dict_value &dv, bool terse)
bool empty() const
whether the value contains None
std::string get_context() const
Header for archiving interface for boost::variant.
void broadcast(const communicator &comm, T *vals, std::size_t count, int root)
Broadcasts array vals of a primitive type T, length count on communicator comm with root root ...
General exception (base class)
void load(alps::hdf5::archive &ar)
Loads the value from an archive.
detail::None None
"Empty value" type
int compare(const T &rhs) const
Comparison.