3 Defines `boost::hana::transform`.
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_TRANSFORM_HPP
11 #define BOOST_HANA_TRANSFORM_HPP
13 #include <boost/hana/fwd/transform.hpp>
15 #include <boost/hana/bool.hpp>
16 #include <boost/hana/concept/functor.hpp>
17 #include <boost/hana/concept/sequence.hpp>
18 #include <boost/hana/config.hpp>
19 #include <boost/hana/core/dispatch.hpp>
20 #include <boost/hana/core/make.hpp>
21 #include <boost/hana/functional/always.hpp>
22 #include <boost/hana/fwd/adjust_if.hpp>
23 #include <boost/hana/unpack.hpp>
26 namespace boost { namespace hana {
28 template <typename Xs, typename F>
29 constexpr auto transform_t::operator()(Xs&& xs, F&& f) const {
30 using S = typename hana::tag_of<Xs>::type;
31 using Transform = BOOST_HANA_DISPATCH_IF(transform_impl<S>,
32 hana::Functor<S>::value
35 #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS
36 static_assert(hana::Functor<S>::value,
37 "hana::transform(xs, f) requires 'xs' to be a Functor");
40 return Transform::apply(static_cast<Xs&&>(xs), static_cast<F&&>(f));
44 template <typename Fun, bool condition>
45 struct transform_impl<Fun, when<condition>> : default_ {
46 template <typename Xs, typename F>
47 static constexpr auto apply(Xs&& xs, F&& f) {
48 return hana::adjust_if(static_cast<Xs&&>(xs),
49 hana::always(hana::true_c),
55 struct transform_impl<S, when<Sequence<S>::value>> {
60 template <typename ...Xs>
61 constexpr auto operator()(Xs&& ...xs) const {
62 return hana::make<S>((*f)(static_cast<Xs&&>(xs))...);
67 template <typename Xs, typename F>
68 static constexpr auto apply(Xs&& xs, F&& f) {
69 // We use a pointer to workaround a Clang 3.5 ICE
70 return hana::unpack(static_cast<Xs&&>(xs),
71 transformer<decltype(&f)>{&f});
74 }} // end namespace boost::hana
76 #endif // !BOOST_HANA_TRANSFORM_HPP