File indexing completed on 2025-01-18 10:09:42
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #ifndef RANGES_V3_ACTION_PUSH_FRONT_HPP
0015 #define RANGES_V3_ACTION_PUSH_FRONT_HPP
0016
0017 #include <utility>
0018
0019 #include <meta/meta.hpp>
0020
0021 #include <range/v3/range_fwd.hpp>
0022
0023 #include <range/v3/action/action.hpp>
0024 #include <range/v3/action/insert.hpp>
0025 #include <range/v3/detail/with_braced_init_args.hpp>
0026 #include <range/v3/functional/bind_back.hpp>
0027 #include <range/v3/utility/static_const.hpp>
0028
0029 #include <range/v3/detail/prologue.hpp>
0030
0031 namespace ranges
0032 {
0033
0034
0035
0036
0037 namespace adl_push_front_detail
0038 {
0039
0040 template<typename Cont, typename T>
0041 using push_front_t = decltype(static_cast<void>(
0042 unwrap_reference(std::declval<Cont &>()).push_front(std::declval<T>())));
0043
0044 template<typename Cont, typename Rng>
0045 using insert_t = decltype(static_cast<void>(
0046 ranges::insert(std::declval<Cont &>(), std::declval<iterator_t<Cont>>(),
0047 std::declval<Rng>())));
0048
0049 template(typename Cont, typename T)(
0050 requires lvalue_container_like<Cont> AND
0051 (!range<T>) AND constructible_from<range_value_t<Cont>, T>)
0052 push_front_t<Cont, T> push_front(Cont && cont, T && t)
0053 {
0054 unwrap_reference(cont).push_front(static_cast<T &&>(t));
0055 }
0056
0057 template(typename Cont, typename Rng)(
0058 requires lvalue_container_like<Cont> AND range<Rng>)
0059 insert_t<Cont, Rng> push_front(Cont && cont, Rng && rng)
0060 {
0061 ranges::insert(cont, begin(cont), static_cast<Rng &&>(rng));
0062 }
0063
0064
0065
0066
0067
0068 template<typename Rng, typename T>
0069 CPP_requires(can_push_front_frag_,
0070 requires(Rng && rng, T && t)
0071 (
0072 push_front(rng, (T &&) t)
0073 ));
0074
0075
0076 template<typename Rng, typename T>
0077 CPP_concept can_push_front_ =
0078 CPP_requires_ref(adl_push_front_detail::can_push_front_frag_, Rng, T);
0079
0080
0081
0082 struct push_front_fn
0083 {
0084 template<typename T>
0085 constexpr auto operator()(T && val) const
0086 {
0087 return make_action_closure(
0088 bind_back(push_front_fn{}, static_cast<T &&>(val)));
0089 }
0090
0091 template<typename T>
0092 constexpr auto operator()(std::initializer_list<T> val) const
0093 {
0094 return make_action_closure(bind_back(push_front_fn{}, val));
0095 }
0096
0097 template(typename T)(
0098 requires range<T &>)
0099 constexpr auto operator()(T & t) const
0100 {
0101 return make_action_closure(
0102 bind_back(push_front_fn{}, detail::reference_wrapper_<T>(t)));
0103 }
0104
0105 template(typename Rng, typename T)(
0106 requires input_range<Rng> AND can_push_front_<Rng, T> AND
0107 (range<T> || constructible_from<range_value_t<Rng>, T>))
0108 Rng operator()(Rng && rng, T && t) const
0109 {
0110 push_front(rng, static_cast<T &&>(t));
0111 return static_cast<Rng &&>(rng);
0112 }
0113
0114 template(typename Rng, typename T)(
0115 requires input_range<Rng> AND
0116 can_push_front_<Rng, std::initializer_list<T>> AND
0117 constructible_from<range_value_t<Rng>, T const &>)
0118 Rng operator()(Rng && rng, std::initializer_list<T> t) const
0119 {
0120 push_front(rng, t);
0121 return static_cast<Rng &&>(rng);
0122 }
0123
0124
0125 template<typename Rng, typename T>
0126 invoke_result_t<push_front_fn, Rng, T &>
0127 operator()(Rng && rng, detail::reference_wrapper_<T> r) const
0128 {
0129 return (*this)(static_cast<Rng &&>(rng), r.get());
0130 }
0131
0132 };
0133
0134 }
0135
0136
0137 namespace actions
0138 {
0139 RANGES_INLINE_VARIABLE(adl_push_front_detail::push_front_fn, push_front)
0140 }
0141
0142 using actions::push_front;
0143
0144
0145 }
0146
0147 #include <range/v3/detail/epilogue.hpp>
0148
0149 #endif