#include #include #include template struct map_list_of_transform { template auto operator() (boost::yap::call_tag, Fn const & fn, Key2 && key, Value2 && value) { boost::yap::transform(fn, *this); map.try_emplace( Key{std::forward(key)}, Value{std::forward(value)} ); return 0; } std::map map; }; template struct map_list_of_expr { using this_type = map_list_of_expr; static boost::yap::expr_kind const kind = Kind; Tuple elements; template operator std::map () const { map_list_of_transform transform; boost::yap::transform(*this, transform); return transform.map; } BOOST_YAP_USER_MEMBER_CALL_OPERATOR(this_type, ::map_list_of_expr) }; struct map_list_of_tag {}; auto map_list_of = boost::yap::make_terminal(map_list_of_tag{}); int main() { // Initialize a map: std::map op = map_list_of ("<", 1) ("<=",2) (">", 3) (">=",4) ("=", 5) ("<>",6) ; std::cout << "\"<\" --> " << op["<"] << std::endl; std::cout << "\"<=\" --> " << op["<="] << std::endl; std::cout << "\">\" --> " << op[">"] << std::endl; std::cout << "\">=\" --> " << op[">="] << std::endl; std::cout << "\"=\" --> " << op["="] << std::endl; std::cout << "\"<>\" --> " << op["<>"] << std::endl; return 0; }