replace.hpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*!
  2. @file
  3. Forward declares `boost::hana::replace`.
  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_REPLACE_HPP
  9. #define BOOST_HANA_FWD_REPLACE_HPP
  10. #include <boost/hana/config.hpp>
  11. #include <boost/hana/core/when.hpp>
  12. BOOST_HANA_NAMESPACE_BEGIN
  13. //! Replace all the elements of a structure that compare equal
  14. //! to some `value` with some new fixed value.
  15. //! @ingroup group-Functor
  16. //!
  17. //!
  18. //! Signature
  19. //! ---------
  20. //! Given `F` a Functor and `U` a type that can be compared with `T`,
  21. //! the signature is
  22. //! \f$
  23. //! \mathtt{replace} : F(T) \times U \times T \to F(T)
  24. //! \f$
  25. //!
  26. //! @param xs
  27. //! The structure to replace elements of.
  28. //!
  29. //! @param oldval
  30. //! An object compared with each element of the structure. Elements
  31. //! of the structure that compare equal to `oldval` are replaced
  32. //! by `newval` in the new structure.
  33. //!
  34. //! @param newval
  35. //! A value by which every element `x` of the structure that compares
  36. //! equal to `oldval` is replaced.
  37. //!
  38. //!
  39. //! Example
  40. //! -------
  41. //! @include example/replace.cpp
  42. #ifdef BOOST_HANA_DOXYGEN_INVOKED
  43. constexpr auto replace = [](auto&& xs, auto&& oldval, auto&& newval) {
  44. return tag-dispatched;
  45. };
  46. #else
  47. template <typename Xs, typename = void>
  48. struct replace_impl : replace_impl<Xs, when<true>> { };
  49. struct replace_t {
  50. template <typename Xs, typename OldVal, typename NewVal>
  51. constexpr auto operator()(Xs&& xs, OldVal&& oldval, NewVal&& newval) const;
  52. };
  53. constexpr replace_t replace{};
  54. #endif
  55. BOOST_HANA_NAMESPACE_END
  56. #endif // !BOOST_HANA_FWD_REPLACE_HPP