From c9f134f7b8bbc4bde4d4d87a42a6f493552b5968 Mon Sep 17 00:00:00 2001 From: Ahana Mukhopadhyay Date: Thu, 11 Jun 2020 13:35:17 -0400 Subject: [PATCH] initial fill algo --- stl/inc/algorithm | 35 +++++++++++++++++ tests/std/test.lst | 1 + .../std/tests/P0896R4_ranges_alg_fill/env.lst | 4 ++ .../tests/P0896R4_ranges_alg_fill/test.cpp | 39 +++++++++++++++++++ 4 files changed, 79 insertions(+) create mode 100644 tests/std/tests/P0896R4_ranges_alg_fill/env.lst create mode 100644 tests/std/tests/P0896R4_ranges_alg_fill/test.cpp diff --git a/stl/inc/algorithm b/stl/inc/algorithm index 55a9f1e847..943226e6ac 100644 --- a/stl/inc/algorithm +++ b/stl/inc/algorithm @@ -2388,6 +2388,41 @@ _FwdIt2 replace_copy_if(_ExPo&&, _FwdIt1 _First, _FwdIt1 _Last, _FwdIt2 _Dest, _ } #endif // _HAS_CXX17 +#ifdef __cpp_lib_concepts +namespace ranges { + template + + // VARIABLE ranges::fill + class _Fill_fn : private _Not_quite_object { + public: + using _Not_quite_object::_Not_quite_object; + + // clang-format off + template _O, sentinel_for<_O> _S> + constexpr _O operator()(_O _First, _S _Last, const _T& _Value) const { + _Adl_verify_range(_First, _Last); + auto _UFirst = _Get_unwrapped(_STD move(_First)); + auto _ULast = _Get_unwrapped(_STD move(_Last)); + while (_UFirst != _ULast) { + *_UFirst = _Value; + ++_UFirst; + } + + _Seek_wrapped(_First, _STD move(_UFirst)); + return _First; + } + + template _Rng> + constexpr borrowed_iterator_t<_Rng> operator()(_Rng&& _Range, const _T& _Value) const { + return (*this)(_RANGES begin(_Range), _RANGES end(_Range), _Value) + } + // clang-format on + }; + + inline constexpr _Fill_fn fill{_Not_quite_object::_Construct_tag{}}; +} // namespace ranges +#endif // __cpp_lib_concepts + // FUNCTION TEMPLATE generate template _CONSTEXPR20 void generate(_FwdIt _First, _FwdIt _Last, _Fn _Func) { // replace [_First, _Last) with _Func() diff --git a/tests/std/test.lst b/tests/std/test.lst index 1ac2abf208..d9ab9d6ee7 100644 --- a/tests/std/test.lst +++ b/tests/std/test.lst @@ -241,6 +241,7 @@ tests\P0896R4_ranges_alg_copy_n tests\P0896R4_ranges_alg_count tests\P0896R4_ranges_alg_count_if tests\P0896R4_ranges_alg_equal +tests\P0896R4_ranges_alg_fill tests\P0896R4_ranges_alg_find tests\P0896R4_ranges_alg_find_end tests\P0896R4_ranges_alg_find_first_of diff --git a/tests/std/tests/P0896R4_ranges_alg_fill/env.lst b/tests/std/tests/P0896R4_ranges_alg_fill/env.lst new file mode 100644 index 0000000000..f3ccc8613c --- /dev/null +++ b/tests/std/tests/P0896R4_ranges_alg_fill/env.lst @@ -0,0 +1,4 @@ +# Copyright (c) Microsoft Corporation. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +RUNALL_INCLUDE ..\concepts_matrix.lst diff --git a/tests/std/tests/P0896R4_ranges_alg_fill/test.cpp b/tests/std/tests/P0896R4_ranges_alg_fill/test.cpp new file mode 100644 index 0000000000..e65197dd78 --- /dev/null +++ b/tests/std/tests/P0896R4_ranges_alg_fill/test.cpp @@ -0,0 +1,39 @@ +// Copyright (c) Microsoft Corporation. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +#include +#include +#include +#include +#include +#include + +constexpr void smoke_test() { + using ranges::fill, ranges::iterator_t; + using std::same_as; + + int output[] = {13, 42, 1367}; + { + const int value = 7; + auto result = fill(output.begin(), output.end(), value); + for (int i = 0; i < 3; ++i) { + assert(output[i] == 7); + } + assert(result == output.end()); + } +} + +int main() { + // STATIC_ASSERT((smoke_test(), true)); + smoke_test(); +} + +struct instantiator { + template + static void call(In&& in = {}) { + (void) ranges::fill(in, SOMETHING); + (void) ranges::fill(ranges::begin(in), ranges::end(in), SOMETHING); + } +}; + +template void test_in_out();