• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*=============================================================================
2     Copyright (c) 1999-2003 Jaakko Jarvi
3     Copyright (c) 2001-2011 Joel de Guzman
4 
5     Distributed under the Boost Software License, Version 1.0. (See accompanying
6     file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 ==============================================================================*/
8 #include <boost/detail/lightweight_test.hpp>
9 #include <boost/fusion/sequence/intrinsic/at.hpp>
10 #include <boost/fusion/sequence/comparison/equal_to.hpp>
11 #include <string>
12 
13 #if !defined(FUSION_AT)
14 #define FUSION_AT at_c
15 #endif
16 
17 #if !defined(FUSION_MAKE)
18 #define FUSION_MAKE BOOST_PP_CAT(make_, FUSION_SEQUENCE)
19 #endif
20 
21 namespace test_detail
22 {
23     // something to prevent warnings for unused variables
dummy(const T &)24     template<class T> void dummy(const T&) {}
25 
26     class A {};
27     class B {};
28 }
29 
make_tuple_test()30 void make_tuple_test() {}
31 
32 void
test()33 test()
34 {
35     using namespace boost::fusion;
36     using namespace test_detail;
37 
38     {
39         FUSION_SEQUENCE<int, char> t1 = FUSION_MAKE(5, 'a');
40         BOOST_TEST(FUSION_AT<0>(t1) == 5);
41         BOOST_TEST(FUSION_AT<1>(t1) == 'a');
42 
43         FUSION_SEQUENCE<int, std::string> t2;
44         t2 = FUSION_MAKE((short int)2, std::string("Hi"));
45         BOOST_TEST(FUSION_AT<0>(t2) == 2);
46         BOOST_TEST(FUSION_AT<1>(t2) == "Hi");
47     }
48 
49     {   // This test was previously disallowed for non-PTS compilers.
50         A a = A(); B b;
51         const A ca = a;
52         FUSION_MAKE(boost::cref(a), b);
53         FUSION_MAKE(boost::ref(a), b);
54         FUSION_MAKE(boost::ref(a), boost::cref(b));
55         FUSION_MAKE(boost::ref(ca));
56     }
57 
58     {   //  the result of make_xxx is assignable:
59         BOOST_TEST(FUSION_MAKE(2, 4, 6) ==
60             (FUSION_MAKE(1, 2, 3) = FUSION_MAKE(2, 4, 6)));
61     }
62 
63     {   // This test was previously disallowed for non-PTS compilers.
64         FUSION_MAKE("Donald", "Daisy"); // should work;
65     //  std::make_pair("Doesn't","Work"); // fails
66     }
67 
68     {
69         // You can store a reference to a function in a sequence
70         FUSION_SEQUENCE<void(&)()> adf(make_tuple_test);
71         dummy(adf); // avoid warning for unused variable
72     }
73 
74 #if defined(FUSION_TEST_FAIL)
75     {
76         //  But make_xxx doesn't work
77         //  with function references, since it creates a const
78         //  qualified function type
79 
80         FUSION_MAKE(make_tuple_test);
81     }
82 #endif
83 
84     {
85         // With function pointers, make_xxx works just fine
86         FUSION_MAKE(&make_tuple_test);
87     }
88 }
89