1 //===----------------------------------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++03, c++11, c++14, c++17
13 // template<class charT, class traits>
14 // constexpr auto operator<=>(basic_string_view<charT, traits> lhs, basic_string_view<charT, traits> rhs);
18 // Mandates: R denotes a comparison category type ([cmp.categories]).
20 #include <string_view>
22 #include "test_macros.h"
24 template <class CharT
, class Ordering
>
26 typedef CharT char_type
;
28 typedef std::streamoff off_type
;
29 typedef std::streampos pos_type
;
30 typedef std::mbstate_t state_type
;
31 using comparison_category
= Ordering
;
33 static constexpr void assign(char_type
&, const char_type
&) noexcept
;
34 static constexpr bool eq(char_type
&, const char_type
&) noexcept
;
35 static constexpr bool lt(char_type
&, const char_type
&) noexcept
;
37 static constexpr int compare(const char_type
*, const char_type
*, std::size_t) { return 0; }
38 static constexpr std::size_t length(const char_type
*);
39 static constexpr const char_type
* find(const char_type
*, std::size_t, const char_type
&);
40 static constexpr char_type
* move(char_type
*, const char_type
*, std::size_t);
41 static constexpr char_type
* copy(char_type
*, const char_type
*, std::size_t);
42 static constexpr char_type
* assign(char_type
*, std::size_t, char_type
);
44 static constexpr int_type
not_eof(int_type
) noexcept
;
46 static constexpr char_type
to_char_type(int_type
) noexcept
;
48 static constexpr int_type
to_int_type(char_type
) noexcept
;
50 static constexpr bool eq_int_type(int_type
, int_type
) noexcept
;
52 static constexpr int_type
eof() noexcept
;
55 template <class CharT
, class Ordering
, bool Valid
>
57 using type
= std::basic_string_view
<CharT
, traits
<CharT
, Ordering
>>;
61 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
62 // These diagnostics are issued for
63 // - Every invalid ordering
65 // expected-error-re@string_view:* 15 {{static assertion failed{{.*}}return type is not a comparison category type}}
67 // This diagnostic is not issued for Ordering == void.
68 // expected-error@string_view:* 10 {{no matching conversion for static_cast from}}
70 // One less test run when wchar_t is unavailable.
71 // expected-error-re@string_view:* 12 {{static assertion failed{{.*}}return type is not a comparison category type}}
72 // expected-error@string_view:* 8 {{no matching conversion for static_cast from}}
77 template <class CharT
>
78 void test_all_orders() {
79 test
<CharT
, std::strong_ordering
, true>();
80 test
<CharT
, std::weak_ordering
, true>();
81 test
<CharT
, std::partial_ordering
, true>();
83 test
<CharT
, void, false>();
84 test
<CharT
, int, false>();
85 test
<CharT
, float, false>();
88 void test_all_types() {
89 test_all_orders
<char>();
90 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
91 test_all_orders
<wchar_t>();
93 test_all_orders
<char8_t
>();
94 test_all_orders
<char16_t
>();
95 test_all_orders
<char32_t
>();