-
Notifications
You must be signed in to change notification settings - Fork 449
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Defer Invokable test in ranges::action, fix up many action concept te…
…sts, fixes #632
- Loading branch information
1 parent
714f590
commit ea9e8e0
Showing
10 changed files
with
163 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Range v3 library | ||
// | ||
// Copyright Eric Niebler 2014 | ||
// | ||
// Use, modification and distribution is subject to the | ||
// Boost Software License, Version 1.0. (See accompanying | ||
// file LICENSE_1_0.txt or copy at | ||
// http://www.boost.org/LICENSE_1_0.txt) | ||
|
||
#include <vector> | ||
#include <range/v3/core.hpp> | ||
#include <range/v3/action/join.hpp> | ||
#include <range/v3/algorithm/move.hpp> | ||
#include <range/v3/algorithm/equal.hpp> | ||
#include <range/v3/view/transform.hpp> | ||
#include "../simple_test.hpp" | ||
#include "../test_utils.hpp" | ||
|
||
template<class> struct undef; | ||
|
||
int main() | ||
{ | ||
using namespace ranges; | ||
|
||
std::vector<std::string> v {"hello"," ","world"}; | ||
auto s = v | move | action::join; | ||
static_assert(std::is_same<decltype(s), std::string>::value, ""); | ||
CHECK(s == "hello world"); | ||
|
||
auto s2 = v | view::transform(view::all) | action::join; | ||
static_assert(std::is_same<decltype(s2), std::vector<char>>::value, ""); | ||
CHECK(equal(s, s2)); | ||
|
||
return ::test_result(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// Range v3 library | ||
// | ||
// Copyright Eric Niebler 2014 | ||
// | ||
// Use, modification and distribution is subject to the | ||
// Boost Software License, Version 1.0. (See accompanying | ||
// file LICENSE_1_0.txt or copy at | ||
// http://www.boost.org/LICENSE_1_0.txt) | ||
|
||
#include <array> | ||
#include <random> | ||
#include <vector> | ||
#include <range/v3/core.hpp> | ||
#include <range/v3/view/iota.hpp> | ||
#include <range/v3/view/stride.hpp> | ||
#include <range/v3/view/take.hpp> | ||
#include <range/v3/algorithm/shuffle.hpp> | ||
#include <range/v3/algorithm/copy.hpp> | ||
#include <range/v3/algorithm/move.hpp> | ||
#include <range/v3/algorithm/is_sorted.hpp> | ||
#include <range/v3/algorithm/equal.hpp> | ||
#include <range/v3/action/shuffle.hpp> | ||
#include <range/v3/action/stable_sort.hpp> | ||
#include "../simple_test.hpp" | ||
#include "../test_utils.hpp" | ||
|
||
void test_bug632() | ||
{ | ||
const std::vector<double> scores = { 3.0, 1.0, 2.0 }; | ||
std::vector<int> indices = { 0, 1, 2 }; | ||
|
||
indices |= ranges::action::stable_sort( | ||
ranges::less{}, | ||
[&] (const int &x) { return scores[ (std::size_t)x ]; } | ||
); | ||
|
||
::check_equal( indices, {1, 2, 0} ); | ||
} | ||
|
||
int main() | ||
{ | ||
using namespace ranges; | ||
std::mt19937 gen; | ||
|
||
std::vector<int> v = view::ints(0,100); | ||
v |= action::shuffle(gen); | ||
CHECK(!is_sorted(v)); | ||
|
||
auto v2 = v | copy | action::stable_sort; | ||
CHECK(size(v2) == size(v)); | ||
CHECK(is_sorted(v2)); | ||
CHECK(!is_sorted(v)); | ||
::models<concepts::Same>(v, v2); | ||
|
||
v |= action::stable_sort; | ||
CHECK(is_sorted(v)); | ||
|
||
v |= action::shuffle(gen); | ||
CHECK(!is_sorted(v)); | ||
|
||
v = v | move | action::stable_sort(std::less<int>()); | ||
CHECK(is_sorted(v)); | ||
CHECK(equal(v, v2)); | ||
|
||
// Container algorithms can also be called directly | ||
// in which case they take and return by reference | ||
shuffle(v, gen); | ||
CHECK(!is_sorted(v)); | ||
auto & v3 = action::stable_sort(v); | ||
CHECK(is_sorted(v)); | ||
CHECK(&v3 == &v); | ||
|
||
auto ref=std::ref(v); | ||
ref |= action::stable_sort; | ||
|
||
// Can pipe a view to a "container" algorithm. | ||
action::stable_sort(v, std::greater<int>()); | ||
v | view::stride(2) | action::stable_sort; | ||
check_equal(view::take(v, 10), {1,98,3,96,5,94,7,92,9,90}); | ||
|
||
test_bug632(); | ||
|
||
return ::test_result(); | ||
} |