]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/yap/perf/map_assign_code_gen.cpp
1 // Copyright (C) 2016-2018 T. Zachary Laine
3 // Distributed under the Boost Software License, Version 1.0. (See
4 // accompanying file LICENSE_1_0.txt or copy at
5 // http://www.boost.org/LICENSE_1_0.txt)
6 #include <boost/yap/expression.hpp>
8 #include <boost/assign/list_of.hpp>
14 template<typename Key
, typename Value
, typename Allocator
>
15 struct map_list_of_transform
17 template<typename Fn
, typename Key2
, typename Value2
>
19 boost::yap::expr_tag
<boost::yap::expr_kind::call
>,
24 boost::yap::transform(
25 boost::yap::as_expr
<boost::yap::minimal_expr
>(fn
), *this);
27 Key
{std::forward
<Key2
&&>(key
)},
28 Value
{std::forward
<Value2
&&>(value
)});
32 std::map
<Key
, Value
, Allocator
> map
;
36 template<boost::yap::expr_kind Kind
, typename Tuple
>
37 struct map_list_of_expr
39 static boost::yap::expr_kind
const kind
= Kind
;
43 template<typename Key
, typename Value
, typename Allocator
>
44 operator std::map
<Key
, Value
, Allocator
>() const
46 map_list_of_transform
<Key
, Value
, Allocator
> transform
;
47 boost::yap::transform(*this, transform
);
51 BOOST_YAP_USER_CALL_OPERATOR(::map_list_of_expr
)
54 struct map_list_of_tag
58 boost::yap::make_terminal
<map_list_of_expr
>(map_list_of_tag
{});
61 #if __GNUC__ || __clang__
62 #define NOINLINE __attribute__((noinline))
68 NOINLINE
std::map
<std::string
, int> make_map_with_boost_yap()
70 return map_list_of("<", 1)("<=", 2)(">", 3)(">=", 4)("=", 5)("<>", 6);
74 NOINLINE
std::map
<std::string
, int> make_map_with_boost_assign()
76 return boost::assign::map_list_of("<", 1)("<=", 2)(">", 3)(">=", 4)("=", 5)(
81 NOINLINE
std::map
<std::string
, int> make_map_manually()
83 std::map
<std::string
, int> retval
;
84 retval
.emplace("<", 1);
85 retval
.emplace("<=", 2);
86 retval
.emplace(">", 3);
87 retval
.emplace(">=", 4);
88 retval
.emplace("=", 5);
89 retval
.emplace("<>", 6);
94 NOINLINE
std::map
<std::string
, int> make_map_inializer_list()
96 std::map
<std::string
, int> retval
= {
97 {"<", 1}, {"<=", 2}, {">", 3}, {">=", 4}, {"=", 5}, {"<>", 6}};
105 std::map
<std::string
, int> op
= make_map_with_boost_yap();
107 std::cout
<< "\"<\" --> " << op
["<"] << std::endl
;
108 std::cout
<< "\"<=\" --> " << op
["<="] << std::endl
;
109 std::cout
<< "\">\" --> " << op
[">"] << std::endl
;
110 std::cout
<< "\">=\" --> " << op
[">="] << std::endl
;
111 std::cout
<< "\"=\" --> " << op
["="] << std::endl
;
112 std::cout
<< "\"<>\" --> " << op
["<>"] << std::endl
;
116 std::map
<std::string
, int> op
= make_map_with_boost_assign();
118 std::cout
<< "\"<\" --> " << op
["<"] << std::endl
;
119 std::cout
<< "\"<=\" --> " << op
["<="] << std::endl
;
120 std::cout
<< "\">\" --> " << op
[">"] << std::endl
;
121 std::cout
<< "\">=\" --> " << op
[">="] << std::endl
;
122 std::cout
<< "\"=\" --> " << op
["="] << std::endl
;
123 std::cout
<< "\"<>\" --> " << op
["<>"] << std::endl
;
127 std::map
<std::string
, int> op
= make_map_manually();
129 std::cout
<< "\"<\" --> " << op
["<"] << std::endl
;
130 std::cout
<< "\"<=\" --> " << op
["<="] << std::endl
;
131 std::cout
<< "\">\" --> " << op
[">"] << std::endl
;
132 std::cout
<< "\">=\" --> " << op
[">="] << std::endl
;
133 std::cout
<< "\"=\" --> " << op
["="] << std::endl
;
134 std::cout
<< "\"<>\" --> " << op
["<>"] << std::endl
;
138 std::map
<std::string
, int> op
= make_map_inializer_list();
140 std::cout
<< "\"<\" --> " << op
["<"] << std::endl
;
141 std::cout
<< "\"<=\" --> " << op
["<="] << std::endl
;
142 std::cout
<< "\">\" --> " << op
[">"] << std::endl
;
143 std::cout
<< "\">=\" --> " << op
[">="] << std::endl
;
144 std::cout
<< "\"=\" --> " << op
["="] << std::endl
;
145 std::cout
<< "\"<>\" --> " << op
["<>"] << std::endl
;