123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269 |
- #ifndef BOOST_HANA_FUNCTIONAL_DEMUX_HPP
- #define BOOST_HANA_FUNCTIONAL_DEMUX_HPP
- #include <boost/hana/basic_tuple.hpp>
- #include <boost/hana/config.hpp>
- #include <boost/hana/detail/decay.hpp>
- #include <cstddef>
- #include <utility>
- namespace boost { namespace hana {
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- #ifdef BOOST_HANA_DOXYGEN_INVOKED
- constexpr auto demux = [](auto&& f) {
- return [perfect-capture](auto&& ...g) {
- return [perfect-capture](auto&& ...x) -> decltype(auto) {
-
-
- return forwarded(f)(forwarded(g)(x...)...);
- };
- };
- };
- #else
- template <typename F>
- struct pre_demux_t;
- struct make_pre_demux_t {
- struct secret { };
- template <typename F>
- constexpr pre_demux_t<typename detail::decay<F>::type> operator()(F&& f) const {
- return {static_cast<F&&>(f)};
- }
- };
- template <typename Indices, typename F, typename ...G>
- struct demux_t;
- template <typename F>
- struct pre_demux_t {
- F f;
- template <typename ...G>
- constexpr demux_t<std::make_index_sequence<sizeof...(G)>, F,
- typename detail::decay<G>::type...>
- operator()(G&& ...g) const& {
- return {make_pre_demux_t::secret{}, this->f, static_cast<G&&>(g)...};
- }
- template <typename ...G>
- constexpr demux_t<std::make_index_sequence<sizeof...(G)>, F,
- typename detail::decay<G>::type...>
- operator()(G&& ...g) && {
- return {make_pre_demux_t::secret{}, static_cast<F&&>(this->f), static_cast<G&&>(g)...};
- }
- };
- template <std::size_t ...n, typename F, typename ...G>
- struct demux_t<std::index_sequence<n...>, F, G...> {
- template <typename ...T>
- constexpr demux_t(make_pre_demux_t::secret, T&& ...t)
- : storage_{static_cast<T&&>(t)...}
- { }
- basic_tuple<F, G...> storage_;
- template <typename ...X>
- constexpr decltype(auto) operator()(X&& ...x) const& {
- return hana::at_c<0>(storage_)(
- hana::at_c<n+1>(storage_)(x...)...
- );
- }
- template <typename ...X>
- constexpr decltype(auto) operator()(X&& ...x) & {
- return hana::at_c<0>(storage_)(
- hana::at_c<n+1>(storage_)(x...)...
- );
- }
- template <typename ...X>
- constexpr decltype(auto) operator()(X&& ...x) && {
- return static_cast<F&&>(hana::at_c<0>(storage_))(
- static_cast<G&&>(hana::at_c<n+1>(storage_))(x...)...
- );
- }
- };
- template <typename F, typename G>
- struct demux_t<std::index_sequence<0>, F, G> {
- template <typename ...T>
- constexpr demux_t(make_pre_demux_t::secret, T&& ...t)
- : storage_{static_cast<T&&>(t)...}
- { }
- basic_tuple<F, G> storage_;
- template <typename ...X>
- constexpr decltype(auto) operator()(X&& ...x) const& {
- return hana::at_c<0>(storage_)(
- hana::at_c<1>(storage_)(static_cast<X&&>(x)...)
- );
- }
- template <typename ...X>
- constexpr decltype(auto) operator()(X&& ...x) & {
- return hana::at_c<0>(storage_)(
- hana::at_c<1>(storage_)(static_cast<X&&>(x)...)
- );
- }
- template <typename ...X>
- constexpr decltype(auto) operator()(X&& ...x) && {
- return static_cast<F&&>(hana::at_c<0>(storage_))(
- static_cast<G&&>(hana::at_c<1>(storage_))(static_cast<X&&>(x)...)
- );
- }
- };
- BOOST_HANA_INLINE_VARIABLE constexpr make_pre_demux_t demux{};
- #endif
- }}
- #endif
|