Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:43:36

0001 /*!
0002 @file
0003 Defines `boost::hana::insert`.
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_INSERT_HPP
0011 #define BOOST_HANA_INSERT_HPP
0012 
0013 #include <boost/hana/fwd/insert.hpp>
0014 
0015 #include <boost/hana/append.hpp>
0016 #include <boost/hana/concat.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/drop_front.hpp>
0021 #include <boost/hana/take_front.hpp>
0022 
0023 
0024 namespace boost { namespace hana {
0025     //! @cond
0026     template <typename Set, typename ...Args>
0027     constexpr decltype(auto) insert_t::operator()(Set&& set, Args&& ...args) const {
0028         return insert_impl<typename hana::tag_of<Set>::type>::apply(
0029             static_cast<Set&&>(set),
0030             static_cast<Args&&>(args)...
0031         );
0032     }
0033     //! @endcond
0034 
0035     template <typename T, bool condition>
0036     struct insert_impl<T, when<condition>> : default_ {
0037         template <typename ...Args>
0038         static constexpr auto apply(Args&& ...) = delete;
0039     };
0040 
0041     template <typename S>
0042     struct insert_impl<S, when<Sequence<S>::value>> {
0043         template <typename Xs, typename N, typename Element>
0044         static constexpr auto apply(Xs&& xs, N const& n, Element&& e) {
0045             return hana::concat(hana::append(hana::take_front(xs, n),
0046                                              static_cast<Element&&>(e)),
0047                                 hana::drop_front(xs, n));
0048         }
0049     };
0050 }} // end namespace boost::hana
0051 
0052 #endif // !BOOST_HANA_INSERT_HPP