forked from boostorg/static_string
Make data_impl constexpr for zero-size strings
This commit is contained in:
@ -119,7 +119,7 @@ public:
|
||||
#ifdef BOOST_STATIC_STRING_ALLOW_UNINIT_MEM
|
||||
CharT data_[N + 1];
|
||||
#else
|
||||
CharT data_[N + 1]{};
|
||||
CharT data_[N + 1]{0};
|
||||
#endif
|
||||
};
|
||||
|
||||
@ -129,17 +129,17 @@ class static_string_base_zero<0, CharT, Traits>
|
||||
{
|
||||
public:
|
||||
BOOST_STATIC_STRING_CPP11_CONSTEXPR
|
||||
static_string_base_zero() noexcept { }
|
||||
static_string_base_zero() noexcept { }
|
||||
|
||||
BOOST_STATIC_STRING_CPP11_CONSTEXPR
|
||||
static_string_base_zero(std::size_t) noexcept { }
|
||||
|
||||
// not possible to constexpr with the static there
|
||||
// Modifying the null terminator is UB
|
||||
BOOST_STATIC_STRING_CPP11_CONSTEXPR
|
||||
CharT*
|
||||
data_impl() const noexcept
|
||||
{
|
||||
static CharT null{};
|
||||
return &null;
|
||||
return const_cast<CharT*>(&null_);
|
||||
}
|
||||
|
||||
BOOST_STATIC_STRING_CPP11_CONSTEXPR
|
||||
@ -158,12 +158,15 @@ public:
|
||||
|
||||
BOOST_STATIC_STRING_CPP14_CONSTEXPR
|
||||
void
|
||||
term_impl() noexcept
|
||||
{
|
||||
term_impl() noexcept { }
|
||||
|
||||
}
|
||||
private:
|
||||
static constexpr CharT null_{0};
|
||||
};
|
||||
|
||||
template<typename CharT, typename Traits>
|
||||
constexpr CharT static_string_base_zero<0, CharT, Traits>::null_;
|
||||
|
||||
// Optimization for storing the size in the last element
|
||||
template<std::size_t N, typename CharT, typename Traits>
|
||||
class static_string_base_null
|
||||
@ -213,7 +216,7 @@ public:
|
||||
#ifdef BOOST_STATIC_STRING_ALLOW_UNINIT_MEM
|
||||
CharT data_[N + 1];
|
||||
#else
|
||||
CharT data_[N + 1]{};
|
||||
CharT data_[N + 1]{0};
|
||||
#endif
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user