Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:38:01

0001 /*!
0002 @file
0003 Defines `boost::hana::back`.
0004 
0005 Copyright Louis Dionne 2013-2022
0006 Distributed under the Boost Software License, Version 1.0.
0007 (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
0008  */
0009 
0010 #ifndef BOOST_HANA_BACK_HPP
0011 #define BOOST_HANA_BACK_HPP
0012 
0013 #include <boost/hana/fwd/back.hpp>
0014 
0015 #include <boost/hana/at.hpp>
0016 #include <boost/hana/concept/iterable.hpp>
0017 #include <boost/hana/config.hpp>
0018 #include <boost/hana/core/dispatch.hpp>
0019 #include <boost/hana/length.hpp>
0020 
0021 #include <cstddef>
0022 
0023 
0024 namespace boost { namespace hana {
0025     //! @cond
0026     template <typename Xs>
0027     constexpr decltype(auto) back_t::operator()(Xs&& xs) const {
0028         using It = typename hana::tag_of<Xs>::type;
0029         using Back = BOOST_HANA_DISPATCH_IF(back_impl<It>,
0030             hana::Iterable<It>::value
0031         );
0032 
0033     #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS
0034         static_assert(hana::Iterable<It>::value,
0035         "hana::back(xs) requires 'xs' to be an Iterable");
0036     #endif
0037 
0038         return Back::apply(static_cast<Xs&&>(xs));
0039     }
0040     //! @endcond
0041 
0042     template <typename It, bool condition>
0043     struct back_impl<It, when<condition>> : default_ {
0044         template <typename Xs>
0045         static constexpr decltype(auto) apply(Xs&& xs) {
0046             constexpr std::size_t len = decltype(hana::length(xs))::value;
0047             static_assert(len > 0, "hana::back(xs) requires 'xs' to be non-empty");
0048             return hana::at_c<len - 1>(static_cast<Xs&&>(xs));
0049         }
0050     };
0051 }} // end namespace boost::hana
0052 
0053 #endif // !BOOST_HANA_BACK_HPP