28 concept static_character = std::same_as<T, char> || std::same_as<T, wchar_t> ||
29 std::same_as<T, char8_t> || std::same_as<T, char16_t> || std::same_as<T, char32_t>;
31 template<
class CharT, std::
size_t N>
32 struct static_string_literal {
33 using char_type = CharT;
34 static constexpr std::size_t size = N;
36 consteval static_string_literal(CharT
const (&text)[N])
noexcept {
37 for (std::size_t i = 0; i != N; ++i) value[i] = text[i];
44template <
typename T, T...xs>
46 static constexpr const T value[
sizeof...(xs)+1] = {xs..., T() };
71 typename Traits = std::char_traits<CharT>
74 std::basic_string_view<CharT,Traits> view{reify<CharT>::value, 0};
86 using traits_type = Traits;
87 using value_type = CharT;
88 using pointer = CharT *;
89 using const_pointer = CharT
const *;
90 using reference = CharT &;
91 using const_reference = CharT
const &;
92 using const_iterator = CharT
const *;
93 using iterator = const_iterator;
94 using const_reverse_iterator = std::reverse_iterator<const_iterator>;
95 using reverse_iterator = const_reverse_iterator;
96 using size_type = std::size_t;
97 using difference_type = std::ptrdiff_t;
103 template <CharT...xs>
105 : view(reify<CharT,xs...>::value,
sizeof...(xs)) {}
138 operator CharT const * () const noexcept {
144 operator std::basic_string_view<CharT,Traits>() const noexcept {
150 operator std::basic_string<CharT,Traits>()
const {
151 return std::basic_string<CharT,Traits>(view);
160 CharT
const &
operator [](size_type i)
const noexcept {
return view[i]; }
164 CharT
const &
at(size_type i)
const {
return view.at(i); }
168 const_reference
front() const noexcept {
return view.front(); }
173 const_reference
back() const noexcept {
return view.back(); }
177 const_pointer
data() const noexcept {
return view.data(); }
185 size_type
size() const noexcept {
return view.size(); }
189 size_type
length() const noexcept {
return view.length(); }
193 size_type
max_size() const noexcept {
return view.max_size(); }
197 bool empty() const noexcept {
return view.empty(); }
201 explicit constexpr operator bool () const noexcept {
return !view.empty(); }
211 if constexpr (std::is_same_v<Traits,std::char_traits<CharT>> && detail::static_character<CharT>) {
212 return self.view.data() == that.view.data();
214 return (self.view.data() == that.view.data()) || (self.view == that.view);
222 if constexpr (std::is_same_v<Traits,std::char_traits<CharT>> && detail::static_character<CharT>) {
223 return self.view.data() != that.view.data();
225 return (self.view.data() != that.view.data()) && (self.view != that.view);
247 auto begin() const noexcept {
return view.data(); }
251 auto end() const noexcept {
return view.data() + view.size(); }
263 auto rbegin() const noexcept {
return const_reverse_iterator(
end()); }
267 auto rend() const noexcept {
return const_reverse_iterator(
begin()); }
286 static constexpr size_type npos = std::basic_string_view<CharT,Traits>::npos;
290template <
typename CharT, CharT...xs>
291basic_static_string(std::integer_sequence<CharT,xs...>) -> basic_static_string<CharT,std::char_traits<CharT>>;
294using static_string = basic_static_string<char>;
295using static_wstring = basic_static_string<wchar_t>;
296using static_u8string = basic_static_string<char8_t>;
297using static_u16string = basic_static_string<char16_t>;
298using static_u32string = basic_static_string<char32_t>;
307 char const * p = reify<char>::value;
310 using traits_type = std::char_traits<char>;
311 using value_type = char;
312 using pointer =
char *;
313 using const_pointer =
char const *;
314 using reference =
char &;
315 using const_reference =
char const &;
316 using const_iterator =
char const *;
317 using iterator = const_iterator;
318 using const_reverse_iterator = std::reverse_iterator<const_iterator>;
319 using reverse_iterator = const_reverse_iterator;
320 using size_type = std::size_t;
321 using difference_type = std::ptrdiff_t;
361 operator const
char * () const noexcept {
return p; }
365 operator static_string () const noexcept {
return static_string(std::string_view(p)); }
369 const char *
data() const noexcept {
return p; }
390 auto begin() const noexcept {
return p; }
394 auto end() const noexcept {
return p + std::char_traits<char>::length(p); }
399 auto cbegin() const noexcept {
return p; }
404 auto cend() const noexcept {
return p + std::char_traits<char>::length(p); }
409 auto rbegin() const noexcept {
return std::reverse_iterator<const char *>(
end()); }
414 auto rend() const noexcept {
return std::reverse_iterator<const char *>(
begin()); }
419 auto crbegin() const noexcept {
return std::reverse_iterator<const char *>(
end()); }
424 auto crend() const noexcept {
return std::reverse_iterator<const char *>(
begin()); }
440template <detail::static_
string_literal Text>
441consteval auto operator""_ss() noexcept {
442 using CharT =
typename decltype(Text)::char_type;
443 return []<std::size_t... I>(std::index_sequence<I...>) {
445 }(std::make_index_sequence<Text.size - 1>{});
451template <detail::static_
string_literal Text>
452 requires std::same_as<
typename decltype(Text)::char_type,
char>
459export namespace std {
461 template <
typename CharT,
typename Traits>
462 struct hash<::native::basic_static_string<CharT,Traits>> {
464 size_t operator()(::native::basic_static_string<CharT,Traits>
const & s)
const noexcept {
465 return reinterpret_cast<size_t>(s.data());
469 struct hash<::native::static_c_string> {
471 size_t operator()(::native::static_c_string s)
const noexcept {
472 return reinterpret_cast<size_t>(s.data());
478 template<
class CharT,
class Traits >
479 inline constexpr bool enable_borrowed_range<::native::basic_static_string<CharT, Traits>> =
true;
481 template<
class CharT,
class Traits >
482 inline constexpr bool enable_view<::native::basic_static_string<CharT, Traits>> =
true;
485 inline constexpr bool enable_borrowed_range<::native::static_c_string> =
true;
488 inline constexpr bool enable_view<::native::static_c_string> =
true;
Compiler attributes for host code, with shader-safe shared modifiers.
A view of one complete interned string, with its length retained. The five standard character widths ...
friend class static_c_string
constexpr friend void swap(basic_static_string &x, basic_static_string &y) noexcept
Exchange views without moving characters.
constexpr auto cbegin() const noexcept
Return the first const character iterator.
constexpr auto rend() const noexcept
Return the reverse end iterator.
constexpr auto cend() const noexcept
Return the const end iterator; C-string form scans to its NUL.
constexpr auto rbegin() const noexcept
Return the first reverse iterator; C-string form first finds its end.
friend constexpr bool operator==(basic_static_string self, basic_static_string that) noexcept
constexpr auto crbegin() const noexcept
Return the first const reverse iterator.
constexpr const_reference back() const noexcept
constexpr size_type max_size() const noexcept
Return the underlying string_view capacity bound, not the current length.
constexpr bool empty() const noexcept
Return whether the stored length is zero.
consteval basic_static_string(std::integer_sequence< CharT, xs... >) noexcept
Intern a compile-time character sequence; append one terminator outside its length.
friend constexpr std::basic_ostream< char, std::char_traits< char > > & operator<<(std::basic_ostream< char, std::char_traits< char > > &os, basic_static_string< char, std::char_traits< char > > v)
constexpr const_pointer data() const noexcept
Borrow the canonical storage; the terminator is at data()[size()].
constexpr const_reference front() const noexcept
Returns the first character. Requires !empty().
constexpr CharT const & at(size_type i) const
access the specified character with bounds checking
constexpr CharT const & operator[](size_type i) const noexcept
Access character i. Requires i < size().
constexpr auto end() const noexcept
Return the one-past-last character iterator; C-string form scans to its NUL.
constexpr auto crend() const noexcept
Return the const reverse end iterator.
constexpr auto begin() const noexcept
Return the first character iterator.
constexpr size_type size() const noexcept
Return the stored number of characters, excluding the final terminator.
constexpr size_type length() const noexcept
Synonym for size().
constexpr basic_static_string(std::basic_string_view< CharT, Traits > value) noexcept
constexpr basic_static_string() noexcept=default
Select the canonical empty interned string.
friend constexpr bool operator!=(basic_static_string self, basic_static_string that) noexcept
A pointer-sized view of a complete interned char string. Length is recovered from the first NUL....
constexpr auto rend() const noexcept
constexpr friend bool operator!=(static_c_string x, static_c_string y) noexcept
Return whether the interned addresses differ.
friend void swap(static_c_string &x, static_c_string &y) noexcept
Exchange the interned pointers without touching characters.
constexpr auto cbegin() const noexcept
constexpr auto rbegin() const noexcept
constexpr auto begin() const noexcept
constexpr auto crbegin() const noexcept
constexpr static_c_string & operator=(static_c_string const &) noexcept=default
Replace this view with the source view without allocation; the source is unchanged.
constexpr friend bool operator==(static_c_string x, static_c_string y) noexcept
Return whether both views refer to the same interned address.
constexpr static_c_string() noexcept=default
Select the canonical empty C string.
constexpr auto cend() const noexcept
constexpr auto crend() const noexcept
constexpr const char * data() const noexcept
Return the borrowed interned pointer.
constexpr auto end() const noexcept
Return the one-past-last character iterator; C-string form scans to its NUL.
#define native_reinitializes
[[clang::reinitializes]]
#define native_artificial
[[artificial]].
#define native_inline
inline [[always_inline]]
#define native_nodiscard
C++17 [[nodiscard]].
#define native_pure
[[pure]]
Architecture-tagged vectors, register packs and supporting value types. Native arithmetic follows its...
Standard-library adaptations documented here for SIMD value types.
Store a compile-time sequence followed by one value-initialized terminator.