]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/hana/replicate.hpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / boost / hana / replicate.hpp
1 /*!
2 @file
3 Defines `boost::hana::replicate`.
4
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)
8 */
9
10 #ifndef BOOST_HANA_REPLICATE_HPP
11 #define BOOST_HANA_REPLICATE_HPP
12
13 #include <boost/hana/fwd/replicate.hpp>
14
15 #include <boost/hana/concept/integral_constant.hpp>
16 #include <boost/hana/concept/monad_plus.hpp>
17 #include <boost/hana/config.hpp>
18 #include <boost/hana/core/dispatch.hpp>
19 #include <boost/hana/core/make.hpp>
20 #include <boost/hana/cycle.hpp>
21 #include <boost/hana/lift.hpp>
22
23 #include <cstddef>
24 #include <utility>
25
26
27 BOOST_HANA_NAMESPACE_BEGIN
28 //! @cond
29 template <typename M>
30 template <typename X, typename N>
31 constexpr auto replicate_t<M>::operator()(X&& x, N const& n) const {
32 using Replicate = BOOST_HANA_DISPATCH_IF(replicate_impl<M>,
33 hana::MonadPlus<M>::value &&
34 hana::IntegralConstant<N>::value
35 );
36
37 #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS
38 static_assert(hana::MonadPlus<M>::value,
39 "hana::replicate<M>(x, n) requires 'M' to be a MonadPlus");
40
41 static_assert(hana::IntegralConstant<N>::value,
42 "hana::replicate<M>(x, n) requires 'n' to be an IntegralConstant");
43 #endif
44
45 return Replicate::apply(static_cast<X&&>(x), n);
46 }
47 //! @endcond
48
49 template <typename M, bool condition>
50 struct replicate_impl<M, when<condition>> : default_ {
51 template <typename X, typename N>
52 static constexpr auto apply(X&& x, N const& n) {
53 return hana::cycle(hana::lift<M>(static_cast<X&&>(x)), n);
54 }
55 };
56
57 template <typename S>
58 struct replicate_impl<S, when<Sequence<S>::value>> {
59 template <typename X, std::size_t ...i>
60 static constexpr auto replicate_helper(X&& x, std::index_sequence<i...>)
61 { return hana::make<S>(((void)i, x)...); }
62
63 template <typename X, typename N>
64 static constexpr auto apply(X&& x, N const&) {
65 constexpr std::size_t n = N::value;
66 return replicate_helper(static_cast<X&&>(x),
67 std::make_index_sequence<n>{});
68 }
69 };
70 BOOST_HANA_NAMESPACE_END
71
72 #endif // !BOOST_HANA_REPLICATE_HPP