Skip to content

Commit ebb9736

Browse files
committed
Prevent use of spaceship operator if not available
1 parent 86fb84d commit ebb9736

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

examples/example.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using namespace std::literals;
88
using namespace beman::literals;
99

10+
#if __cpp_impl_three_way_comparison >= 201907L
1011
std::string_view to_string(std::strong_ordering order) {
1112
if (order == std::strong_ordering::equal) {
1213
return "equal";
@@ -21,6 +22,7 @@ std::string_view to_string(std::strong_ordering order) {
2122
return "internal error";
2223
}
2324
}
25+
#endif
2426

2527
int main() {
2628
std::string s = "hello world";
@@ -39,7 +41,9 @@ int main() {
3941
std::cout << ("hello"_csv != "goodbye"sv) << "\n";
4042
std::cout << ("hello"_csv != "goodbye"_csv) << "\n";
4143
std::cout << (z0 == z1) << "\n";
44+
#if __cpp_impl_three_way_comparison >= 201907L
4245
std::cout << to_string(z0 <=> z1) << "\n";
46+
#endif
4347
std::cout << z0[z0.size()] * 1 << "\n";
4448
std::cout << z0.c_str() << "\n";
4549
std::cout << "\"" << empty << "\"\n";
@@ -61,7 +65,9 @@ int main() {
6165
std::cout << (L"hello"_csv != L"goodbye"sv) << "\n";
6266
std::cout << (L"hello"_csv != L"goodbye"_csv) << "\n";
6367
std::cout << (wz0 == wz1) << "\n";
68+
#if __cpp_impl_three_way_comparison >= 201907L
6469
std::cout << to_string(wz0 <=> wz1) << "\n";
70+
#endif
6571
std::cout << wz0[wz0.size()] * 1 << "\n";
6672
std::wcout << std::format(L"{}\n", wz0.c_str());
6773
std::wcout << std::format(L"\"{}\"\n", wempty);

include/beman/cstring_view/cstring_view.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,13 @@ constexpr bool operator==(basic_cstring_view<charT, traits>
3131
std::type_identity_t<basic_cstring_view<charT, traits>> y) noexcept;
3232

3333
template <class charT, class traits>
34+
35+
#if __cpp_impl_three_way_comparison >= 201907L
3436
constexpr auto operator<=>(basic_cstring_view<charT, traits> x,
3537
std::type_identity_t<basic_cstring_view<charT, traits>> y) noexcept;
3638

39+
#endif
40+
3741
// [cstring.view.io], inserters and extractors
3842
template <class charT, class traits>
3943
std::basic_ostream<charT, traits>& operator<<(std::basic_ostream<charT, traits>& os,

0 commit comments

Comments
 (0)