3 Forward declares `boost::hana::flatten`.
5 @copyright Louis Dionne 2013-2017
6 Distributed under the Boost Software License, Version 1.0.
7 (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
10 #ifndef BOOST_HANA_FWD_FLATTEN_HPP
11 #define BOOST_HANA_FWD_FLATTEN_HPP
13 #include <boost/hana/config.hpp>
14 #include <boost/hana/core/when.hpp>
17 BOOST_HANA_NAMESPACE_BEGIN
18 //! Collapse two levels of monadic structure into a single level.
19 //! @ingroup group-Monad
21 //! Given a monadic value wrapped into two levels of monad, `flatten`
22 //! removes one such level. An implementation of `flatten` must satisfy
24 //! flatten(xs) == chain(xs, id)
27 //! For `Sequence`s, this simply takes a `Sequence` of `Sequence`s, and
28 //! returns a (non-recursively) flattened `Sequence`.
33 //! For a `Monad` `M`, the signature of `flatten` is
35 //! \mathtt{flatten} : M(M(T)) \to M(T)
39 //! A value with two levels of monadic structure, which should be
40 //! collapsed into a single level of structure.
45 //! @include example/flatten.cpp
46 #ifdef BOOST_HANA_DOXYGEN_INVOKED
47 constexpr auto flatten = [](auto&& xs) {
48 return tag-dispatched;
51 template <typename M, typename = void>
52 struct flatten_impl : flatten_impl<M, when<true>> { };
55 template <typename Xs>
56 constexpr auto operator()(Xs&& xs) const;
59 constexpr flatten_t flatten{};
61 BOOST_HANA_NAMESPACE_END
63 #endif // !BOOST_HANA_FWD_FLATTEN_HPP