]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | /*! |
2 | @file | |
3 | Defines `boost::hana::first`. | |
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_FIRST_HPP | |
11 | #define BOOST_HANA_FIRST_HPP | |
12 | ||
13 | #include <boost/hana/fwd/first.hpp> | |
14 | ||
15 | #include <boost/hana/concept/product.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 Pair> | |
23 | constexpr decltype(auto) first_t::operator()(Pair&& pair) const { | |
24 | using P = typename hana::tag_of<Pair>::type; | |
25 | using First = BOOST_HANA_DISPATCH_IF(first_impl<P>, | |
26 | hana::Product<P>::value | |
27 | ); | |
28 | ||
29 | #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS | |
30 | static_assert(hana::Product<P>::value, | |
31 | "hana::first(pair) requires 'pair' to be a Product"); | |
32 | #endif | |
33 | ||
34 | return First::apply(static_cast<Pair&&>(pair)); | |
35 | } | |
36 | //! @endcond | |
37 | ||
38 | template <typename P, bool condition> | |
39 | struct first_impl<P, when<condition>> : default_ { | |
40 | template <typename ...Args> | |
41 | static constexpr auto apply(Args&& ...) = delete; | |
42 | }; | |
43 | BOOST_HANA_NAMESPACE_END | |
44 | ||
45 | #endif // !BOOST_HANA_FIRST_HPP |