MPL11
 All Classes Namespaces Files Typedefs Macros Groups Pages
functor.hpp
Go to the documentation of this file.
1 
12 #ifndef BOOST_MPL11_DETAIL_TEST_FUNCTOR_HPP
13 #define BOOST_MPL11_DETAIL_TEST_FUNCTOR_HPP
14 
15 #include <boost/mpl11/functor.hpp>
16 
17 #include <boost/mpl11/core.hpp>
20 
21 
22 namespace boost { namespace mpl11 { namespace detail {
23 namespace functor_detail {
24 template <typename ...x>
25 struct f { using type = f<typename x::type...>; };
26 
27 struct x0 { using type = x0; };
28 struct x1 { using type = x1; };
29 struct x2 { using type = x2; };
30 struct x3 { using type = x3; };
31 struct x4 { using type = x4; };
32 using u = undefined;
33 
34 template <template <typename ...> class s>
35 struct test_fmap {
36  template <typename ...xs>
37  using _fmap = fmap<lift<f>, s<xs...>>;
38 
39  struct go
40  : expect<_fmap<>>::template to_eq<s<>>
41  , expect<_fmap<x0>>::template to_eq<s<f<x0>>>
42  , expect<_fmap<x0, x1>>::template to_eq<s<f<x0>, f<x1>>>
43  , expect<_fmap<x0, x1, x2>>::template to_eq<s<f<x0>, f<x1>, f<x2>>>
44  , expect<_fmap<x0, x1, x2, x3>>::template
45  to_eq<s<f<x0>, f<x1>, f<x2>, f<x3>>>
46  , expect<_fmap<x0, x1, x2, x3, x4>>::template
47  to_eq<s<f<x0>, f<x1>, f<x2>, f<x3>, f<x4>>>
48  { };
49 
50  static_assert(sizeof(go), "");
51 };
52 
53 template <template <typename ...> class functor>
54 struct test_datatype {
55  template <typename ...xs>
56  using _datatype = typename expect<
57  typename datatype<typename functor<xs...>::type>::type
58  >::template to_satisfy<lift<mpl11::Functor>>;
59 
60  static_assert(
61  sizeof(_datatype<>) +
62  sizeof(_datatype<u>) +
63  sizeof(_datatype<u, u>) +
64  sizeof(_datatype<u, u, u>)
65  , "");
66 };
67 } // end namespace functor_detail
68 
69 template <template <typename ...> class functor>
70 struct test_Functor
71  : functor_detail::test_fmap<functor>
72  , functor_detail::test_datatype<functor>
73 { };
74 }}} // end namespace boost::mpl11::detail
75 
76 #endif // !BOOST_MPL11_DETAIL_TEST_FUNCTOR_HPP
Defines the fmap method of the Functor typeclass.
Defines the Core module.
Defines utilities to write unit tests.
Defines the Functional module.