Skip to content

Commit

Permalink
initial fill algo
Browse files Browse the repository at this point in the history
  • Loading branch information
ahanamuk committed Jun 11, 2020
1 parent a685197 commit c9f134f
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 0 deletions.
35 changes: 35 additions & 0 deletions stl/inc/algorithm
Original file line number Diff line number Diff line change
Expand Up @@ -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 <class _FwdIt, class _T>

This comment has been minimized.

Copy link
@CaseyCarter

CaseyCarter Jun 12, 2020

Member

Oops


// VARIABLE ranges::fill
class _Fill_fn : private _Not_quite_object {
public:
using _Not_quite_object::_Not_quite_object;

// clang-format off
template <class _T, output_iterator<const _T&> _O, sentinel_for<_O> _S>
constexpr _O operator()(_O _First, _S _Last, const _T& _Value) const {

This comment has been minimized.

Copy link
@miscco

miscco Jun 12, 2020

Contributor

Conventionally the STL avoids single character identifiers. Usually the out iterator is named _Out

This comment has been minimized.

Copy link
@CaseyCarter

CaseyCarter Jun 12, 2020

Member

I'd name these template parameters _Ty, _It, and _Se. (_Out is really only useful when there's an input iterator to distinguish it from.)

_Adl_verify_range(_First, _Last);
auto _UFirst = _Get_unwrapped(_STD move(_First));
auto _ULast = _Get_unwrapped(_STD move(_Last));

This comment has been minimized.

Copy link
@miscco

miscco Jun 12, 2020

Contributor

Conventionally equal signs are aligned. Maybe you could reenable clang format after the Funktion signature

This comment has been minimized.

Copy link
@CaseyCarter

CaseyCarter Jun 12, 2020

Member

I think we can just remove the // clang-format meow comments and let clang-format handle all of this class; there are no requires-clauses or concept definitions here to make it go nuts.

while (_UFirst != _ULast) {
*_UFirst = _Value;
++_UFirst;
}

_Seek_wrapped(_First, _STD move(_UFirst));
return _First;
}

template <class _T, output_range<const _T&> _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 <class _FwdIt, class _Fn>
_CONSTEXPR20 void generate(_FwdIt _First, _FwdIt _Last, _Fn _Func) { // replace [_First, _Last) with _Func()
Expand Down
1 change: 1 addition & 0 deletions tests/std/test.lst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions tests/std/tests/P0896R4_ranges_alg_fill/env.lst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright (c) Microsoft Corporation.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

RUNALL_INCLUDE ..\concepts_matrix.lst
39 changes: 39 additions & 0 deletions tests/std/tests/P0896R4_ranges_alg_fill/test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright (c) Microsoft Corporation.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#include <algorithm>
#include <cassert>
#include <concepts>
#include <ranges>
#include <utility>
#include <range_algorithm_support.hpp>

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);

This comment has been minimized.

Copy link
@miscco

miscco Jun 12, 2020

Contributor

If you value as a variable you might reuse it here

}
assert(result == output.end());
}
}

int main() {
// STATIC_ASSERT((smoke_test(), true));

This comment has been minimized.

Copy link
@miscco

miscco Jun 12, 2020

Contributor

Is there a reason for deactivating the compile time test?

smoke_test();
}

struct instantiator {
template <class In>
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<instantiator>();

0 comments on commit c9f134f

Please sign in to comment.