1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
|
// Copyright Daniel Wallin 2005.
// Copyright Cromwell D. Enage 2019.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
namespace test {
struct default_src
{
typedef int result_type;
int operator()() const
{
return 0;
}
};
} // namespace test
#include <boost/parameter/name.hpp>
namespace test {
BOOST_PARAMETER_NAME(x)
BOOST_PARAMETER_NAME(y)
BOOST_PARAMETER_NAME(z)
} // namespace test
#include <boost/parameter/is_argument_pack.hpp>
#include <boost/parameter/config.hpp>
#include <boost/mpl/has_key.hpp>
#include <boost/mpl/assert.hpp>
#include <boost/core/lightweight_test.hpp>
#if defined(BOOST_PARAMETER_CAN_USE_MP11)
#include <boost/mp11/map.hpp>
#include <type_traits>
#endif
namespace test {
template <typename ArgumentPack, typename K, typename T>
void check0(ArgumentPack const& p, K const& kw, T const& value)
{
#if defined(BOOST_PARAMETER_CAN_USE_MP11)
static_assert(
!boost::mp11::mp_map_contains<ArgumentPack,test::tag::z>::value
, "test::tag::z must not be in ArgumentPack"
);
static_assert(
std::is_same<
boost::mp11::mp_map_find<ArgumentPack,test::tag::z>
, void
>::value
, "test::tag::z must not be found in ArgumentPack"
);
#endif // BOOST_PARAMETER_CAN_USE_MP11
BOOST_MPL_ASSERT((boost::parameter::is_argument_pack<ArgumentPack>));
BOOST_MPL_ASSERT_NOT((
boost::mpl::has_key<ArgumentPack,test::tag::z>
));
BOOST_TEST_EQ(p[kw], value);
}
} // namespace test
#include <boost/mpl/void.hpp>
#include <boost/mpl/bool.hpp>
#include <boost/mpl/int.hpp>
#include <boost/mpl/if.hpp>
#include <boost/mpl/key_type.hpp>
#include <boost/mpl/order.hpp>
#include <boost/mpl/count.hpp>
#include <boost/mpl/equal_to.hpp>
#include <boost/type_traits/is_same.hpp>
namespace test {
template <typename ArgumentPack, typename K, typename T>
void check1(ArgumentPack const& p, K const& kw, T const& value)
{
#if defined(BOOST_PARAMETER_CAN_USE_MP11)
static_assert(
boost::mp11::mp_map_contains<ArgumentPack,typename K::tag>::value
, "typename K::tag must be in ArgumentPack"
);
static_assert(
!boost::mp11::mp_map_contains<ArgumentPack,test::tag::z>::value
, "test::tag::z must not be in ArgumentPack"
);
static_assert(
!std::is_same<
boost::mp11::mp_map_find<ArgumentPack,typename K::tag>
, void
>::value
, "typename K::tag must be found in ArgumentPack"
);
static_assert(
std::is_same<
boost::mp11::mp_map_find<ArgumentPack,test::tag::z>
, void
>::value
, "test::tag::z must not be found in ArgumentPack"
);
#endif // BOOST_PARAMETER_CAN_USE_MP11
BOOST_MPL_ASSERT((boost::parameter::is_argument_pack<ArgumentPack>));
BOOST_MPL_ASSERT((boost::mpl::has_key<ArgumentPack,typename K::tag>));
BOOST_MPL_ASSERT_NOT((
boost::mpl::has_key<ArgumentPack,test::tag::z>
));
BOOST_MPL_ASSERT((
boost::mpl::equal_to<
typename boost::mpl::count<ArgumentPack,typename K::tag>::type
, boost::mpl::int_<1>
>
));
BOOST_MPL_ASSERT((
typename boost::mpl::if_<
boost::is_same<
typename boost::mpl
::key_type<ArgumentPack,typename K::tag>::type
, typename K::tag
>
, boost::mpl::true_
, boost::mpl::false_
>::type
));
BOOST_MPL_ASSERT((
typename boost::mpl::if_<
boost::is_same<
typename boost::mpl
::order<ArgumentPack,typename K::tag>::type
, boost::mpl::void_
>
, boost::mpl::false_
, boost::mpl::true_
>::type
));
BOOST_TEST_EQ(p[kw], value);
}
} // namespace test
int main()
{
test::check1(test::_x = 20, test::_x, 20);
test::check1(test::_y = 20, test::_y, 20);
test::check0(test::_x = 20, test::_x | 0, 20);
test::check0(test::_y = 20, test::_y | 0, 20);
test::check0(test::_x = 20, test::_x || test::default_src(), 20);
test::check0(test::_y = 20, test::_y || test::default_src(), 20);
test::check0(test::_y = 20, test::_x | 0, 0);
test::check0(test::_y = 20, test::_x || test::default_src(), 0);
return boost::report_errors();
}
|