一呼百應, "one call, a hundred responses"
Loading...
Searching...
No Matches
ein::basic_static_string< CharT, Traits > Class Template Reference

statically known interned strings these have O(1) comparison for equality More...

#include <static_string.hpp>

Public Types

using traits_type = Traits
 
using value_type = CharT
 
using pointer = CharT *
 
using const_pointer = CharT const *
 
using reference = CharT &
 
using const_reference = CharT const &
 
using const_iterator = CharT const *
 
using iterator = const_iterator
 
using const_reverse_iterator = std::reverse_iterator<const_iterator>
 
using reverse_iterator = const_reverse_iterator
 
using size_type = std::size_t
 
using difference_type = std::ptrdiff_t
 

Public Member Functions

constexpr basic_static_string (std::basic_string_view< CharT, Traits > view)
 
constructors
template<CharT... xs>
consteval basic_static_string (std::integer_sequence< CharT, xs... >)
 
constexpr basic_static_string () noexcept=default
 
constexpr basic_static_string (basic_static_string const &) noexcept=default
 
constexpr basic_static_string (basic_static_string const &&) noexcept=default
 
assignments
ein_reinitializes constexpr basic_static_stringoperator= (basic_static_string const &that) noexcept=default
 
ein_reinitializes constexpr basic_static_stringoperator= (basic_static_string &&that) noexcept=default
 
conversions
constexpr operator CharT const * () const noexcept
 
constexpr operator std::basic_string_view< CharT, Traits > () const noexcept
 
constexpr operator std::basic_string< CharT, Traits > () const noexcept
 
element access
constexpr CharT const & operator[] (size_type i) const noexcept
 access the specified character
 
constexpr CharT const & at (size_type i) const
 access the specified character with bounds checking
 
constexpr const_reference front () const noexcept
 Returns reference to the first character in the static_string.
 
constexpr const_reference back () const noexcept
 
constexpr const_pointer data () const noexcept
 
capacity
constexpr size_type size () const noexcept
 
constexpr size_type length () const noexcept
 
constexpr size_type max_size () const noexcept
 
constexpr bool empty () const noexcept
 
 operator bool () const noexcept
 
iterators
constexpr auto begin () const noexcept
 
constexpr auto end () const noexcept
 
constexpr auto cbegin () const noexcept
 
constexpr auto cend () const noexcept
 
constexpr auto rbegin () const noexcept
 
constexpr auto rend () const noexcept
 
constexpr auto crbegin () const noexcept
 
constexpr auto crend () const noexcept
 

Static Public Attributes

static constexpr size_type npos = std::basic_string_view<CharT,Traits>::npos
 

Private Attributes

std::basic_string_view< CharT, Traits > view
 

Friends

class static_c_string
 
constexpr friend void swap (basic_static_string &x, basic_static_string &y) noexcept
 
comparisons
Precondition
Traits::eq is assumed reflexive even if overloaded
constexpr bool operator== (basic_static_string self, basic_static_string that) noexcept
 
constexpr bool operator!= (basic_static_string self, basic_static_string that) noexcept
 
constexpr basic_ostream< CharT, Traits > & operator<< (basic_ostream< CharT, Traits > &os, basic_static_string< CharT, Traits > v)
 input/output
 

Detailed Description

template<typename CharT, typename Traits = std::char_traits<CharT>>
class ein::basic_static_string< CharT, Traits >

statically known interned strings these have O(1) comparison for equality

Invariant
all such strings point to the start of the static member inside operator""_ss for some string and their len is unmodified. this ensures that they have O(1) comparison, because reference and pointer equality coincide.

Definition at line 40 of file static_string.hpp.

Member Typedef Documentation

◆ const_iterator

template<typename CharT , typename Traits = std::char_traits<CharT>>
using ein::basic_static_string< CharT, Traits >::const_iterator = CharT const *

Definition at line 55 of file static_string.hpp.

◆ const_pointer

template<typename CharT , typename Traits = std::char_traits<CharT>>
using ein::basic_static_string< CharT, Traits >::const_pointer = CharT const *

Definition at line 52 of file static_string.hpp.

◆ const_reference

template<typename CharT , typename Traits = std::char_traits<CharT>>
using ein::basic_static_string< CharT, Traits >::const_reference = CharT const &

Definition at line 54 of file static_string.hpp.

◆ const_reverse_iterator

template<typename CharT , typename Traits = std::char_traits<CharT>>
using ein::basic_static_string< CharT, Traits >::const_reverse_iterator = std::reverse_iterator<const_iterator>

Definition at line 57 of file static_string.hpp.

◆ difference_type

template<typename CharT , typename Traits = std::char_traits<CharT>>
using ein::basic_static_string< CharT, Traits >::difference_type = std::ptrdiff_t

Definition at line 60 of file static_string.hpp.

◆ iterator

template<typename CharT , typename Traits = std::char_traits<CharT>>
using ein::basic_static_string< CharT, Traits >::iterator = const_iterator

Definition at line 56 of file static_string.hpp.

◆ pointer

template<typename CharT , typename Traits = std::char_traits<CharT>>
using ein::basic_static_string< CharT, Traits >::pointer = CharT *

Definition at line 51 of file static_string.hpp.

◆ reference

template<typename CharT , typename Traits = std::char_traits<CharT>>
using ein::basic_static_string< CharT, Traits >::reference = CharT &

Definition at line 53 of file static_string.hpp.

◆ reverse_iterator

template<typename CharT , typename Traits = std::char_traits<CharT>>
using ein::basic_static_string< CharT, Traits >::reverse_iterator = const_reverse_iterator

Definition at line 58 of file static_string.hpp.

◆ size_type

template<typename CharT , typename Traits = std::char_traits<CharT>>
using ein::basic_static_string< CharT, Traits >::size_type = std::size_t

Definition at line 59 of file static_string.hpp.

◆ traits_type

template<typename CharT , typename Traits = std::char_traits<CharT>>
using ein::basic_static_string< CharT, Traits >::traits_type = Traits

Definition at line 49 of file static_string.hpp.

◆ value_type

template<typename CharT , typename Traits = std::char_traits<CharT>>
using ein::basic_static_string< CharT, Traits >::value_type = CharT

Definition at line 50 of file static_string.hpp.

Constructor & Destructor Documentation

◆ basic_static_string() [1/5]

template<typename CharT , typename Traits = std::char_traits<CharT>>
ein::basic_static_string< CharT, Traits >::basic_static_string ( std::basic_string_view< CharT, Traits > view)
inlineconstexpr[[always_inline]]

Definition at line 45 of file static_string.hpp.

46 : view(view) {}
std::basic_string_view< CharT, Traits > view

◆ basic_static_string() [2/5]

template<typename CharT , typename Traits = std::char_traits<CharT>>
template<CharT... xs>
ein::basic_static_string< CharT, Traits >::basic_static_string ( std::integer_sequence< CharT, xs... > )
inlineexplicitconsteval

Definition at line 66 of file static_string.hpp.

67 : view(reify<CharT,xs...>::value,sizeof...(xs)) {}
static constexpr const T value[sizeof...(xs)+1]

◆ basic_static_string() [3/5]

template<typename CharT , typename Traits = std::char_traits<CharT>>
ein::basic_static_string< CharT, Traits >::basic_static_string ( )
constexprdefaultnoexcept[[always_inline]]

◆ basic_static_string() [4/5]

template<typename CharT , typename Traits = std::char_traits<CharT>>
ein::basic_static_string< CharT, Traits >::basic_static_string ( basic_static_string< CharT, Traits > const & )
constexprdefaultnoexcept[[always_inline]]

◆ basic_static_string() [5/5]

template<typename CharT , typename Traits = std::char_traits<CharT>>
ein::basic_static_string< CharT, Traits >::basic_static_string ( basic_static_string< CharT, Traits > const && )
constexprdefaultnoexcept[[always_inline]]

Member Function Documentation

◆ at()

template<typename CharT , typename Traits = std::char_traits<CharT>>
CharT const & ein::basic_static_string< CharT, Traits >::at ( size_type i) const
inlineconstexpr[[nodiscard]][[always_inline]][[pure]]

access the specified character with bounds checking

Definition at line 118 of file static_string.hpp.

118 {
119 if (i >= view.size()) throw std::out_of_range("basic_static_string::at");
120 return view.at(i);
121 }

References ein::basic_static_string< CharT, Traits >::view.

◆ back()

template<typename CharT , typename Traits = std::char_traits<CharT>>
const_reference ein::basic_static_string< CharT, Traits >::back ( ) const
inlineconstexprnoexcept[[nodiscard]][[always_inline]][[pure]]
Precondition
!empty()

Definition at line 135 of file static_string.hpp.

135{ return view.back(); }

References ein::basic_static_string< CharT, Traits >::view.

◆ begin()

template<typename CharT , typename Traits = std::char_traits<CharT>>
auto ein::basic_static_string< CharT, Traits >::begin ( ) const
inlineconstexprnoexcept[[nodiscard]][[always_inline]][[const]][[artificial]]

Definition at line 198 of file static_string.hpp.

198{ return view.begin(); }

References ein::basic_static_string< CharT, Traits >::view.

◆ cbegin()

template<typename CharT , typename Traits = std::char_traits<CharT>>
auto ein::basic_static_string< CharT, Traits >::cbegin ( ) const
inlineconstexprnoexcept[[nodiscard]][[always_inline]][[const]][[artificial]]

Definition at line 204 of file static_string.hpp.

204{ return view.cbegin(); }

References ein::basic_static_string< CharT, Traits >::view.

◆ cend()

template<typename CharT , typename Traits = std::char_traits<CharT>>
auto ein::basic_static_string< CharT, Traits >::cend ( ) const
inlineconstexprnoexcept[[nodiscard]][[always_inline]][[pure]]

Definition at line 207 of file static_string.hpp.

207{ return view.cend(); }

References ein::basic_static_string< CharT, Traits >::view.

◆ crbegin()

template<typename CharT , typename Traits = std::char_traits<CharT>>
auto ein::basic_static_string< CharT, Traits >::crbegin ( ) const
inlineconstexprnoexcept[[nodiscard]][[always_inline]][[pure]]

Definition at line 216 of file static_string.hpp.

216{ return view.crbegin(); }

References ein::basic_static_string< CharT, Traits >::view.

◆ crend()

template<typename CharT , typename Traits = std::char_traits<CharT>>
auto ein::basic_static_string< CharT, Traits >::crend ( ) const
inlineconstexprnoexcept[[nodiscard]][[always_inline]][[pure]]

Definition at line 219 of file static_string.hpp.

219{ return view.crend(); }

References ein::basic_static_string< CharT, Traits >::view.

◆ data()

template<typename CharT , typename Traits = std::char_traits<CharT>>
const_pointer ein::basic_static_string< CharT, Traits >::data ( ) const
inlineconstexprnoexcept[[nodiscard]][[always_inline]][[pure]]

Definition at line 138 of file static_string.hpp.

138{ return view.data(); }

References ein::basic_static_string< CharT, Traits >::view.

Referenced by ein::basic_static_string< char >::operator char const *().

Here is the caller graph for this function:

◆ empty()

template<typename CharT , typename Traits = std::char_traits<CharT>>
bool ein::basic_static_string< CharT, Traits >::empty ( ) const
inlineconstexprnoexcept[[nodiscard]][[always_inline]][[pure]]

Definition at line 154 of file static_string.hpp.

154{ return view.empty(); }

References ein::basic_static_string< CharT, Traits >::view.

◆ end()

template<typename CharT , typename Traits = std::char_traits<CharT>>
auto ein::basic_static_string< CharT, Traits >::end ( ) const
inlineconstexprnoexcept[[nodiscard]][[always_inline]][[pure]]

Definition at line 201 of file static_string.hpp.

201{ return view.end(); }

References ein::basic_static_string< CharT, Traits >::view.

◆ front()

template<typename CharT , typename Traits = std::char_traits<CharT>>
const_reference ein::basic_static_string< CharT, Traits >::front ( ) const
inlineconstexprnoexcept[[nodiscard]][[always_inline]][[pure]]

Returns reference to the first character in the static_string.

Note
while the corresponding string_view operation is undefined if empty(), this offers the slight weakening that it'll return CharT(0).
Precondition
!empty()

Definition at line 131 of file static_string.hpp.

131{ return view.front(); }

References ein::basic_static_string< CharT, Traits >::view.

◆ length()

template<typename CharT , typename Traits = std::char_traits<CharT>>
size_type ein::basic_static_string< CharT, Traits >::length ( ) const
inlineconstexprnoexcept[[nodiscard]][[always_inline]][[pure]]

Definition at line 148 of file static_string.hpp.

148{ return view.length(); }

References ein::basic_static_string< CharT, Traits >::view.

◆ max_size()

template<typename CharT , typename Traits = std::char_traits<CharT>>
size_type ein::basic_static_string< CharT, Traits >::max_size ( ) const
inlineconstexprnoexcept[[nodiscard]][[always_inline]][[pure]]

Definition at line 151 of file static_string.hpp.

151{ return view.max_size(); }

References ein::basic_static_string< CharT, Traits >::view.

◆ operator bool()

template<typename CharT , typename Traits = std::char_traits<CharT>>
ein::basic_static_string< CharT, Traits >::operator bool ( ) const
inlineexplicitnoexcept[[nodiscard]][[always_inline]][[pure]]

Definition at line 157 of file static_string.hpp.

157{ return view; }

References ein::basic_static_string< CharT, Traits >::view.

◆ operator CharT const *()

template<typename CharT , typename Traits = std::char_traits<CharT>>
ein::basic_static_string< CharT, Traits >::operator CharT const * ( ) const
inlineconstexprnoexcept[[nodiscard]][[always_inline]][[pure]]

Definition at line 94 of file static_string.hpp.

94 {
95 return view.data; // an extra invariant that its null terminated is maintained
96 }

◆ operator std::basic_string< CharT, Traits >()

template<typename CharT , typename Traits = std::char_traits<CharT>>
ein::basic_static_string< CharT, Traits >::operator std::basic_string< CharT, Traits > ( ) const
inlineconstexprnoexcept[[nodiscard]][[always_inline]][[pure]]

Definition at line 104 of file static_string.hpp.

104 {
105 return view;
106 }

◆ operator std::basic_string_view< CharT, Traits >()

template<typename CharT , typename Traits = std::char_traits<CharT>>
ein::basic_static_string< CharT, Traits >::operator std::basic_string_view< CharT, Traits > ( ) const
inlineconstexprnoexcept[[nodiscard]][[always_inline]][[pure]]

Definition at line 99 of file static_string.hpp.

99 {
100 return view;
101 }

◆ operator=() [1/2]

template<typename CharT , typename Traits = std::char_traits<CharT>>
ein_reinitializes constexpr basic_static_string & ein::basic_static_string< CharT, Traits >::operator= ( basic_static_string< CharT, Traits > && that)
constexprdefaultnoexcept[[always_inline]]

◆ operator=() [2/2]

template<typename CharT , typename Traits = std::char_traits<CharT>>
ein_reinitializes constexpr basic_static_string & ein::basic_static_string< CharT, Traits >::operator= ( basic_static_string< CharT, Traits > const & that)
constexprdefaultnoexcept[[always_inline]]

◆ operator[]()

template<typename CharT , typename Traits = std::char_traits<CharT>>
CharT const & ein::basic_static_string< CharT, Traits >::operator[] ( size_type i) const
inlineconstexprnoexcept[[nodiscard]][[always_inline]][[pure]]

access the specified character

Definition at line 114 of file static_string.hpp.

114{ return view[i]; }

References ein::basic_static_string< CharT, Traits >::view.

◆ rbegin()

template<typename CharT , typename Traits = std::char_traits<CharT>>
auto ein::basic_static_string< CharT, Traits >::rbegin ( ) const
inlineconstexprnoexcept[[nodiscard]][[always_inline]][[pure]]

Definition at line 210 of file static_string.hpp.

210{ return view.rbegin(); }

References ein::basic_static_string< CharT, Traits >::view.

◆ rend()

template<typename CharT , typename Traits = std::char_traits<CharT>>
auto ein::basic_static_string< CharT, Traits >::rend ( ) const
inlineconstexprnoexcept[[nodiscard]][[always_inline]][[pure]]

Definition at line 213 of file static_string.hpp.

213{ return view.rend(); }

References ein::basic_static_string< CharT, Traits >::view.

◆ size()

template<typename CharT , typename Traits = std::char_traits<CharT>>
size_type ein::basic_static_string< CharT, Traits >::size ( ) const
inlineconstexprnoexcept[[nodiscard]][[always_inline]][[pure]]

Definition at line 145 of file static_string.hpp.

145{ return view.size(); }

References ein::basic_static_string< CharT, Traits >::view.

Friends And Related Symbol Documentation

◆ operator!=

template<typename CharT , typename Traits = std::char_traits<CharT>>
bool operator!= ( basic_static_string< CharT, Traits > self,
basic_static_string< CharT, Traits > that )
friend[[nodiscard]][[always_inline]][[pure]][[artificial]]
Precondition
Traits::eq is assumed reflexive

Definition at line 174 of file static_string.hpp.

174 {
175 if constexpr (std::is_same_v<Traits,std::char_traits<CharT>> && one_of_t<CharT,char,wchar_t,char8_t,char16_t,char32_t>) {
176 return self.view.data() != that.view.data();
177 } else {
178 return (self.view.data() != that.view.data()) && (self.view != that.view);
179 }
180 }

◆ operator<<

template<typename CharT , typename Traits = std::char_traits<CharT>>
basic_ostream< CharT, Traits > & operator<< ( basic_ostream< CharT, Traits > & os,
basic_static_string< CharT, Traits > v )
friend

input/output

Exceptions
std::ios_base:failureif an exception is thrown during output.

Definition at line 187 of file static_string.hpp.

188 {
189 return os << v.view;
190 }

◆ operator==

template<typename CharT , typename Traits = std::char_traits<CharT>>
bool operator== ( basic_static_string< CharT, Traits > self,
basic_static_string< CharT, Traits > that )
friend[[nodiscard]][[always_inline]][[pure]][[artificial]]

Definition at line 164 of file static_string.hpp.

164 {
165 if constexpr (std::is_same_v<Traits,std::char_traits<CharT>> && one_of_t<CharT,char,wchar_t,char8_t,char16_t,char32_t>) {
166 return self.view.data() == that.view.data();
167 } else {
168 return (self.view.data() == that.view.data()) || (self.view == that.view); // fallback required
169 }
170 }

◆ static_c_string

template<typename CharT , typename Traits = std::char_traits<CharT>>
friend class static_c_string
friend

Definition at line 48 of file static_string.hpp.

◆ swap

template<typename CharT , typename Traits = std::char_traits<CharT>>
friend void swap ( basic_static_string< CharT, Traits > & x,
basic_static_string< CharT, Traits > & y )
friend[[always_inline]]

Definition at line 224 of file static_string.hpp.

224 {
225 using std::swap;
226 swap(x.view,y.view);
227 }
constexpr friend void swap(basic_static_string &x, basic_static_string &y) noexcept

Member Data Documentation

◆ npos

template<typename CharT , typename Traits = std::char_traits<CharT>>
size_type ein::basic_static_string< CharT, Traits >::npos = std::basic_string_view<CharT,Traits>::npos
staticconstexpr

Definition at line 229 of file static_string.hpp.

◆ view


The documentation for this class was generated from the following file: