]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | /*! |
2 | @file | |
3 | Defines `boost::hana::empty`. | |
4 | ||
b32b8144 | 5 | @copyright Louis Dionne 2013-2017 |
7c673cae FG |
6 | Distributed under the Boost Software License, Version 1.0. |
7 | (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) | |
8 | */ | |
9 | ||
10 | #ifndef BOOST_HANA_EMPTY_HPP | |
11 | #define BOOST_HANA_EMPTY_HPP | |
12 | ||
13 | #include <boost/hana/fwd/empty.hpp> | |
14 | ||
15 | #include <boost/hana/concept/monad_plus.hpp> | |
16 | #include <boost/hana/concept/sequence.hpp> | |
17 | #include <boost/hana/config.hpp> | |
18 | #include <boost/hana/core/dispatch.hpp> | |
19 | #include <boost/hana/core/make.hpp> | |
20 | ||
21 | ||
1e59de90 | 22 | namespace boost { namespace hana { |
92f5a8d4 | 23 | //! @cond |
7c673cae | 24 | template <typename M> |
92f5a8d4 | 25 | constexpr auto empty_t<M>::operator()() const { |
7c673cae FG |
26 | #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS |
27 | static_assert(hana::MonadPlus<M>::value, | |
28 | "hana::empty<M>() requires 'M' to be a MonadPlus"); | |
29 | #endif | |
30 | ||
92f5a8d4 TL |
31 | using Empty = BOOST_HANA_DISPATCH_IF(empty_impl<M>, |
32 | hana::MonadPlus<M>::value | |
33 | ); | |
7c673cae | 34 | |
92f5a8d4 TL |
35 | return Empty::apply(); |
36 | } | |
37 | //! @endcond | |
7c673cae FG |
38 | |
39 | template <typename M, bool condition> | |
40 | struct empty_impl<M, when<condition>> : default_ { | |
41 | template <typename ...Args> | |
42 | static constexpr auto apply(Args&& ...) = delete; | |
43 | }; | |
44 | ||
45 | template <typename S> | |
46 | struct empty_impl<S, when<Sequence<S>::value>> { | |
47 | static constexpr auto apply() { | |
48 | return hana::make<S>(); | |
49 | } | |
50 | }; | |
1e59de90 | 51 | }} // end namespace boost::hana |
7c673cae FG |
52 | |
53 | #endif // !BOOST_HANA_EMPTY_HPP |