From e537e0a17ac05d76689101594260e46cfd087349 Mon Sep 17 00:00:00 2001 From: Morwenn Date: Tue, 16 Jan 2024 21:55:04 +0100 Subject: [PATCH] Remove testing-tools/span.h --- tests/adapters/hybrid_adapter_sfinae.cpp | 16 ++++---- tests/adapters/indirect_adapter.cpp | 10 ++--- tests/metrics/comparisons.cpp | 13 +++--- tests/metrics/moves.cpp | 8 ++-- tests/metrics/projections.cpp | 9 ++--- tests/sorters/every_sorter_span.cpp | 6 +-- tests/testing-tools/span.h | 51 ------------------------ 7 files changed, 30 insertions(+), 83 deletions(-) delete mode 100644 tests/testing-tools/span.h diff --git a/tests/adapters/hybrid_adapter_sfinae.cpp b/tests/adapters/hybrid_adapter_sfinae.cpp index 3004ac6b..150e1003 100644 --- a/tests/adapters/hybrid_adapter_sfinae.cpp +++ b/tests/adapters/hybrid_adapter_sfinae.cpp @@ -1,15 +1,15 @@ /* - * Copyright (c) 2015-2022 Morwenn + * Copyright (c) 2015-2024 Morwenn * SPDX-License-Identifier: MIT */ #include #include +#include #include #include #include #include #include -#include namespace { @@ -116,13 +116,13 @@ TEST_CASE( "sfinae forwarding in hybrid_adapter", SECTION( "with span" ) { - sorter_type res1 = sorter(make_span(vec1)); + sorter_type res1 = sorter(std::span(vec1)); CHECK( res1 == sorter_type::integer ); - sorter_type res2 = sorter(make_span(vec2)); + sorter_type res2 = sorter(std::span(vec2)); CHECK( res2 == sorter_type::floating_point ); - sorter_type res3 = sorter(make_span(vec3)); + sorter_type res3 = sorter(std::span(vec3)); CHECK( res3 == sorter_type::generic ); } } @@ -173,13 +173,13 @@ TEST_CASE( "sfinae forwarding in nested hybrid_adapter", SECTION( "with span" ) { - sorter_type res1 = sorter(make_span(vec1)); + sorter_type res1 = sorter(std::span(vec1)); CHECK( res1 == sorter_type::integer ); - sorter_type res2 = sorter(make_span(vec2)); + sorter_type res2 = sorter(std::span(vec2)); CHECK( res2 == sorter_type::floating_point ); - sorter_type res3 = sorter(make_span(vec3)); + sorter_type res3 = sorter(std::span(vec3)); CHECK( res3 == sorter_type::generic ); } } diff --git a/tests/adapters/indirect_adapter.cpp b/tests/adapters/indirect_adapter.cpp index 671ed92b..45604aab 100644 --- a/tests/adapters/indirect_adapter.cpp +++ b/tests/adapters/indirect_adapter.cpp @@ -1,10 +1,11 @@ /* - * Copyright (c) 2016-2022 Morwenn + * Copyright (c) 2016-2024 Morwenn * SPDX-License-Identifier: MIT */ #include #include #include +#include #include #include #include @@ -12,7 +13,6 @@ #include #include #include -#include TEST_CASE( "basic tests with indirect_adapter", "[indirect_adapter]" ) @@ -74,20 +74,20 @@ TEST_CASE( "indirect_adapter with temporary span", SECTION( "with comparison" ) { - sorter(make_span(collection), std::greater<>{}); + sorter(std::span(collection), std::greater<>{}); CHECK( std::is_sorted(collection.begin(), collection.end(), std::greater<>{}) ); } SECTION( "with projection" ) { - sorter(make_span(collection), std::negate<>{}); + sorter(std::span(collection), std::negate<>{}); CHECK( helpers::is_sorted(collection.begin(), collection.end(), std::less<>{}, std::negate<>{}) ); } SECTION( "with comparison and projection" ) { - sorter(make_span(collection), std::greater<>{}, std::negate<>{}); + sorter(std::span(collection), std::greater<>{}, std::negate<>{}); CHECK( std::is_sorted(collection.begin(), collection.end()) ); } } diff --git a/tests/metrics/comparisons.cpp b/tests/metrics/comparisons.cpp index d1208c75..79207920 100644 --- a/tests/metrics/comparisons.cpp +++ b/tests/metrics/comparisons.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Morwenn + * Copyright (c) 2023-2024 Morwenn * SPDX-License-Identifier: MIT */ #include @@ -7,13 +7,12 @@ #include #include #include -#include +#include #include #include #include #include #include -#include #include using wrapper = generic_wrapper; @@ -52,8 +51,8 @@ TEST_CASE( "basic metrics::comparisons tests", } } -TEST_CASE( "metrics::comparisons with span", - "[metrics][span][selection_sorter]" ) +TEST_CASE( "metrics::comparisons with temporary range", + "[metrics][subrange][selection_sorter]" ) { cppsort::metrics::comparisons< cppsort::selection_sorter @@ -65,7 +64,7 @@ TEST_CASE( "metrics::comparisons with span", auto distribution = dist::shuffled{}; distribution(std::back_inserter(collection), 65, 0); - auto res = sorter(make_span(collection)); + auto res = sorter(std::ranges::subrange(collection)); CHECK( res == 2080 ); CHECK( std::is_sorted(collection.begin(), collection.end()) ); } @@ -76,7 +75,7 @@ TEST_CASE( "metrics::comparisons with span", auto distribution = dist::shuffled{}; distribution(std::back_inserter(collection), 80, 0); - auto res = sorter(make_span(collection), &wrapper::value); + auto res = sorter(std::ranges::subrange(collection), &wrapper::value); CHECK( res == 3160 ); CHECK( helpers::is_sorted(collection.begin(), collection.end(), std::less<>{}, &wrapper::value) ); diff --git a/tests/metrics/moves.cpp b/tests/metrics/moves.cpp index 44971266..89c6af1a 100644 --- a/tests/metrics/moves.cpp +++ b/tests/metrics/moves.cpp @@ -1,18 +1,18 @@ /* - * Copyright (c) 2023 Morwenn + * Copyright (c) 2023-2024 Morwenn * SPDX-License-Identifier: MIT */ #include #include #include #include +#include #include #include #include #include #include #include -#include #include using wrapper = generic_wrapper; @@ -57,7 +57,7 @@ TEST_CASE( "metrics::moves with span", auto distribution = dist::descending_plateau{}; distribution(std::back_inserter(collection), 65); - auto res = sorter(make_span(collection)); + auto res = sorter(std::span(collection)); CHECK( res == 463 ); CHECK( std::is_sorted(collection.begin(), collection.end()) ); } @@ -68,7 +68,7 @@ TEST_CASE( "metrics::moves with span", auto distribution = dist::descending_plateau{}; distribution(std::back_inserter(collection), 80); - auto res = sorter(make_span(collection), &wrapper::value); + auto res = sorter(std::span(collection), &wrapper::value); CHECK( res == 573 ); CHECK( helpers::is_sorted(collection.begin(), collection.end(), std::less<>{}, &wrapper::value) ); diff --git a/tests/metrics/projections.cpp b/tests/metrics/projections.cpp index 67284601..2b279294 100644 --- a/tests/metrics/projections.cpp +++ b/tests/metrics/projections.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Morwenn + * Copyright (c) 2023-2024 Morwenn * SPDX-License-Identifier: MIT */ #include @@ -7,14 +7,13 @@ #include #include #include -#include +#include #include #include #include #include #include #include -#include #include using wrapper = generic_wrapper; @@ -66,7 +65,7 @@ TEST_CASE( "metrics::projections with span", auto distribution = dist::shuffled{}; distribution(std::back_inserter(collection), 65, 0); - auto res = sorter(make_span(collection)); + auto res = sorter(std::ranges::subrange(collection)); CHECK( res == 4160 ); CHECK( std::is_sorted(collection.begin(), collection.end()) ); } @@ -77,7 +76,7 @@ TEST_CASE( "metrics::projections with span", auto distribution = dist::shuffled{}; distribution(std::back_inserter(collection), 80, 0); - auto res = sorter(make_span(collection), &wrapper::value); + auto res = sorter(std::ranges::subrange(collection), &wrapper::value); CHECK( res == 6320 ); CHECK( helpers::is_sorted(collection.begin(), collection.end(), std::less<>{}, &wrapper::value) ); diff --git a/tests/sorters/every_sorter_span.cpp b/tests/sorters/every_sorter_span.cpp index ad23b810..042983aa 100644 --- a/tests/sorters/every_sorter_span.cpp +++ b/tests/sorters/every_sorter_span.cpp @@ -1,9 +1,10 @@ /* - * Copyright (c) 2016-2023 Morwenn + * Copyright (c) 2016-2024 Morwenn * SPDX-License-Identifier: MIT */ #include #include +#include #include #include #include @@ -11,7 +12,6 @@ #include #include #include -#include TEMPLATE_TEST_CASE( "test every sorter with temporary span", "[sorters][span]", old_default_sorter, @@ -58,6 +58,6 @@ TEMPLATE_TEST_CASE( "test every sorter with temporary span", "[sorters][span]", distribution(std::back_inserter(collection), 491, -125); TestType sorter; - sorter(make_span(collection)); + sorter(std::span(collection)); CHECK( std::is_sorted(collection.begin(), collection.end()) ); } diff --git a/tests/testing-tools/span.h b/tests/testing-tools/span.h deleted file mode 100644 index d39e2b70..00000000 --- a/tests/testing-tools/span.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (c) 2016-2021 Morwenn - * SPDX-License-Identifier: MIT - */ -#ifndef CPPSORT_TESTSUITE_SPAN_H_ -#define CPPSORT_TESTSUITE_SPAN_H_ - -//////////////////////////////////////////////////////////// -// Headers -//////////////////////////////////////////////////////////// -#include - -//////////////////////////////////////////////////////////// -// Very basic span type -// -// While the original goal of sorters is to sort some kinds -// of collections that are typically lvalues, there are more -// and more span-like types (GSL, Ranges v3...) and these -// might be passed to sorters as temporary values. -// -// Therefore sorters need to handle temporary span-like -// classes like the one below too. -// - -template -class span -{ - public: - - template - explicit span(Range& range): - _begin(std::begin(range)), - _end(std::end(range)) - {} - - auto begin() const { return _begin; } - auto end() const { return _end; } - - private: - - Iterator _begin, _end; -}; - -template -auto make_span(Range& range) - -> span -{ - return span(range); -} - -#endif // CPPSORT_TESTSUITE_SPAN_H_