Back to home page

EIC code displayed by LXR

 
 

    


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

0001 /*!
0002 @file
0003 Defines `boost::hana::fill`.
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_FILL_HPP
0011 #define BOOST_HANA_FILL_HPP
0012 
0013 #include <boost/hana/fwd/fill.hpp>
0014 
0015 #include <boost/hana/concept/functor.hpp>
0016 #include <boost/hana/concept/sequence.hpp>
0017 #include <boost/hana/config.hpp>
0018 #include <boost/hana/core/dispatch.hpp>
0019 #include <boost/hana/core/make.hpp>
0020 #include <boost/hana/functional/always.hpp>
0021 #include <boost/hana/transform.hpp>
0022 #include <boost/hana/unpack.hpp>
0023 
0024 
0025 namespace boost { namespace hana {
0026     //! @cond
0027     template <typename Xs, typename Value>
0028     constexpr auto fill_t::operator()(Xs&& xs, Value&& value) const {
0029         using S = typename hana::tag_of<Xs>::type;
0030         using Fill = BOOST_HANA_DISPATCH_IF(fill_impl<S>,
0031             hana::Functor<S>::value
0032         );
0033 
0034     #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS
0035         static_assert(hana::Functor<S>::value,
0036         "hana::fill(xs, value) requires 'xs' to be a Functor");
0037     #endif
0038 
0039         return Fill::apply(static_cast<Xs&&>(xs),
0040                            static_cast<Value&&>(value));
0041     }
0042     //! @endcond
0043 
0044     template <typename Fun, bool condition>
0045     struct fill_impl<Fun, when<condition>> : default_ {
0046         template <typename Xs, typename Value>
0047         static constexpr auto apply(Xs&& xs, Value&& v) {
0048             return hana::transform(static_cast<Xs&&>(xs),
0049                                    hana::always(static_cast<Value&&>(v))
0050             );
0051         }
0052     };
0053 
0054     template <typename S>
0055     struct fill_impl<S, when<Sequence<S>::value>> {
0056         //! @cond
0057         template <typename V>
0058         struct filler {
0059             V const& v;
0060             template <typename ...Xs>
0061             constexpr auto operator()(Xs const& ...xs) const {
0062                 return hana::make<S>(((void)xs, v)...);
0063             }
0064         };
0065         //! @endcond
0066 
0067         template <typename Xs, typename V>
0068         static constexpr auto apply(Xs const& xs, V const& v) {
0069             return hana::unpack(xs, filler<V>{v});
0070         }
0071     };
0072 }} // end namespace boost::hana
0073 
0074 #endif // !BOOST_HANA_FILL_HPP