Guarded static_asserts

This commit is contained in:
Krystian Stasiowski
2019-10-27 17:23:52 -04:00
parent 79df90dde0
commit 58ef0fb908
3 changed files with 12 additions and 0 deletions

View File

@ -126,7 +126,11 @@ CharT*
raw_to_string(CharT* last, std::size_t size, Integer i) raw_to_string(CharT* last, std::size_t size, Integer i)
{ {
boost::ignore_unused(size); boost::ignore_unused(size);
#ifdef BOOST_FIXED_STRING_USE_BOOST
BOOST_ASSERT(size >= max_digits(sizeof(Integer))); BOOST_ASSERT(size >= max_digits(sizeof(Integer)));
#else
assert(size >= max_digits(sizeof(Integer)));
#endif
return raw_to_string<CharT, Integer, Traits>( return raw_to_string<CharT, Integer, Traits>(
last, i, std::is_signed<Integer>{}); last, i, std::is_signed<Integer>{});
} }

View File

@ -916,7 +916,11 @@ public:
void void
pop_back() pop_back()
{ {
#ifdef BOOST_FIXED_STRING_USE_BOOST
BOOST_ASSERT(n_ > 0); BOOST_ASSERT(n_ > 0);
#else
assert(n > 0);
#endif
Traits::assign(s_[--n_], 0); Traits::assign(s_[--n_], 0);
} }

View File

@ -795,7 +795,11 @@ to_fixed_string(Integer x)
{ {
using CharT = char; using CharT = char;
using Traits = std::char_traits<CharT>; using Traits = std::char_traits<CharT>;
#ifdef BOOST_FIXED_STRING_USE_BOOST
BOOST_STATIC_ASSERT(std::is_integral<Integer>::value); BOOST_STATIC_ASSERT(std::is_integral<Integer>::value);
#else
static_assert(std::is_integral<Integer>::value);
#endif
char buf[detail::max_digits(sizeof(Integer))]; char buf[detail::max_digits(sizeof(Integer))];
auto last = buf + sizeof(buf); auto last = buf + sizeof(buf);
auto it = detail::raw_to_string< auto it = detail::raw_to_string<