61 using reference = std::string_view::const_reference;
63 using iterator = std::string_view::const_iterator;
82 static_assert(std::is_nothrow_constructible_v<Metadata,
decltype(
str)>);
83 new (ptr_) Metadata{
str};
86 static_assert(
alignof(Metadata) >=
alignof(
value_type));
87 static_assert(std::is_nothrow_copy_constructible_v<value_type>);
100 static_cast<Metadata*
>(ptr_)->num_owners.fetch_add(1, std::memory_order_relaxed);
106 static_cast<Metadata*
>(ptr_)->num_owners.fetch_add(1, std::memory_order_relaxed);
124 if (
static_cast<Metadata*
>(ptr_)->num_owners.fetch_sub(1, std::memory_order_relaxed) == 1) {
125 ::operator delete(ptr_, std::align_val_t{
alignof(Metadata)});
131 std::swap(a.ptr_, b.ptr_);
138 return std::string_view{*
this}.at(
pos);
158 return std::string_view{*
this}.back();
165 return static_cast<value_type*
>(ptr_) +
sizeof(Metadata);
177 return std::string_view{
data(),
size()};
189 return std::string_view{*
this}.begin();
195 return std::string_view{*
this}.cbegin();
201 return std::string_view{*
this}.end();
207 return std::string_view{*
this}.cend();
218 return std::string_view{*
this}.starts_with(
sv);
224 return static_cast<const Metadata*
>(ptr_)->
size;
229 return lhs.ptr_ ==
rhs.ptr_
or std::string_view{
lhs} == std::string_view{
rhs};
232 template<
typename StringViewLike>
233 requires std::constructible_from<std::string_view, StringViewLike>
236 return std::string_view{
lhs} ==
rhs;
239 template<
typename StringViewLike>
240 requires std::constructible_from<std::string_view, StringViewLike>
243 return lhs == std::string_view{
rhs};
248 if (
lhs.ptr_ ==
rhs.ptr_) {
249 return std::strong_ordering::equal;
251 return std::string_view{
lhs} <=> std::string_view{
rhs};
254 template<
typename StringViewLike>
255 requires std::constructible_from<std::string_view, StringViewLike>
258 return std::string_view{
lhs} <=>
rhs;
261 template<
typename StringViewLike>
262 requires std::constructible_from<std::string_view, StringViewLike>
270 return lhs << std::string_view{
rhs};
279 return static_cast<long>(
static_cast<Metadata*
>(ptr_)->num_owners.load(std::memory_order_relaxed));
292 struct Metadata
final {
296 hash{std::hash<std::string_view>{}(
str)}
301 std::atomic<size_t> num_owners = 1;
305 void* ptr_ =
nullptr;
310struct std::hash<
osc::SharedPreHashedString> final {
313 return static_cast<const osc::SharedPreHashedString::Metadata*
>(str.ptr_)->hash;
Definition c_string_view.h:12
Definition shared_pre_hashed_string.h:55
const_reference at(size_type pos) const
Definition shared_pre_hashed_string.h:136
SharedPreHashedString(std::string_view str)
Definition shared_pre_hashed_string.h:72
friend constexpr auto operator<=>(const SharedPreHashedString &lhs, const StringViewLike &rhs)
Definition shared_pre_hashed_string.h:256
SharedPreHashedString(SharedPreHashedString &&tmp) noexcept
Definition shared_pre_hashed_string.h:103
SharedPreHashedString & operator=(const SharedPreHashedString &src) noexcept
Definition shared_pre_hashed_string.h:109
~SharedPreHashedString() noexcept
Definition shared_pre_hashed_string.h:122
std::string_view::const_reference const_reference
Definition shared_pre_hashed_string.h:62
friend constexpr auto operator<=>(const SharedPreHashedString &lhs, const SharedPreHashedString &rhs)
Definition shared_pre_hashed_string.h:246
SharedPreHashedString(const char *s)
Definition shared_pre_hashed_string.h:94
const_reference operator[](size_type pos) const
Definition shared_pre_hashed_string.h:144
friend constexpr bool operator==(const SharedPreHashedString &lhs, const StringViewLike &rhs)
Definition shared_pre_hashed_string.h:234
std::string_view::const_reverse_iterator const_reverse_iterator
Definition shared_pre_hashed_string.h:66
std::string_view::difference_type difference_type
Definition shared_pre_hashed_string.h:60
friend constexpr bool operator==(const StringViewLike &lhs, const SharedPreHashedString &rhs)
Definition shared_pre_hashed_string.h:241
long use_count() const noexcept
Definition shared_pre_hashed_string.h:277
SharedPreHashedString()
Definition shared_pre_hashed_string.h:68
SharedPreHashedString(const SharedPreHashedString &src) noexcept
Definition shared_pre_hashed_string.h:97
bool starts_with(std::string_view sv) const noexcept
Definition shared_pre_hashed_string.h:216
friend constexpr bool operator==(const SharedPreHashedString &lhs, const SharedPreHashedString &rhs)
Definition shared_pre_hashed_string.h:227
operator std::string_view() const noexcept
Definition shared_pre_hashed_string.h:175
std::string_view::value_type value_type
Definition shared_pre_hashed_string.h:58
size_type size() const
Definition shared_pre_hashed_string.h:222
const_iterator cend() const noexcept
Definition shared_pre_hashed_string.h:205
std::string_view::const_iterator iterator
Definition shared_pre_hashed_string.h:63
const_iterator end() const noexcept
Definition shared_pre_hashed_string.h:199
const_iterator begin() const noexcept
Definition shared_pre_hashed_string.h:187
const_reference front() const
Definition shared_pre_hashed_string.h:150
std::string_view::const_reverse_iterator reverse_iterator
Definition shared_pre_hashed_string.h:65
std::string_view::size_type size_type
Definition shared_pre_hashed_string.h:59
SharedPreHashedString(std::nullptr_t)=delete
SharedPreHashedString & operator=(SharedPreHashedString &&tmp) noexcept
Definition shared_pre_hashed_string.h:116
friend void swap(SharedPreHashedString &a, SharedPreHashedString &b) noexcept
Definition shared_pre_hashed_string.h:129
friend constexpr auto operator<=>(const StringViewLike &lhs, const SharedPreHashedString &rhs)
Definition shared_pre_hashed_string.h:263
const_reference back() const
Definition shared_pre_hashed_string.h:156
friend std::ostream & operator<<(std::ostream &lhs, const SharedPreHashedString &rhs)
Definition shared_pre_hashed_string.h:268
std::string_view::const_reference reference
Definition shared_pre_hashed_string.h:61
std::string_view::const_iterator const_iterator
Definition shared_pre_hashed_string.h:64
std::string_view::traits_type traits_type
Definition shared_pre_hashed_string.h:57
const value_type * c_str() const
Definition shared_pre_hashed_string.h:169
const value_type * data() const
Definition shared_pre_hashed_string.h:162
bool empty() const noexcept
Definition shared_pre_hashed_string.h:211
const_iterator cbegin() const noexcept
Definition shared_pre_hashed_string.h:193
size_t size(const OpenSim::Set< T, C > &s)
Definition open_sim_helpers.h:80
Definition custom_decoration_generator.h:5
constexpr U to(T &&value)
Definition conversion.h:56
size_t operator()(const osc::SharedPreHashedString &str) const noexcept
Definition shared_pre_hashed_string.h:311