From d26c8416fc1215ce5c343566055a6fca7f1f6336 Mon Sep 17 00:00:00 2001 From: Casey Carter Date: Tue, 13 Apr 2021 08:15:29 -0700 Subject: [PATCH] Push _Rewrap_iterator up into Fixes #1830 --- stl/inc/algorithm | 14 -------------- stl/inc/xutility | 14 ++++++++++++++ .../P0896R4_ranges_alg_uninitialized_copy/test.cpp | 13 ++++++++++++- 3 files changed, 26 insertions(+), 15 deletions(-) diff --git a/stl/inc/algorithm b/stl/inc/algorithm index e128b93569c..a748bbb800d 100644 --- a/stl/inc/algorithm +++ b/stl/inc/algorithm @@ -215,20 +215,6 @@ namespace ranges { } } - // FUNCTION TEMPLATE _Rewrap_iterator - template - _NODISCARD constexpr iterator_t<_Rng> _Rewrap_iterator(_Rng&& _Range, _It&& _Val) { - _STL_INTERNAL_STATIC_ASSERT(is_same_v, _Unwrapped_t>>); - - if constexpr (is_same_v, iterator_t<_Rng>>) { - return _STD forward<_It>(_Val); - } else { - auto _Result = _RANGES begin(_Range); - _Result._Seek_to(_STD forward<_It>(_Val)); - return _Result; - } - } - // FUNCTION TEMPLATE _Get_final_iterator_unwrapped template _Se> _NODISCARD constexpr auto _Get_final_iterator_unwrapped(const _Unwrapped_t<_Wrapped>& _UFirst, _Se&& _Last) { diff --git a/stl/inc/xutility b/stl/inc/xutility index 728c332e48e..2e17ebc0b5a 100644 --- a/stl/inc/xutility +++ b/stl/inc/xutility @@ -4766,6 +4766,20 @@ _NODISCARD bool equal(_ExPo&& _Exec, const _FwdIt1 _First1, const _FwdIt1 _Last1 #ifdef __cpp_lib_concepts namespace ranges { + // FUNCTION TEMPLATE _Rewrap_iterator + template + _NODISCARD constexpr iterator_t<_Rng> _Rewrap_iterator(_Rng&& _Range, _It&& _Val) { + _STL_INTERNAL_STATIC_ASSERT(is_same_v, _Unwrapped_t>>); + + if constexpr (is_same_v, iterator_t<_Rng>>) { + return _STD forward<_It>(_Val); + } else { + auto _Result = _RANGES begin(_Range); + _Result._Seek_to(_STD forward<_It>(_Val)); + return _Result; + } + } + // CONCEPT _Convertible_from template concept _Convertible_from = convertible_to<_From, _To>; diff --git a/tests/std/tests/P0896R4_ranges_alg_uninitialized_copy/test.cpp b/tests/std/tests/P0896R4_ranges_alg_uninitialized_copy/test.cpp index 0199745aa45..331bda6932f 100644 --- a/tests/std/tests/P0896R4_ranges_alg_uninitialized_copy/test.cpp +++ b/tests/std/tests/P0896R4_ranges_alg_uninitialized_copy/test.cpp @@ -1,11 +1,22 @@ // Copyright (c) Microsoft Corporation. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +#include + +// Regression test for GH-1830, in which ranges::uninitialized_copy used +// _Rewrap_iterator which was defined in (now in ). + +void unused_function() { + const int src[] = {11, 22, 33, 44, 55}; + int dst[5]; + + std::ranges::uninitialized_copy(src, dst); +} + #include #include #include #include -#include #include #include #include