for_each.hpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*!
  2. @file
  3. Forward declares `boost::hana::for_each`.
  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_FOR_EACH_HPP
  9. #define BOOST_HANA_FWD_FOR_EACH_HPP
  10. #include <boost/hana/config.hpp>
  11. #include <boost/hana/core/when.hpp>
  12. BOOST_HANA_NAMESPACE_BEGIN
  13. //! Perform an action on each element of a foldable, discarding
  14. //! the result each time.
  15. //! @ingroup group-Foldable
  16. //!
  17. //! Iteration is done from left to right, i.e. in the same order as when
  18. //! using `fold_left`. If the structure is not finite, this method will
  19. //! not terminate.
  20. //!
  21. //!
  22. //! @param xs
  23. //! The structure to iterate over.
  24. //!
  25. //! @param f
  26. //! A function called as `f(x)` for each element `x` of the structure.
  27. //! The result of `f(x)`, whatever it is, is ignored.
  28. //!
  29. //!
  30. //! Example
  31. //! -------
  32. //! @include example/for_each.cpp
  33. #ifdef BOOST_HANA_DOXYGEN_INVOKED
  34. constexpr auto for_each = [](auto&& xs, auto&& f) -> void {
  35. tag-dispatched;
  36. };
  37. #else
  38. template <typename T, typename = void>
  39. struct for_each_impl : for_each_impl<T, when<true>> { };
  40. struct for_each_t {
  41. template <typename Xs, typename F>
  42. constexpr void operator()(Xs&& xs, F&& f) const;
  43. };
  44. constexpr for_each_t for_each{};
  45. #endif
  46. BOOST_HANA_NAMESPACE_END
  47. #endif // !BOOST_HANA_FWD_FOR_EACH_HPP