drop_front.hpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*!
  2. @file
  3. Defines `boost::hana::drop_front`.
  4. @copyright Louis Dionne 2013-2017
  5. Distributed under the Boost Software License, Version 1.0.
  6. (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
  7. */
  8. #ifndef BOOST_HANA_DROP_FRONT_HPP
  9. #define BOOST_HANA_DROP_FRONT_HPP
  10. #include <boost/hana/fwd/drop_front.hpp>
  11. #include <boost/hana/concept/integral_constant.hpp>
  12. #include <boost/hana/concept/iterable.hpp>
  13. #include <boost/hana/config.hpp>
  14. #include <boost/hana/core/dispatch.hpp>
  15. #include <boost/hana/core/tag_of.hpp>
  16. #include <boost/hana/integral_constant.hpp>
  17. BOOST_HANA_NAMESPACE_BEGIN
  18. //! @cond
  19. template <typename Xs, typename N>
  20. constexpr auto drop_front_t::operator()(Xs&& xs, N const& n) const {
  21. using It = typename hana::tag_of<Xs>::type;
  22. using DropFront = BOOST_HANA_DISPATCH_IF(drop_front_impl<It>,
  23. hana::Iterable<It>::value &&
  24. hana::IntegralConstant<N>::value
  25. );
  26. #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS
  27. static_assert(hana::Iterable<It>::value,
  28. "hana::drop_front(xs, n) requires 'xs' to be an Iterable");
  29. static_assert(hana::IntegralConstant<N>::value,
  30. "hana::drop_front(xs, n) requires 'n' to be an IntegralConstant");
  31. #endif
  32. return DropFront::apply(static_cast<Xs&&>(xs), n);
  33. }
  34. template <typename Xs>
  35. constexpr auto drop_front_t::operator()(Xs&& xs) const {
  36. return (*this)(static_cast<Xs&&>(xs), hana::size_t<1>{});
  37. }
  38. //! @endcond
  39. template <typename It, bool condition>
  40. struct drop_front_impl<It, when<condition>> : default_ {
  41. template <typename Xs, typename N>
  42. static constexpr auto apply(Xs&&, N const&) = delete;
  43. };
  44. BOOST_HANA_NAMESPACE_END
  45. #endif // !BOOST_HANA_DROP_FRONT_HPP