take_while.hpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*!
  2. @file
  3. Forward declares `boost::hana::take_while`.
  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_WHILE_HPP
  9. #define BOOST_HANA_FWD_TAKE_WHILE_HPP
  10. #include <boost/hana/config.hpp>
  11. #include <boost/hana/core/when.hpp>
  12. BOOST_HANA_NAMESPACE_BEGIN
  13. //! Take elements from a sequence while the `predicate` is satisfied.
  14. //! @ingroup group-Sequence
  15. //!
  16. //! Specifically, `take_while` returns a new sequence containing the
  17. //! longest prefix of `xs` in which all the elements satisfy the given
  18. //! predicate.
  19. //!
  20. //!
  21. //! @param xs
  22. //! The sequence to take elements from.
  23. //!
  24. //! @param predicate
  25. //! A function called as `predicate(x)`, where `x` is an element of the
  26. //! sequence, and returning a `Logical` representing whether `x` should be
  27. //! included in the resulting sequence. In the current version of the
  28. //! library, `predicate` has to return a `Constant Logical`.
  29. //!
  30. //!
  31. //! Example
  32. //! -------
  33. //! @include example/take_while.cpp
  34. #ifdef BOOST_HANA_DOXYGEN_INVOKED
  35. constexpr auto take_while = [](auto&& xs, auto&& predicate) {
  36. return tag-dispatched;
  37. };
  38. #else
  39. template <typename S, typename = void>
  40. struct take_while_impl : take_while_impl<S, when<true>> { };
  41. struct take_while_t {
  42. template <typename Xs, typename Pred>
  43. constexpr auto operator()(Xs&& xs, Pred&& pred) const;
  44. };
  45. constexpr take_while_t take_while{};
  46. #endif
  47. BOOST_HANA_NAMESPACE_END
  48. #endif // !BOOST_HANA_FWD_TAKE_WHILE_HPP