Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:38:06

0001 /*!
0002 @file
0003 Defines `boost::hana::transform`.
0004 
0005 Copyright Louis Dionne 2013-2022
0006 Distributed under the Boost Software License, Version 1.0.
0007 (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
0008  */
0009 
0010 #ifndef BOOST_HANA_TRANSFORM_HPP
0011 #define BOOST_HANA_TRANSFORM_HPP
0012 
0013 #include <boost/hana/fwd/transform.hpp>
0014 
0015 #include <boost/hana/bool.hpp>
0016 #include <boost/hana/concept/functor.hpp>
0017 #include <boost/hana/concept/sequence.hpp>
0018 #include <boost/hana/config.hpp>
0019 #include <boost/hana/core/dispatch.hpp>
0020 #include <boost/hana/core/make.hpp>
0021 #include <boost/hana/functional/always.hpp>
0022 #include <boost/hana/fwd/adjust_if.hpp>
0023 #include <boost/hana/unpack.hpp>
0024 
0025 
0026 namespace boost { namespace hana {
0027     //! @cond
0028     template <typename Xs, typename F>
0029     constexpr auto transform_t::operator()(Xs&& xs, F&& f) const {
0030         using S = typename hana::tag_of<Xs>::type;
0031         using Transform = BOOST_HANA_DISPATCH_IF(transform_impl<S>,
0032             hana::Functor<S>::value
0033         );
0034 
0035     #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS
0036         static_assert(hana::Functor<S>::value,
0037         "hana::transform(xs, f) requires 'xs' to be a Functor");
0038     #endif
0039 
0040         return Transform::apply(static_cast<Xs&&>(xs), static_cast<F&&>(f));
0041     }
0042     //! @endcond
0043 
0044     template <typename Fun, bool condition>
0045     struct transform_impl<Fun, when<condition>> : default_ {
0046         template <typename Xs, typename F>
0047         static constexpr auto apply(Xs&& xs, F&& f) {
0048             return hana::adjust_if(static_cast<Xs&&>(xs),
0049                                    hana::always(hana::true_c),
0050                                    static_cast<F&&>(f));
0051         }
0052     };
0053 
0054     template <typename S>
0055     struct transform_impl<S, when<Sequence<S>::value>> {
0056         //! @cond
0057         template <typename F>
0058         struct transformer {
0059             F f;
0060             template <typename ...Xs>
0061             constexpr auto operator()(Xs&& ...xs) const {
0062                 return hana::make<S>((*f)(static_cast<Xs&&>(xs))...);
0063             }
0064         };
0065         //! @endcond
0066 
0067         template <typename Xs, typename F>
0068         static constexpr auto apply(Xs&& xs, F&& f) {
0069             // We use a pointer to workaround a Clang 3.5 ICE
0070             return hana::unpack(static_cast<Xs&&>(xs),
0071                                 transformer<decltype(&f)>{&f});
0072         }
0073     };
0074 }} // end namespace boost::hana
0075 
0076 #endif // !BOOST_HANA_TRANSFORM_HPP