3 Defines `boost::hana::front`.
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)
10 #ifndef BOOST_HANA_FRONT_HPP
11 #define BOOST_HANA_FRONT_HPP
13 #include <boost/hana/fwd/front.hpp>
15 #include <boost/hana/at.hpp>
16 #include <boost/hana/concept/iterable.hpp>
17 #include <boost/hana/config.hpp>
18 #include <boost/hana/core/dispatch.hpp>
21 BOOST_HANA_NAMESPACE_BEGIN
23 template <typename Xs>
24 constexpr decltype(auto) front_t::operator()(Xs&& xs) const {
25 using It = typename hana::tag_of<Xs>::type;
26 using Front = BOOST_HANA_DISPATCH_IF(front_impl<It>,
27 hana::Iterable<It>::value
30 #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS
31 static_assert(hana::Iterable<It>::value,
32 "hana::front(xs) requires 'xs' to be an Iterable");
35 return Front::apply(static_cast<Xs&&>(xs));
39 template <typename It, bool condition>
40 struct front_impl<It, when<condition>> : default_ {
41 template <typename Xs>
42 static constexpr decltype(auto) apply(Xs&& xs)
43 { return hana::at_c<0>(static_cast<Xs&&>(xs)); }
45 BOOST_HANA_NAMESPACE_END
47 #endif // !BOOST_HANA_FRONT_HPP