take_front.hpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*!
  2. @file
  3. Forward declares `boost::hana::take_front` and `boost::hana::take_front_c`.
  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_FWD_TAKE_FRONT_HPP
  9. #define BOOST_HANA_FWD_TAKE_FRONT_HPP
  10. #include <boost/hana/config.hpp>
  11. #include <boost/hana/core/when.hpp>
  12. #include <cstddef>
  13. BOOST_HANA_NAMESPACE_BEGIN
  14. //! Returns the first `n` elements of a sequence, or the whole sequence
  15. //! if the sequence has less than `n` elements.
  16. //! @ingroup group-Sequence
  17. //!
  18. //! Given a `Sequence` `xs` and an `IntegralConstant` `n`, `take_front(xs, n)`
  19. //! is a new sequence containing the first `n` elements of `xs`, in the
  20. //! same order. If `length(xs) <= n`, the whole sequence is returned and
  21. //! no error is triggered.
  22. //!
  23. //!
  24. //! @param xs
  25. //! The sequence to take the elements from.
  26. //!
  27. //! @param n
  28. //! A non-negative `IntegralConstant` representing the number of elements
  29. //! to keep in the resulting sequence.
  30. //!
  31. //!
  32. //! Example
  33. //! -------
  34. //! @include example/take_front.cpp
  35. #ifdef BOOST_HANA_DOXYGEN_INVOKED
  36. constexpr auto take_front = [](auto&& xs, auto const& n) {
  37. return tag-dispatched;
  38. };
  39. #else
  40. template <typename S, typename = void>
  41. struct take_front_impl : take_front_impl<S, when<true>> { };
  42. struct take_front_t {
  43. template <typename Xs, typename N>
  44. constexpr auto operator()(Xs&& xs, N const& n) const;
  45. };
  46. constexpr take_front_t take_front{};
  47. #endif
  48. //! Equivalent to `take_front`; provided for convenience.
  49. //! @ingroup group-Sequence
  50. //!
  51. //!
  52. //! Example
  53. //! -------
  54. //! @include example/take_front_c.cpp
  55. #ifdef BOOST_HANA_DOXYGEN_INVOKED
  56. template <std::size_t n>
  57. constexpr auto take_front_c = [](auto&& xs) {
  58. return hana::take_front(forwarded(xs), hana::size_c<n>);
  59. };
  60. #else
  61. template <std::size_t n>
  62. struct take_front_c_t;
  63. template <std::size_t n>
  64. constexpr take_front_c_t<n> take_front_c{};
  65. #endif
  66. BOOST_HANA_NAMESPACE_END
  67. #endif // !BOOST_HANA_FWD_TAKE_FRONT_HPP