• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright Louis Dionne 2013-2017
2 // Distributed under the Boost Software License, Version 1.0.
3 // (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
4 
5 #include <boost/hana/assert.hpp>
6 #include <boost/hana/concept/struct.hpp>
7 #include <boost/hana/contains.hpp>
8 #include <boost/hana/define_struct.hpp>
9 #include <boost/hana/string.hpp>
10 
11 #include <laws/base.hpp>
12 namespace hana = boost::hana;
13 using hana::test::ct_eq;
14 
15 
16 // This allows us to make sure we can enter template types
17 // containing commas in the macro.
18 template <typename T, typename ...>
19 using commas = T;
20 
21 struct Data0 {
22     BOOST_HANA_DEFINE_STRUCT(Data0);
23 };
24 struct Data1 {
25     BOOST_HANA_DEFINE_STRUCT(Data1,
26         (commas<ct_eq<1>, void>, member1)
27     );
28 };
29 struct Data2 {
30     BOOST_HANA_DEFINE_STRUCT(Data2,
31         (commas<ct_eq<1>, void, void>, member1),
32         (ct_eq<2>, member2)
33     );
34 };
35 struct Data3 {
36     BOOST_HANA_DEFINE_STRUCT(Data3,
37         (ct_eq<1>, member1),
38         (ct_eq<2>, member2),
39         (commas<ct_eq<3>, void, void, void>, member3)
40     );
41 };
42 
43 static_assert(hana::Struct<Data0>::value, "");
44 static_assert(hana::Struct<Data1>::value, "");
45 static_assert(hana::Struct<Data2>::value, "");
46 static_assert(hana::Struct<Data3>::value, "");
47 
main()48 int main() {
49     BOOST_HANA_CONSTANT_CHECK(hana::contains(Data1{}, BOOST_HANA_STRING("member1")));
50 
51     BOOST_HANA_CONSTANT_CHECK(hana::contains(Data2{}, BOOST_HANA_STRING("member1")));
52     BOOST_HANA_CONSTANT_CHECK(hana::contains(Data2{}, BOOST_HANA_STRING("member2")));
53 
54     BOOST_HANA_CONSTANT_CHECK(hana::contains(Data3{}, BOOST_HANA_STRING("member1")));
55     BOOST_HANA_CONSTANT_CHECK(hana::contains(Data3{}, BOOST_HANA_STRING("member2")));
56     BOOST_HANA_CONSTANT_CHECK(hana::contains(Data3{}, BOOST_HANA_STRING("member3")));
57 }
58