Use inheritance for string implementation

This commit is contained in:
2025-03-14 18:53:39 +01:00
parent 4630cb5237
commit d1bb5a83f6
2 changed files with 21 additions and 22 deletions

View File

@ -390,14 +390,18 @@ public:
auto data(this auto&& self)
{
using return_type = un_ref_t<copy_cref_t<decltype(self), T>>*;
// NOLINTNEXTLINE(*-reinterpret-cast)
auto&& buffer = reinterpret_cast<copy_cref_t<decltype(self), class buffer>>(self);
if constexpr (kInlineCapacity == 0)
{
return return_type{ self.m_data };
return return_type{ buffer.m_data };
}
else
{
// NOLINTNEXTLINE(*-reinterpret-cast)
return self.is_on_heap() ? return_type{ self.m_data } : reinterpret_cast<return_type>(&self);
return buffer.is_on_heap()
? return_type{ buffer.m_data }
// NOLINTNEXTLINE(*-reinterpret-cast)
: reinterpret_cast<return_type>(&buffer);
}
}