Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

<algorithm>: Implemented ranges::move #888

Merged
merged 24 commits into from
Jun 20, 2020
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
19c2a15
added the move algorithm on line 1265 of algorithm and created a new …
ahanamuk Jun 8, 2020
354e48b
added cmake file
ahanamuk Jun 8, 2020
09f6c9f
passing all tests for ranges move algorithm
ahanamuk Jun 8, 2020
61375a9
updated move algo tests to check that we actually move elems, not jus…
ahanamuk Jun 9, 2020
68640ed
enabled constexpr, cleaned up move algo test
ahanamuk Jun 9, 2020
5277552
removed iostream unused header
ahanamuk Jun 9, 2020
45fb14d
mainly updated formatting/comments based on feedback
ahanamuk Jun 10, 2020
80e349e
Delete cmake
ahanamuk Jun 10, 2020
d4f91b0
modified a test
ahanamuk Jun 11, 2020
a685197
Merge branch 'move_algo' of https://github.com/ahanamuk/STL
ahanamuk Jun 11, 2020
c9f134f
initial fill algo
ahanamuk Jun 11, 2020
93ff947
Passing all fill tests
ahanamuk Jun 11, 2020
be947f1
added a test case
ahanamuk Jun 11, 2020
5cb7bfc
minor changes/formatting updates to move
ahanamuk Jun 12, 2020
9170077
updated clang formatting
ahanamuk Jun 12, 2020
d4fbaac
initial fill algo
ahanamuk Jun 11, 2020
064684e
comitting untracked stuff
ahanamuk Jun 16, 2020
3f8fb49
cleaned up branch for move algo
ahanamuk Jun 16, 2020
3991e34
removed fill files
ahanamuk Jun 16, 2020
5582587
formatting update
ahanamuk Jun 16, 2020
73cf0f2
Merge branch 'master' into move
CaseyCarter Jun 16, 2020
492a007
Fix what Casey broke in the test_range PR
CaseyCarter Jun 16, 2020
7a899e5
Trim trailing whitespace
CaseyCarter Jun 16, 2020
4ffc678
minor updates
ahanamuk Jun 17, 2020
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
Empty file added cmake
Empty file.
39 changes: 39 additions & 0 deletions stl/inc/algorithm
Original file line number Diff line number Diff line change
Expand Up @@ -1263,6 +1263,43 @@ namespace ranges {
} // namespace ranges
#endif // __cpp_lib_concepts

#ifdef __cpp_lib_concepts

ahanamuk marked this conversation as resolved.
Show resolved Hide resolved
namespace ranges {
// ALIAS TEMPLATE copy_result
ahanamuk marked this conversation as resolved.
Show resolved Hide resolved
ahanamuk marked this conversation as resolved.
Show resolved Hide resolved
template <class _In, class _Out>
using move_result = in_out_result<_In, _Out>;

class _Move_fn : private _Not_quite_object {
ahanamuk marked this conversation as resolved.
Show resolved Hide resolved
public:
using _Not_quite_object::_Not_quite_object;

template <input_iterator _It, sentinel_for<_It> _Se, weakly_incrementable _Out>
requires indirectly_movable<_It, _Out> constexpr move_result<_It, _Out> operator()(
CaseyCarter marked this conversation as resolved.
Show resolved Hide resolved
_It _First, _Se _Last, _Out _Result) const {
ahanamuk marked this conversation as resolved.
Show resolved Hide resolved
_Adl_verify_range(_First, _Last);
auto _UFirst = _Get_unwrapped(_STD move(_First));
const auto _ULast = _Get_unwrapped(_STD move(_Last));
for (; _UFirst != _ULast; ++_UFirst, (void) ++_Result) {
CaseyCarter marked this conversation as resolved.
Show resolved Hide resolved
*_Result = _RANGES iter_move(_UFirst);
CaseyCarter marked this conversation as resolved.
Show resolved Hide resolved
}

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

template <input_range _Rng, weakly_incrementable _Out>
requires indirectly_movable<iterator_t<_Rng>, _Out> constexpr move_result<borrowed_iterator_t<_Rng>, _Out>
operator()(_Rng&& _Range, _Out _Result) const {
ahanamuk marked this conversation as resolved.
Show resolved Hide resolved
return (*this)(_RANGES begin(_Range), _RANGES end(_Range), _STD move(_Result));
}
};

inline constexpr _Move_fn move{_Not_quite_object::_Construct_tag{}};
} // namespace ranges
#endif // __cpp_lib_concepts


ahanamuk marked this conversation as resolved.
Show resolved Hide resolved
// FUNCTION TEMPLATE partition_copy
template <class _InIt, class _OutIt1, class _OutIt2, class _Pr>
_CONSTEXPR20 pair<_OutIt1, _OutIt2> partition_copy(
Expand Down Expand Up @@ -5173,6 +5210,8 @@ _NODISCARD constexpr const _Ty& clamp(const _Ty& _Val, const _Ty& _Min_val, cons
}
#endif // _HAS_CXX17


ahanamuk marked this conversation as resolved.
Show resolved Hide resolved

ahanamuk marked this conversation as resolved.
Show resolved Hide resolved
_STD_END
#pragma pop_macro("new")
_STL_RESTORE_CLANG_WARNINGS
Expand Down
1 change: 1 addition & 0 deletions tests/std/test.lst
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ tests\P0896R4_ranges_alg_find_if_not
tests\P0896R4_ranges_alg_for_each
tests\P0896R4_ranges_alg_for_each_n
tests\P0896R4_ranges_alg_mismatch
tests\P0896R4_ranges_alg_move
tests\P0896R4_ranges_alg_none_of
tests\P0896R4_ranges_iterator_machinery
tests\P0896R4_ranges_range_machinery
Expand Down
4 changes: 4 additions & 0 deletions tests/std/tests/P0896R4_ranges_alg_move/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
78 changes: 78 additions & 0 deletions tests/std/tests/P0896R4_ranges_alg_move/test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#include <algorithm>
ahanamuk marked this conversation as resolved.
Show resolved Hide resolved
#include <cassert>
#include <concepts>
#include <ranges>
#include <utility>
#include <range_algorithm_support.hpp>

struct int_wrapper {
int val = 10;
constexpr int_wrapper() = default;
constexpr int_wrapper(int x) : val{x} {}
constexpr int_wrapper(int_wrapper&& that) : val{std::exchange(that.val, -1)} {}
constexpr int_wrapper& operator=(int_wrapper&& that) {
val = std::exchange(that.val, -1);
return *this;
}
};

constexpr void smoke_test() {
using ranges::move, ranges::move_result, ranges::iterator_t;
using std::same_as;

// Validate that move_result aliases in_out_result
STATIC_ASSERT(same_as<move_result<int, double>, ranges::in_out_result<int, double>>);

// Validate dangling story
STATIC_ASSERT(same_as<decltype(move(borrowed<false>{}, static_cast<int*>(nullptr))), move_result<ranges::dangling, int*>>);
CaseyCarter marked this conversation as resolved.
Show resolved Hide resolved
STATIC_ASSERT(same_as<decltype(move(borrowed<true>{}, static_cast<int*>(nullptr))), move_result<int*, int*>>);

int const input[] = {13, 53, 12435};
{
int output[] = {-1, -1, -1};
CaseyCarter marked this conversation as resolved.
Show resolved Hide resolved
auto result = move(move_only_range{input}, move_only_range{output}.begin());
CaseyCarter marked this conversation as resolved.
Show resolved Hide resolved
STATIC_ASSERT(same_as<decltype(result),
move_result<iterator_t<move_only_range<int const>>, iterator_t<move_only_range<int>>>>);
assert(result.in == move_only_range{input}.end());
assert(result.out == move_only_range{output}.end());
assert(ranges::equal(output, input));
}
{
int output[] = {-1, -1, -1};
CaseyCarter marked this conversation as resolved.
Show resolved Hide resolved
move_only_range wrapped_input{input};
auto result = move(wrapped_input.begin(), wrapped_input.end(), move_only_range{output}.begin());
STATIC_ASSERT(same_as<decltype(result), move_result<iterator_t<move_only_range<int const>>, iterator_t<move_only_range<int>>>>);
assert(result.in == wrapped_input.end());
assert(result.out == move_only_range{output}.end());
assert(ranges::equal(output, input));
}
{
int_wrapper input1[3] = {13, 55, 1234};
int expected_output[3] = {13, 55, 1234};
CaseyCarter marked this conversation as resolved.
Show resolved Hide resolved
int_wrapper actual_output[3] = {-1, -1, -1};
move_only_range wrapped_input{input1};
auto result = move(wrapped_input.begin(), wrapped_input.end(), move_only_range{actual_output}.begin());
assert(result.in == wrapped_input.end());
assert(result.out == move_only_range{actual_output}.end());
for (int i = 0; i < 3; i++) {
StephanTLavavej marked this conversation as resolved.
Show resolved Hide resolved
assert(input1[i].val == -1);
CaseyCarter marked this conversation as resolved.
Show resolved Hide resolved
assert(actual_output[i].val == expected_output[i]);
}
}

}

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

struct instantiator {
template <class In, class Out>
static void call(In&& in = {}, Out out = {}) {
(void) ranges::move(in, std::move(out));
(void) ranges::move(ranges::begin(in), ranges::end(in), std::move(out)); // what is this
StephanTLavavej marked this conversation as resolved.
Show resolved Hide resolved
}
};

template void test_in_out<instantiator>();
CaseyCarter marked this conversation as resolved.
Show resolved Hide resolved