]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | /*! |
2 | @file | |
3 | Defines `boost::hana::extract`. | |
4 | ||
5 | @copyright Louis Dionne 2013-2016 | |
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_EXTRACT_HPP | |
11 | #define BOOST_HANA_EXTRACT_HPP | |
12 | ||
13 | #include <boost/hana/fwd/extract.hpp> | |
14 | ||
15 | #include <boost/hana/concept/comonad.hpp> | |
16 | #include <boost/hana/config.hpp> | |
17 | #include <boost/hana/core/dispatch.hpp> | |
18 | ||
19 | ||
20 | BOOST_HANA_NAMESPACE_BEGIN | |
21 | //! @cond | |
22 | template <typename W_> | |
23 | constexpr decltype(auto) extract_t::operator()(W_&& w) const { | |
24 | using W = typename hana::tag_of<W_>::type; | |
25 | using Extract = BOOST_HANA_DISPATCH_IF(extract_impl<W>, | |
26 | hana::Comonad<W>::value | |
27 | ); | |
28 | ||
29 | #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS | |
30 | static_assert(hana::Comonad<W>::value, | |
31 | "hana::extract(w) requires 'w' to be a Comonad"); | |
32 | #endif | |
33 | ||
34 | return Extract::apply(static_cast<W_&&>(w)); | |
35 | } | |
36 | //! @endcond | |
37 | ||
38 | template <typename W, bool condition> | |
39 | struct extract_impl<W, when<condition>> : default_ { | |
40 | template <typename ...Args> | |
41 | static constexpr auto apply(Args&& ...args) = delete; | |
42 | }; | |
43 | BOOST_HANA_NAMESPACE_END | |
44 | ||
45 | #endif // !BOOST_HANA_EXTRACT_HPP |