MPL11
 All Classes Namespaces Files Typedefs Macros Groups Pages
core.hpp
Go to the documentation of this file.
1 
12 #ifndef BOOST_MPL11_CORE_HPP
13 #define BOOST_MPL11_CORE_HPP
14 
15 #include <boost/mpl11/fwd/core.hpp>
16 
19 #include <boost/mpl11/fwd/bool.hpp>
21 
22 
23 namespace boost { namespace mpl11 {
24  // undefined
25  namespace core_detail {
26  template <typename ...xs>
27  struct undefined_ {
28  static_assert(detail::dependent<xs...>::value(false),
29  "Error: `undefined` may not be instantiated.");
30  };
31  }
32 
33 
34 
35  // instantiate
36  template <template <typename ...> class Typeclass>
37  struct instantiate {
38  template <typename ...>
39  using with = true_;
40  };
41 
42 
43 
44  // box
45  template <typename x>
46  struct box {
47  using type = x;
48  };
49 
50 
51 
52  // datatype
53  namespace core_detail {
54  template <typename T>
55  auto pick_datatype(T*) -> typename T::mpl_datatype;
56  auto pick_datatype(...) -> Foreign;
57  }
58 
59  template <typename ctor>
60  struct datatype {
61  using type = decltype(core_detail::pick_datatype((ctor*)nullptr));
62  };
63 
64 
65 
66  // cast_to
67  template <typename To>
68  struct cast_to {
69  using type = cast_to;
70 
71  template <typename x>
72  using apply = typename cast<
73  typename datatype<x>::type, To
74  >::type::template apply<x>;
75  };
76 
77 
78 
79  // Foreign
80  namespace core_detail {
81  // Data constructor for `Foreign`. Not sure that should be public.
82  // This only preserves type identity. Also; this is not the only
83  // data constructor. In fact, any type is a valid data constructor
84  // for `Foreign`. I'm not sure I like that.
85  template <typename>
86  struct foreign {
87  using type = foreign;
88  using mpl_datatype = Foreign;
89  };
90  }
91 
92  template <typename From>
93  struct cast<From, Foreign> {
94  using type = cast;
95 
96  template <typename x>
97  using apply = core_detail::foreign<x>;
98  };
99 
100  // We can't use `lift<id>` here because `foreign` is not the only
101  // data constructor for `Foreign`! Pitfall!
102  template <>
103  struct cast<Foreign, Foreign> : lift<box> { };
104 }} // end namespace boost::mpl11
105 
106 
107 #include <boost/mpl11/bool.hpp>
109 #include <boost/mpl11/logical.hpp>
110 
111 
112 namespace boost { namespace mpl11 {
113  // cast
114  namespace core_detail {
115  template <typename ...datatypes>
116  struct invalid_cast {
117  static_assert(detail::dependent<datatypes...>::value(false),
118  "No cast is provided between the two requested datatypes.");
119  };
120  }
121 
122  // Note that we must not specialize cast<From, From> because that
123  // could make the specialization ambiguous when `cast` is defined
124  // over parameterized types, say `cast<Vector<T>, Vector<T>>`.
125  template <typename From, typename To>
126  struct cast
127  : if_c<detail::std_is_same<From, To>::value,
128  lift<box>,
129  core_detail::invalid_cast<From, To>
130  >
131  { };
132 }}
133 
134 #endif // !BOOST_MPL11_CORE_HPP
Boxes its argument.
Definition: core.hpp:46
Returns the datatype of the given data constructor.
Definition: core.hpp:60
Forward declares the Core module.
Holds default methods of typeclasses.
Definition: core.hpp:37
Forwards to boost/mpl11/fwd/integer.hpp.
Forward declares logical metafunctions.
Defines the Logical module.
Defines boost::mpl11::detail::dependent.
Defines boost::mpl11::detail::std_is_same.
Metafunction class converting an object of the From datatype to an object of the To datatype...
Definition: core.hpp:126
Equivalent to if_, Then, Else>.
Definition: logical.hpp:63
Invokes a metafunction class with the given arguments.
Definition: functional.hpp:39
Metafunction class converting an object to the To datatype.
Definition: core.hpp:68
Alias to bool_; provided for convenience.
Definition: integer.hpp:79
Forwards to boost/mpl11/integer.hpp.
Defines the Functional module.