VCCC  2024.05
VisualCamp Common C++ library
copy.hpp
Go to the documentation of this file.
1 //
2 // Created by yonggyulee on 1/12/24.
3 //
4 
5 #ifndef VCCC_ALGORITHM_RANGES_COPY_HPP
6 #define VCCC_ALGORITHM_RANGES_COPY_HPP
7 
8 #include <type_traits>
9 #include <utility>
10 
18 #include "vccc/__ranges/begin.hpp"
20 #include "vccc/__ranges/end.hpp"
24 
25 namespace vccc {
26 namespace ranges {
27 
28 template<typename I, typename O> using copy_result = in_out_result<I, O>;
29 template<typename I, typename O> using copy_if_result = in_out_result<I, O>;
30 
31 namespace detail {
32 
33 struct copy_niebloid {
34  private:
36  struct check_range : std::false_type {};
37  template<typename R, typename O>
38  struct check_range<R, O, true>
39  : conjunction<
40  weakly_incrementable<O>,
41  indirectly_copyable<iterator_t<R>, O>,
42  has_typename_type<borrowed_iterator<R>>
43  > {};
44 
45  public:
46  template<typename I, typename S, typename O, std::enable_if_t<conjunction<
51  >::value, int> = 0>
52  constexpr copy_result<I, O> operator()(I first, S last, O result) const {
53  for (; first != last; ++first, (void)++result)
54  *result = *first;
55  return {std::move(first), std::move(result)};
56  }
57 
59  constexpr copy_result<borrowed_iterator_t<R>, O> operator()(R&& r, O result) const {
60  return (*this)(ranges::begin(r), ranges::end(r), std::move(result));
61  }
62 };
63 
64 } // namespace detail
65 
68 
69 VCCC_INLINE_OR_STATIC constexpr detail::copy_niebloid copy{};
70 
72 
73 } // namespace ranges
74 } // namespace vccc
75 
76 #endif // VCCC_ALGORITHM_RANGES_COPY_HPP
constexpr VCCC_INLINE_OR_STATIC detail::copy_niebloid copy
Definition: copy.hpp:69
constexpr VCCC_INLINE_OR_STATIC detail::begin_niebloid begin
returns an iterator to the beginning of a range
Definition: begin.hpp:116
constexpr VCCC_INLINE_OR_STATIC detail::end_niebloid end
returns a sentinel indicating the end of a range
Definition: end.hpp:120
#define VCCC_INLINE_OR_STATIC
Definition: inline_or_static.hpp:9
Definition: directory.h:12
constexpr VCCC_INLINE_OR_STATIC detail::element_niebloid< 0 > first
Definition: key_value.hpp:34
constexpr VCCC_INLINE_OR_STATIC detail::element_niebloid< 1 > value
Definition: key_value.hpp:35
Definition: conjunction.hpp:22
specifies that values may be copied from an indirectly_readable type to an indirectly_writable type
Definition: indirectly_copyable.hpp:39
specifies that a type is an input iterator, that is, its referenced values can be read and it can be ...
Definition: input_iterator.hpp:55
Definition: in_out_result.hpp:22
Definition: sentinel_for.hpp:24
Definition: weakly_incrementable.hpp:52