Back to home page

EIC code displayed by LXR

 
 

    


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

0001 /*!
0002 @file
0003 Defines `boost::hana::drop_front_exactly`.
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_DROP_FRONT_EXACTLY_HPP
0011 #define BOOST_HANA_DROP_FRONT_EXACTLY_HPP
0012 
0013 #include <boost/hana/fwd/drop_front_exactly.hpp>
0014 
0015 #include <boost/hana/bool.hpp>
0016 #include <boost/hana/concept/integral_constant.hpp>
0017 #include <boost/hana/concept/iterable.hpp>
0018 #include <boost/hana/config.hpp>
0019 #include <boost/hana/core/dispatch.hpp>
0020 #include <boost/hana/drop_front.hpp>
0021 #include <boost/hana/integral_constant.hpp>
0022 #include <boost/hana/is_empty.hpp>
0023 
0024 
0025 namespace boost { namespace hana {
0026     //! @cond
0027     template <typename Xs, typename N>
0028     constexpr auto drop_front_exactly_t::operator()(Xs&& xs, N const& n) const {
0029         using It = typename hana::tag_of<Xs>::type;
0030         using DropFrontExactly = BOOST_HANA_DISPATCH_IF(drop_front_exactly_impl<It>,
0031             hana::Iterable<It>::value &&
0032             hana::IntegralConstant<N>::value
0033         );
0034 
0035     #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS
0036         static_assert(hana::Iterable<It>::value,
0037         "hana::drop_front_exactly(xs, n) requires 'xs' to be an Iterable");
0038 
0039         static_assert(hana::IntegralConstant<N>::value,
0040         "hana::drop_front_exactly(xs, n) requires 'n' to be an IntegralConstant");
0041     #endif
0042 
0043         static_assert(N::value >= 0,
0044         "hana::drop_front_exactly(xs, n) requires 'n' to be non-negative");
0045 
0046         return DropFrontExactly::apply(static_cast<Xs&&>(xs), n);
0047     }
0048 
0049     template <typename Xs>
0050     constexpr auto drop_front_exactly_t::operator()(Xs&& xs) const {
0051         return (*this)(static_cast<Xs&&>(xs), hana::size_c<1>);
0052     }
0053     //! @endcond
0054 
0055     namespace detail {
0056         template <typename Xs, typename N>
0057         constexpr void check_dfe_overflow(Xs const& xs, N const&, hana::true_) {
0058             constexpr bool n_overflew_length = decltype(
0059                 hana::is_empty(hana::drop_front(xs, hana::size_c<N::value - 1>))
0060             )::value;
0061             static_assert(!n_overflew_length,
0062             "hana::drop_front_exactly(xs, n) requires 'n' to be less than or "
0063             "equal to the number of elements in 'xs'");
0064         }
0065 
0066         template <typename Xs, typename N>
0067         constexpr void check_dfe_overflow(Xs const&, N const&, hana::false_) { }
0068     }
0069 
0070     template <typename It, bool condition>
0071     struct drop_front_exactly_impl<It, when<condition>> : default_ {
0072         template <typename Xs, typename N>
0073         static constexpr auto apply(Xs&& xs, N const& n) {
0074             auto result = hana::drop_front(static_cast<Xs&&>(xs), n);
0075             constexpr bool check_for_overflow =
0076                 decltype(hana::is_empty(result))::value && N::value != 0;
0077 
0078             detail::check_dfe_overflow(xs, n, hana::bool_c<check_for_overflow>);
0079 
0080             return result; // NRVO applied
0081         }
0082     };
0083 }} // end namespace boost::hana
0084 
0085 #endif // !BOOST_HANA_DROP_FRONT_EXACTLY_HPP