1 /*! 2 @file 3 Forward declares `boost::hana::flatten`. 4 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) 8 */ 9 10 #ifndef BOOST_HANA_FWD_FLATTEN_HPP 11 #define BOOST_HANA_FWD_FLATTEN_HPP 12 13 #include <boost/hana/config.hpp> 14 #include <boost/hana/core/when.hpp> 15 16 17 BOOST_HANA_NAMESPACE_BEGIN 18 //! Collapse two levels of monadic structure into a single level. 19 //! @ingroup group-Monad 20 //! 21 //! Given a monadic value wrapped into two levels of monad, `flatten` 22 //! removes one such level. An implementation of `flatten` must satisfy 23 //! @code 24 //! flatten(xs) == chain(xs, id) 25 //! @endcode 26 //! 27 //! For `Sequence`s, this simply takes a `Sequence` of `Sequence`s, and 28 //! returns a (non-recursively) flattened `Sequence`. 29 //! 30 //! 31 //! Signature 32 //! --------- 33 //! For a `Monad` `M`, the signature of `flatten` is 34 //! @f$ 35 //! \mathtt{flatten} : M(M(T)) \to M(T) 36 //! @f$ 37 //! 38 //! @param xs 39 //! A value with two levels of monadic structure, which should be 40 //! collapsed into a single level of structure. 41 //! 42 //! 43 //! Example 44 //! ------- 45 //! @include example/flatten.cpp 46 #ifdef BOOST_HANA_DOXYGEN_INVOKED __anon82d3082e0102(auto&& xs) 47 constexpr auto flatten = [](auto&& xs) { 48 return tag-dispatched; 49 }; 50 #else 51 template <typename M, typename = void> 52 struct flatten_impl : flatten_impl<M, when<true>> { }; 53 54 struct flatten_t { 55 template <typename Xs> 56 constexpr auto operator()(Xs&& xs) const; 57 }; 58 59 constexpr flatten_t flatten{}; 60 #endif 61 BOOST_HANA_NAMESPACE_END 62 63 #endif // !BOOST_HANA_FWD_FLATTEN_HPP 64