Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion stl/inc/algorithm
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ namespace ranges {

template <forward_iterator _It, sentinel_for<_It> _Se, class _Pj = identity,
indirect_binary_predicate<projected<_It, _Pj>, projected<_It, _Pj>> _Pr = ranges::equal_to>
_NODISCARD constexpr _It operator()(_It _First, const _Se _Last, _Pr _Pred = {}, _Pj _Proj = {}) const {
_NODISCARD constexpr _It operator()(_It _First, _Se _Last, _Pr _Pred = {}, _Pj _Proj = {}) const {
_Adl_verify_range(_First, _Last);

auto _UResult = _Adjacent_find_unchecked(
Expand Down
12 changes: 4 additions & 8 deletions stl/inc/memory
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ namespace ranges {

private:
template <class _It, class _Se, class _Ty>
_NODISCARD static _It _Uninitialized_fill_unchecked(_It _OFirst, const _Se _OLast, const _Ty& _Val) {
_NODISCARD static _It _Uninitialized_fill_unchecked(_It _OFirst, _Se _OLast, const _Ty& _Val) {
_STL_INTERNAL_STATIC_ASSERT(_No_throw_forward_iterator<_It>);
_STL_INTERNAL_STATIC_ASSERT(_No_throw_sentinel_for<_Se, _It>);
_STL_INTERNAL_STATIC_ASSERT(constructible_from<iter_value_t<_It>, const _Ty&>);
Expand Down Expand Up @@ -792,16 +792,13 @@ namespace ranges {

private:
template <class _It, class _Se>
_NODISCARD static _It _Uninitialized_value_construct_unchecked(_It _OFirst, const _Se _OLast) {
_NODISCARD static _It _Uninitialized_value_construct_unchecked(_It _OFirst, _Se _OLast) {
_STL_INTERNAL_STATIC_ASSERT(_No_throw_forward_iterator<_It>);
_STL_INTERNAL_STATIC_ASSERT(_No_throw_sentinel_for<_Se, _It>);
_STL_INTERNAL_STATIC_ASSERT(default_initializable<iter_value_t<_It>>);

if constexpr (_Use_memset_value_construct_v<_It>) {
const auto _OFinal = _RANGES next(_OFirst, _STD move(_OLast));
const auto _Count = static_cast<size_t>(_OFinal - _OFirst);
_CSTD memset(_OFirst, 0, _Count);
return _OFinal;
return _Zero_range(_OFirst, _RANGES next(_OFirst, _STD move(_OLast)));
} else {
_Uninitialized_backout _Backout{_STD move(_OFirst)};

Expand Down Expand Up @@ -850,8 +847,7 @@ namespace ranges {

auto _UFirst = _Get_unwrapped_n(_STD move(_First), _Count);
if constexpr (_Use_memset_value_construct_v<_It>) {
_CSTD memset(_UFirst, 0, static_cast<size_t>(_Count));
_Seek_wrapped(_First, _UFirst + _Count);
_Seek_wrapped(_First, _Zero_range(_UFirst, _UFirst + _Count));
} else {
_Uninitialized_backout _Backout{_STD move(_UFirst)};

Expand Down
15 changes: 15 additions & 0 deletions tests/std/tests/P0896R4_ranges_alg_uninitialized_fill/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,20 @@ struct throwing_test {
}
};

struct memset_test {
static constexpr unsigned char expected[] = {42, 42, 42};

static void call() {
{ // Validate only range overload
unsigned char input[3];

const auto result = ranges::uninitialized_fill(input, static_cast<unsigned char>(42));
assert(result == end(input));
assert(ranges::equal(input, expected));
}
}
};

using test_range = test::range<test::fwd, int_wrapper, test::Sized::no, test::CanDifference::no, test::Common::no,
test::CanCompare::yes, test::ProxyRef::no>;

Expand All @@ -150,4 +164,5 @@ int main() {

instantiator::call<test_range>();
throwing_test::call<test_range>();
memset_test::call();
}
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,20 @@ struct throwing_test {
}
};

struct memset_test {
static constexpr unsigned char expected[] = {42, 42, 42};

static void call() {
{ // Validate only range overload
unsigned char input[3];

const auto result = ranges::uninitialized_fill_n(input, 3, static_cast<unsigned char>(42));
assert(result == end(input));
assert(ranges::equal(input, expected));
}
}
};

using test_range = test::range<test::fwd, int_wrapper, test::Sized::no, test::CanDifference::no, test::Common::no,
test::CanCompare::yes, test::ProxyRef::no>;

Expand All @@ -129,4 +143,5 @@ int main() {

instantiator::call<test_range>();
throwing_test::call<test_range>();
memset_test::call();
}
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,20 @@ struct throwing_test {
}
};

struct memset_test {
static constexpr int expected[] = {0, 0, 0};

static void call() {
{ // Validate only range overload
int input[3];

const auto result = ranges::uninitialized_value_construct(input);
assert(result == end(input));
assert(ranges::equal(input, expected));
}
}
};

using test_range = test::range<test::fwd, int_wrapper, test::Sized::no, test::CanDifference::no, test::Common::no,
test::CanCompare::yes, test::ProxyRef::no>;

Expand All @@ -130,4 +144,5 @@ int main() {

instantiator::call<test_range>();
throwing_test::call<test_range>();
memset_test::call();
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,20 @@ struct throwing_test {
}
};

struct memset_test {
static constexpr int expected[] = {0, 0, 0};

static void call() {
{ // Validate only range overload
int input[3];

const auto result = ranges::uninitialized_value_construct_n(begin(input), 3);
assert(result == end(input));
assert(ranges::equal(input, expected));
}
}
};

using test_range = test::range<test::fwd, int_wrapper, test::Sized::no, test::CanDifference::no, test::Common::no,
test::CanCompare::yes, test::ProxyRef::no>;

Expand All @@ -109,4 +123,5 @@ int main() {

instantiator::call<test_range>();
throwing_test::call<test_range>();
memset_test::call();
}