append.hpp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*!
  2. @file
  3. Forward declares `boost::hana::append`.
  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_APPEND_HPP
  9. #define BOOST_HANA_FWD_APPEND_HPP
  10. #include <boost/hana/config.hpp>
  11. #include <boost/hana/core/when.hpp>
  12. BOOST_HANA_NAMESPACE_BEGIN
  13. //! Append an element to a monadic structure.
  14. //! @ingroup group-MonadPlus
  15. //!
  16. //! Given an element `x` and a monadic structure `xs`, `append` returns a
  17. //! new monadic structure which is the result of lifting `x` into the
  18. //! monadic structure and then combining that (to the right) with `xs`.
  19. //! In other words,
  20. //! @code
  21. //! append(xs, x) == concat(xs, lift<Xs>(x))
  22. //! @endcode
  23. //! where `Xs` is the tag of `xs`. For sequences, this has the intuitive
  24. //! behavior of simply appending an element to the end of the sequence,
  25. //! hence the name.
  26. //!
  27. //! > #### Rationale for not calling this `push_back`
  28. //! > See the rationale for using `prepend` instead of `push_front`.
  29. //!
  30. //!
  31. //! Signature
  32. //! ---------
  33. //! Given a MonadPlus `M`, the signature is
  34. //! @f$ \mathtt{append} : M(T) \times T \to M(T) @f$.
  35. //!
  36. //! @param xs
  37. //! A monadic structure that will be combined to the left of the element.
  38. //!
  39. //! @param x
  40. //! An element to combine to the right of the monadic structure.
  41. //!
  42. //!
  43. //! Example
  44. //! -------
  45. //! @include example/append.cpp
  46. #ifdef BOOST_HANA_DOXYGEN_INVOKED
  47. constexpr auto append = [](auto&& xs, auto&& x) {
  48. return tag-dispatched;
  49. };
  50. #else
  51. template <typename M, typename = void>
  52. struct append_impl : append_impl<M, when<true>> { };
  53. struct append_t {
  54. template <typename Xs, typename X>
  55. constexpr auto operator()(Xs&& xs, X&& x) const;
  56. };
  57. constexpr append_t append{};
  58. #endif
  59. BOOST_HANA_NAMESPACE_END
  60. #endif // !BOOST_HANA_FWD_APPEND_HPP