• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*=============================================================================
2     Copyright (c) 2007 Tobias Schwinger
3 
4     Use modification and distribution are subject to the Boost Software
5     License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
6     http://www.boost.org/LICENSE_1_0.txt).
7 ==============================================================================*/
8 
9 #include <boost/config.hpp>
10 #include <boost/fusion/support/deduce_sequence.hpp>
11 #include <boost/fusion/mpl.hpp>
12 #include <boost/detail/lightweight_test.hpp>
13 
14 #include <boost/mpl/equal.hpp>
15 
16 #include <boost/ref.hpp>
17 #ifndef BOOST_NO_CXX11_HDR_FUNCTIONAL
18 #include <functional>
19 #endif
20 
21 using boost::is_same;
22 using boost::reference_wrapper;
23 using boost::fusion::traits::deduce;
24 using boost::fusion::traits::deduce_sequence;
25 
26 namespace fusion = boost::fusion;
27 
28 template <class Args>
29 struct test_seq_ctor
30 {
31     typename deduce_sequence<Args>::type fsq_args;
32 
test_seq_ctortest_seq_ctor33     test_seq_ctor(Args const & args)
34         : fsq_args(args)
35     { }
36 };
37 
38 #define TEST_SAME_TYPE(a,b) BOOST_TEST(( is_same< a, b >::value ))
39 #define TEST_SAME_ELEMENTS(a,b) BOOST_TEST(( boost::mpl::equal< a, b >::type::value ))
40 
41 typedef fusion::vector<int, int const, int &, int const &> args1;
42 typedef fusion::vector<int, int, int &, int> storable1;
43 template struct test_seq_ctor<args1>;
44 
45 typedef fusion::vector< reference_wrapper<int> &, reference_wrapper<int const> &,
46     reference_wrapper<int> const &, reference_wrapper<int const> const & > args2;
47 typedef fusion::vector<int &, int const &, int &, int const &> storable2;
48 template struct test_seq_ctor<args2>;
49 
50 
51 typedef fusion::vector<int *, int const *, int const * const, int const * &, int const * const &> args3;
52 typedef fusion::vector<int *, int const *, int const *, int const * &, int const * > storable3;
53 template struct test_seq_ctor<args3>;
54 
55 typedef fusion::vector<int(&)[2], int const(&)[2]> args4;
56 typedef args4 storable4;
57 template struct test_seq_ctor<args4>;
58 
main()59 int main()
60 {
61     TEST_SAME_TYPE(deduce<int &>::type, int &);
62     TEST_SAME_TYPE(deduce<int volatile &>::type,  int volatile &);
63 
64     TEST_SAME_TYPE(deduce<int>::type, int);
65     TEST_SAME_TYPE(deduce<int const &>::type, int);
66     TEST_SAME_TYPE(deduce<int const volatile &>::type, int);
67 
68     TEST_SAME_TYPE(deduce< reference_wrapper<int> & >::type, int &);
69     TEST_SAME_TYPE(deduce< reference_wrapper<int const> & >::type, int const &);
70     TEST_SAME_TYPE(deduce< reference_wrapper<int> const & >::type, int &);
71     TEST_SAME_TYPE(deduce< reference_wrapper<int const> const & >::type, int const &);
72 
73 #ifndef BOOST_NO_CXX11_HDR_FUNCTIONAL
74     TEST_SAME_TYPE(deduce< std::reference_wrapper<int> & >::type, int &);
75     TEST_SAME_TYPE(deduce< std::reference_wrapper<int const> & >::type, int const &);
76     TEST_SAME_TYPE(deduce< std::reference_wrapper<int> const & >::type, int &);
77     TEST_SAME_TYPE(deduce< std::reference_wrapper<int const> const & >::type, int const &);
78 #endif
79 
80     TEST_SAME_TYPE(deduce< int(&)[2] >::type, int(&)[2]);
81     TEST_SAME_TYPE(deduce< int const (&)[2] >::type, int const (&)[2]);
82     TEST_SAME_TYPE(deduce< int volatile (&)[2] >::type, int volatile (&)[2]);
83     TEST_SAME_TYPE(deduce< int const volatile (&)[2] >::type, int const volatile (&)[2]);
84 
85     TEST_SAME_ELEMENTS(deduce_sequence<args1>::type,storable1);
86     TEST_SAME_ELEMENTS(deduce_sequence<args2>::type,storable2);
87     TEST_SAME_ELEMENTS(deduce_sequence<args3>::type,storable3);
88     TEST_SAME_ELEMENTS(deduce_sequence<args4>::type,storable4);
89 
90     return boost::report_errors();
91 }
92