MPL11
 All Classes Namespaces Files Typedefs Macros Groups Pages
maybe.hpp
Go to the documentation of this file.
1 
12 #ifndef BOOST_MPL11_MAYBE_HPP
13 #define BOOST_MPL11_MAYBE_HPP
14 
16 
17 #include <boost/mpl11/core.hpp>
19 #include <boost/mpl11/functor.hpp>
20 
21 #include <boost/mpl11/bool.hpp> // required by fwd/maybe.hpp
22 #include <boost/mpl11/functional.hpp> //
23 
24 
25 namespace boost { namespace mpl11 {
26  template <typename x>
27  struct just {
28  using type = just;
29  using mpl_datatype = Maybe;
30 
31  template <typename def, typename f>
32  using maybe_ = typename f::type::template apply<x>;
33  };
34 
35  struct nothing {
36  using type = nothing;
37  using mpl_datatype = Maybe;
38 
39  template <typename def, typename f>
40  using maybe_ = def;
41  };
42 
43  template <typename def, typename f, typename m>
44  struct maybe
45  : m::type::template maybe_<def, f>
46  { };
47 
48  namespace maybe_detail {
49  template <typename ...dum>
50  struct err_from_just {
51  static_assert(detail::dependent<dum...>::value(false),
52  "Using from_just on a nothing.");
53 
54  struct type;
55  };
56  }
57 
58  template <>
59  struct Functor<Maybe> : instantiate<Functor>::with<Maybe> {
60  template <typename f, typename m>
61  using fmap_impl = typename m::template maybe_<nothing, f>;
62  };
63 
64 #if 0
65  template <typename T, typename U>
66  struct Comparable<Maybe<T>, Maybe<U>, typename Comparable<T, U>::type>
67  : instantiate<Comparable>::with<Maybe<T>, Maybe<U>>
68  {
69  template <typename x, typename y>
70  struct equal_impl
71  : equal_impl<typename x::type, typename y::type>
72  { };
73 
74  template <>
75  struct equal_impl<nothing, nothing>
76  : true_
77  { };
78 
79  template <typename x, typename y>
80  struct equal_impl<just<x>, just<y>>
81  : equal<x, y>
82  { };
83  };
84 #endif
85 }} // end namespace boost::mpl11
86 
87 #endif // !BOOST_MPL11_MAYBE_HPP
Forward declares the Maybe datatype.
Defines the fmap method of the Functor typeclass.
Defines boost::mpl11::detail::dependent.
Defines the Core module.
Invokes a metafunction class with the given arguments.
Definition: functional.hpp:39
Forwards to boost/mpl11/integer.hpp.
Defines the Functional module.