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