Skip to content

Commit 0a68255

Browse files
committed
Unconditional support for std::[w]string_view (#66)
1 parent dac4602 commit 0a68255

File tree

3 files changed

+3
-19
lines changed

3 files changed

+3
-19
lines changed

docs/Changelog.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@ While **cpp-sort** theoretically requires a fully C++17-compliant compiler, a fe
1212
When compiled with C++17, **cpp-sort** might gain a few additional features depending on the level of C++17 support provided by the compiler. The availability of most of the features depends on the presence of corresponding [feature-testing macros][feature-test-macros]. The support for feature-testing macros being optional in C++17, it is possible that some of the features listed below aren't available even though the compiler is implements them. If it is the case and it is a problem for you, don't hesitate to open an issue so that we can explicitly support the given compiler.
1313

1414
**New features:**
15-
* `string_spread_sort` now accepts [`std::string_view`][std-string-view] and sometimes `std::wstring_view`.
16-
17-
This feature is made available through the check `__cplusplus > 201402L && __has_include(<string_view>)`.
18-
1915
* Sorter adapters have been updated to take advantage of deduction guides:
2016

2117
```cpp
@@ -100,6 +96,5 @@ When compiled with C++20, **cpp-sort** might gain a few additional features depe
10096
[std-mem-fn]: https://en.cppreference.com/w/cpp/utility/functional/mem_fn
10197
[std-ranges-greater]: https://en.cppreference.com/w/cpp/utility/functional/ranges/greater
10298
[std-ranges-less]: https://en.cppreference.com/w/cpp/utility/functional/ranges/less
103-
[std-string-view]: https://en.cppreference.com/w/cpp/string/basic_string_view
10499
[std-swap]: https://en.cppreference.com/w/cpp/algorithm/swap
105100
[utility-iter-move]: Miscellaneous-utilities.md#iter_move-and-iter_swap

docs/Sorters.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ It comes into three main flavours (available individually if needed):
593593

594594
* `integer_spread_sorter` works with any type satisfying the trait `std::is_integral`.
595595
* `float_spread_sorter` works with any type satisfying the trait `std::numeric_limits::is_iec559` whose size is the same as `std::uint32_t` or `std::uin64_t`.
596-
* `string_spread_sorter` works with `std::string` and `std::wstring` (if `wchar_t` is 2 bytes). This sorter also supports reverse sorting with `std::greater<>` and `std::ranges::greater`. In C++17 it also works with `std::string_view` and `std::wstring_view` (if `wchar_t` is 2 bytes).
596+
* `string_spread_sorter` works with `std::string` and `std::string_view`, as well as `std::wstring` and `std::wstring_view` when `wchar_t` is 2 bytes. This sorter also supports reverse sorting with `std::greater<>` and `std::ranges::greater`.
597597

598598
These sorters accept projections as long as their simplest form can handle the result of the projection. The three of them are aggregated into one main sorter the following way:
599599

include/cpp-sort/sorters/spread_sorter/string_spread_sorter.h

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015-2021 Morwenn
2+
* Copyright (c) 2015-2025 Morwenn
33
* SPDX-License-Identifier: MIT
44
*/
55
#ifndef CPPSORT_SORTERS_SPREAD_SORTER_STRING_SPREAD_SORTER_H_
@@ -12,6 +12,7 @@
1212
#include <functional>
1313
#include <iterator>
1414
#include <string>
15+
#include <string_view>
1516
#include <type_traits>
1617
#include <utility>
1718
#include <cpp-sort/sorter_facade.h>
@@ -22,10 +23,6 @@
2223
#include "../../detail/spreadsort/string_sort.h"
2324
#include "../../detail/type_traits.h"
2425

25-
#if __cplusplus > 201402L && __has_include(<string_view>)
26-
# include <string_view>
27-
#endif
28-
2926
namespace cppsort
3027
{
3128
////////////////////////////////////////////////////////////
@@ -46,9 +43,7 @@ namespace cppsort
4643
Projection projection={}) const
4744
-> detail::enable_if_t<
4845
std::is_same<projected_t<RandomAccessIterator, Projection>, std::string>::value
49-
#if __cplusplus > 201402L && __has_include(<string_view>)
5046
|| std::is_same<projected_t<RandomAccessIterator, Projection>, std::string_view>::value
51-
#endif
5247
>
5348
{
5449
static_assert(
@@ -72,9 +67,7 @@ namespace cppsort
7267
Projection projection={}) const
7368
-> detail::enable_if_t<(
7469
std::is_same<projected_t<RandomAccessIterator, Projection>, std::wstring>::value
75-
#if __cplusplus > 201402L && __has_include(<string_view>)
7670
|| std::is_same<projected_t<RandomAccessIterator, Projection>, std::wstring_view>::value
77-
#endif
7871
) && (sizeof(wchar_t) == 2)
7972
>
8073
{
@@ -102,9 +95,7 @@ namespace cppsort
10295
std::greater<> compare, Projection projection={}) const
10396
-> detail::enable_if_t<
10497
std::is_same<projected_t<RandomAccessIterator, Projection>, std::string>::value
105-
#if __cplusplus > 201402L && __has_include(<string_view>)
10698
|| std::is_same<projected_t<RandomAccessIterator, Projection>, std::string_view>::value
107-
#endif
10899
>
109100
{
110101
static_assert(
@@ -129,9 +120,7 @@ namespace cppsort
129120
std::greater<> compare, Projection projection={}) const
130121
-> detail::enable_if_t<(
131122
std::is_same<projected_t<RandomAccessIterator, Projection>, std::wstring>::value
132-
#if __cplusplus > 201402L && __has_include(<string_view>)
133123
|| std::is_same<projected_t<RandomAccessIterator, Projection>, std::wstring_view>::value
134-
#endif
135124
) && (sizeof(wchar_t) == 2)
136125
>
137126
{

0 commit comments

Comments
 (0)