diff --git a/absl/algorithm/container.h b/absl/algorithm/container.h index 20ba4a30..838f0db0 100644 --- a/absl/algorithm/container.h +++ b/absl/algorithm/container.h @@ -174,6 +174,25 @@ template struct IsIterator< Iter, std::void_t::iterator_category>> : std::true_type {}; + +template +using ResultOfRangeToIteratorTransfer = + std::enable_if_t>::value && + !container_algorithm_internal::IsMultidimensionalArray< + std::remove_reference_t>::value, + std::decay_t>; + +template +using ResultOfRangeToRangeTransfer = + std::enable_if_t>::value && + !container_algorithm_internal::IsMultidimensionalArray< + std::remove_reference_t>::value && + !container_algorithm_internal::IsMultidimensionalArray< + std::remove_reference_t>::value, + void>; + } // namespace container_algorithm_internal // PUBLIC API @@ -577,12 +596,8 @@ ABSL_INTERNAL_CONSTEXPR_SINCE_CXX20 // Container-based version of the `std::copy()` function to copy a // container's elements into an iterator. template -ABSL_INTERNAL_CONSTEXPR_SINCE_CXX20 - std::enable_if_t>::value && - !container_algorithm_internal::IsMultidimensionalArray< - InputSequence>::value, - std::decay_t> +ABSL_INTERNAL_CONSTEXPR_SINCE_CXX20 container_algorithm_internal:: + ResultOfRangeToIteratorTransfer c_copy(const InputSequence& input, OutputIterator&& output) { return std::copy(container_algorithm_internal::c_begin(input), container_algorithm_internal::c_end(input), @@ -601,13 +616,8 @@ ABSL_INTERNAL_CONSTEXPR_SINCE_CXX20 // are copied, and `output` is not truncated. template ABSL_INTERNAL_CONSTEXPR_SINCE_CXX20 - std::enable_if_t>::value && - !container_algorithm_internal::IsMultidimensionalArray< - std::remove_reference_t>::value && - !container_algorithm_internal::IsMultidimensionalArray< - InputSequence>::value, - void> + container_algorithm_internal::ResultOfRangeToRangeTransfer c_copy(const InputSequence& input, OutputRange&& output) { container_algorithm_internal::AssertCopySize(input, output); absl::c_copy(input, container_algorithm_internal::c_begin( @@ -619,12 +629,9 @@ ABSL_INTERNAL_CONSTEXPR_SINCE_CXX20 // Container-based version of the `std::copy_n()` function to copy a // container's first N elements into an iterator. template -ABSL_INTERNAL_CONSTEXPR_SINCE_CXX20 std::enable_if_t< - container_algorithm_internal::IsIterator< - absl::remove_cvref_t>::value && - !container_algorithm_internal::IsMultidimensionalArray::value, - std::decay_t> -c_copy_n(const C& input, Size n, OutputIterator&& output) { +ABSL_INTERNAL_CONSTEXPR_SINCE_CXX20 container_algorithm_internal:: + ResultOfRangeToIteratorTransfer + c_copy_n(const C& input, Size n, OutputIterator&& output) { return std::copy_n(container_algorithm_internal::c_begin(input), n, std::forward(output)); } @@ -641,14 +648,9 @@ c_copy_n(const C& input, Size n, OutputIterator&& output) { // If `std::size(output) > n`, only `n` elements are copied, and `output` is not // truncated. template -ABSL_INTERNAL_CONSTEXPR_SINCE_CXX20 std::enable_if_t< - container_algorithm_internal::HasBeginEnd< - std::add_lvalue_reference_t>::value && - !container_algorithm_internal::IsMultidimensionalArray< - std::remove_reference_t>::value && - !container_algorithm_internal::IsMultidimensionalArray::value, - void> -c_copy_n(const C& input, Size n, OutputRange&& output) { +ABSL_INTERNAL_CONSTEXPR_SINCE_CXX20 + container_algorithm_internal::ResultOfRangeToRangeTransfer + c_copy_n(const C& input, Size n, OutputRange&& output) { container_algorithm_internal::AssertCopyNSize(input, n, output); absl::c_copy_n( input, n, @@ -683,12 +685,8 @@ c_copy_backward(const C& src, BidirectionalIterator dest) { // Container-based version of the `std::move()` function to move // a container's elements into an iterator. template -ABSL_INTERNAL_CONSTEXPR_SINCE_CXX20 - std::enable_if_t>::value && - !container_algorithm_internal::IsMultidimensionalArray< - std::remove_reference_t>::value, - std::decay_t> +ABSL_INTERNAL_CONSTEXPR_SINCE_CXX20 container_algorithm_internal:: + ResultOfRangeToIteratorTransfer c_move(C&& src, OutputIterator&& dest) { return std::move(container_algorithm_internal::c_begin(src), container_algorithm_internal::c_end(src), @@ -702,13 +700,7 @@ ABSL_INTERNAL_CONSTEXPR_SINCE_CXX20 // this function does not resize `dest`. template ABSL_INTERNAL_CONSTEXPR_SINCE_CXX20 - std::enable_if_t>::value && - !container_algorithm_internal::IsMultidimensionalArray< - std::remove_reference_t>::value && - !container_algorithm_internal::IsMultidimensionalArray< - std::remove_reference_t>::value, - void> + container_algorithm_internal::ResultOfRangeToRangeTransfer c_move(C&& src, OutputRange&& dest) { container_algorithm_internal::AssertCopySize(src, dest); absl::c_move(std::forward(src), container_algorithm_internal::c_begin(