diff --git a/test/triqs/parameters/default.cpp b/test/triqs/parameters/default.cpp index 040f5ef0..897683de 100644 --- a/test/triqs/parameters/default.cpp +++ b/test/triqs/parameters/default.cpp @@ -9,24 +9,21 @@ int main() { parameters P,P2; parameter_defaults pdef; - pdef.required - ( "A", int(), "really ?") - ; + pdef.required ( "A", int(), "really ?") ; - pdef.optional - ( "B", short(0), " short ") - ( "C", 1u, " unsigned short ") - ( "D", int(2), " int ") - ( "E", 3u, " unsigned int ") - ( "F", long(4), " long ") - ( "G", 5ll, " long ") - ( "H", float(6), " float ") - ( "I", double(7.8), " doube ") - // ( "K", std::complex(12), " double complex ") - ( "L", std::string("13"), " string ") - // ( "M", std::vector { 1,4 }, " vector ") - ( "N", double(15), "") - ( "W", int(16), "") + pdef.optional( "B", short(0), " short ") + .optional( "C", 1u, " unsigned short ") + .optional( "D", int(2), " int ") + .optional( "E", 3u, " unsigned int ") + .optional( "F", long(4), " long ") + .optional( "G", 5ll, " long ") + .optional( "H", float(6), " float ") + .optional( "I", double(7.8), " doube ") + .optional( "K", std::complex(12), " double complex ") + .optional( "L", std::string("13"), " string ") + .optional( "M", std::vector { 1,4 }, " vector ") + .optional( "N", double(15), "") + .optional( "W", int(16), "") ; P["a"] = long(1); diff --git a/triqs/parameters/defaults.hpp b/triqs/parameters/defaults.hpp index c14e0749..6d5c5a25 100644 --- a/triqs/parameters/defaults.hpp +++ b/triqs/parameters/defaults.hpp @@ -49,18 +49,12 @@ namespace triqs { namespace utility { template void serialize(Archive & ar, const unsigned int version) { ar & boost::serialization::make_nvp("object_map",object_map); } - struct _inserter { - parameter_defaults * p; bool opt; - _inserter(parameter_defaults *p_, bool opt_) : p(p_), opt(opt_) {} - template _inserter operator()(std::string const & key, T && def_val, std::string const & doc) { - p->object_map[key] = std::forward(def_val); - p->documentation[key] = doc; - p->is_optional[key] = opt; - return *this; - } - - }; - friend struct _inserter; + template parameter_defaults & insert(std::string const & key, T && def_val, std::string const & doc, bool opt) { + object_map[key] = std::forward(def_val); + documentation[key] = doc; + is_optional[key] = opt; + return *this; + } template const T getter(std::map const & m, std::string const & key) const { auto it = m.find(key); assert(it !=m.end()); return it->second; @@ -79,19 +73,19 @@ namespace triqs { namespace utility { bool is_required(std::string const & key) const { return (has_key(key) && (! getter(this->is_optional,key)));} std::string doc(std::string const & key) const { return (has_key(key) ? getter(this->documentation,key) : "");} - ///inserter for optional parameters; - ///calls can be chained for multiple parameters - template - _inserter optional (std::string const & key, T && def_val, std::string const & doc) { - return _inserter(this, true)(key,std::forward(def_val), doc); - } + /// inserter for optional parameters; + /// calls can be chained for multiple parameters + template parameter_defaults &optional(std::string const &key, T &&def_val, std::string const &doc) { + insert(key, std::forward(def_val), doc, true); + return *this; + } - ///inserter for required parameters; - ///calls can be chained for multiple parameters - template - _inserter required (std::string const & key, T && def_val, std::string const & doc) { - return _inserter(this, false)(key,std::forward(def_val), doc); - } + /// inserter for required parameters; + /// calls can be chained for multiple parameters + template parameter_defaults &required(std::string const &key, T &&def_val, std::string const &doc) { + insert(key, std::forward(def_val), doc, false); + return *this; + } ///parameters class-like element access _object const & operator[](std::string const & key) const {