remove_range.hpp 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*!
  2. @file
  3. Forward declares `boost::hana::remove_range` and `boost::hana::remove_range_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_REMOVE_RANGE_HPP
  9. #define BOOST_HANA_FWD_REMOVE_RANGE_HPP
  10. #include <boost/hana/config.hpp>
  11. #include <boost/hana/core/when.hpp>
  12. #include <cstddef>
  13. BOOST_HANA_NAMESPACE_BEGIN
  14. //! Remove the elements inside a given range of indices from a sequence.
  15. //! @ingroup group-Sequence
  16. //!
  17. //! `remove_range` returns a new sequence identical to the original,
  18. //! except that elements at indices in the provided range are removed.
  19. //! Specifically, `remove_range([x0, ..., xn], from, to)` is a new
  20. //! sequence equivalent to `[x0, ..., x_from-1, x_to, ..., xn]`.
  21. //!
  22. //!
  23. //! @note
  24. //! The behavior is undefined if the range contains any index out of the
  25. //! bounds of the sequence.
  26. //!
  27. //!
  28. //! @param xs
  29. //! A sequence from which elements are removed.
  30. //!
  31. //! @param [from, to)
  32. //! An half-open interval of `IntegralConstant`s representing the indices
  33. //! of the elements to be removed from the sequence. The `IntegralConstant`s
  34. //! in the half-open interval must be non-negative and in the bounds of
  35. //! the sequence. The half-open interval must also be valid, meaning that
  36. //! `from <= to`.
  37. //!
  38. //!
  39. //! Example
  40. //! -------
  41. //! @include example/remove_range.cpp
  42. #ifdef BOOST_HANA_DOXYGEN_INVOKED
  43. constexpr auto remove_range = [](auto&& xs, auto const& from, auto const& to) {
  44. return tag-dispatched;
  45. };
  46. #else
  47. template <typename S, typename = void>
  48. struct remove_range_impl : remove_range_impl<S, when<true>> { };
  49. struct remove_range_t {
  50. template <typename Xs, typename From, typename To>
  51. constexpr auto operator()(Xs&& xs, From const& from, To const& to) const;
  52. };
  53. constexpr remove_range_t remove_range{};
  54. #endif
  55. //! Equivalent to `remove_range`; provided for convenience.
  56. //! @ingroup group-Sequence
  57. //!
  58. //!
  59. //! Example
  60. //! -------
  61. //! @include example/remove_range_c.cpp
  62. #ifdef BOOST_HANA_DOXYGEN_INVOKED
  63. template <std::size_t from, std::size_t to>
  64. constexpr auto remove_range_c = [](auto&& xs) {
  65. return hana::remove_range(forwarded(xs), hana::size_c<from>, hana::size_c<to>);
  66. };
  67. #else
  68. template <std::size_t from, std::size_t to>
  69. struct remove_range_c_t;
  70. template <std::size_t from, std::size_t to>
  71. constexpr remove_range_c_t<from, to> remove_range_c{};
  72. #endif
  73. BOOST_HANA_NAMESPACE_END
  74. #endif // !BOOST_HANA_FWD_REMOVE_RANGE_HPP