Consistent initialization style

This commit is contained in:
Krystian Stasiowski
2020-02-28 14:35:16 -05:00
parent d75f97bca5
commit 18f89ef078

View File

@ -1257,7 +1257,7 @@ public:
at(size_type pos) at(size_type pos)
{ {
BOOST_STATIC_STRING_THROW_IF( BOOST_STATIC_STRING_THROW_IF(
pos >= size(), std::out_of_range{"pos >= size()"}); pos >= size(), std::out_of_range("pos >= size()"));
return data()[pos]; return data()[pos];
} }
@ -1270,7 +1270,7 @@ public:
at(size_type pos) const at(size_type pos) const
{ {
BOOST_STATIC_STRING_THROW_IF( BOOST_STATIC_STRING_THROW_IF(
pos >= size(), std::out_of_range{"pos >= size()"}); pos >= size(), std::out_of_range("pos >= size()"));
return data()[pos]; return data()[pos];
} }
@ -1526,7 +1526,7 @@ public:
reserve(size_type n) reserve(size_type n)
{ {
BOOST_STATIC_STRING_THROW_IF( BOOST_STATIC_STRING_THROW_IF(
n > max_size(), std::length_error{"n > max_size()"}); n > max_size(), std::length_error("n > max_size()"));
} }
/** Returns the number of characters that can be held in currently allocated storage. /** Returns the number of characters that can be held in currently allocated storage.
@ -1592,7 +1592,7 @@ public:
value_type ch) value_type ch)
{ {
BOOST_STATIC_STRING_THROW_IF( BOOST_STATIC_STRING_THROW_IF(
index > size(), std::out_of_range{"index > size()"}); index > size(), std::out_of_range("index > size()"));
insert(begin() + index, count, ch); insert(begin() + index, count, ch);
return *this; return *this;
} }
@ -1658,7 +1658,7 @@ public:
size_type count) size_type count)
{ {
BOOST_STATIC_STRING_THROW_IF( BOOST_STATIC_STRING_THROW_IF(
index > size(), std::out_of_range{"index > size()"}); index > size(), std::out_of_range("index > size()"));
insert(data() + index, s, s + count); insert(data() + index, s, s + count);
return *this; return *this;
} }
@ -4235,7 +4235,7 @@ private:
assign_char(value_type, std::false_type) assign_char(value_type, std::false_type)
{ {
BOOST_STATIC_STRING_THROW( BOOST_STATIC_STRING_THROW(
std::length_error{"max_size() == 0"}); std::length_error("max_size() == 0"));
// This eliminates any potential warnings // This eliminates any potential warnings
#ifdef BOOST_STATIC_STRING_NO_NORETURN #ifdef BOOST_STATIC_STRING_NO_NORETURN
return *this; return *this;
@ -4260,7 +4260,7 @@ private:
size_type n2) size_type n2)
{ {
BOOST_STATIC_STRING_THROW_IF( BOOST_STATIC_STRING_THROW_IF(
pos > size(), std::out_of_range{"pos > size()"}); pos > size(), std::out_of_range("pos > size()"));
return replace_unchecked(data() + pos, data() + pos + capped_length(pos, n1), s, n2); return replace_unchecked(data() + pos, data() + pos + capped_length(pos, n1), s, n2);
} }
@ -4280,7 +4280,7 @@ private:
size_type count) size_type count)
{ {
BOOST_STATIC_STRING_THROW_IF( BOOST_STATIC_STRING_THROW_IF(
index > size(), std::out_of_range{"index > size()"}); index > size(), std::out_of_range("index > size()"));
insert_unchecked(data() + index, s, count); insert_unchecked(data() + index, s, count);
return *this; return *this;
} }
@ -4310,7 +4310,7 @@ private:
size_type length) const size_type length) const
{ {
BOOST_STATIC_STRING_THROW_IF( BOOST_STATIC_STRING_THROW_IF(
index > size(), std::out_of_range{"index > size()"}); index > size(), std::out_of_range("index > size()"));
return (std::min)(length, size() - index); return (std::min)(length, size() - index);
} }
}; };
@ -4935,7 +4935,7 @@ basic_static_string(const_pointer s)
{ {
const auto count = traits_type::length(s); const auto count = traits_type::length(s);
BOOST_STATIC_STRING_THROW_IF(count > max_size(), BOOST_STATIC_STRING_THROW_IF(count > max_size(),
std::length_error{"count > max_size()"}); std::length_error("count > max_size()"));
traits_type::copy(data(), s, count + 1); traits_type::copy(data(), s, count + 1);
this->set_size(count); this->set_size(count);
} }
@ -4950,7 +4950,7 @@ assign(
basic_static_string& basic_static_string&
{ {
BOOST_STATIC_STRING_THROW_IF(count > max_size(), BOOST_STATIC_STRING_THROW_IF(count > max_size(),
std::length_error{"count > max_size()"}); std::length_error("count > max_size()"));
this->set_size(count); this->set_size(count);
traits_type::assign(data(), size(), ch); traits_type::assign(data(), size(), ch);
return term(); return term();
@ -4966,7 +4966,7 @@ assign(
basic_static_string& basic_static_string&
{ {
BOOST_STATIC_STRING_THROW_IF(count > max_size(), BOOST_STATIC_STRING_THROW_IF(count > max_size(),
std::length_error{"count > max_size()"}); std::length_error("count > max_size()"));
this->set_size(count); this->set_size(count);
traits_type::move(data(), s, size()); traits_type::move(data(), s, size());
return term(); return term();
@ -4991,7 +4991,7 @@ assign(
{ {
this->set_size(i); this->set_size(i);
term(); term();
BOOST_STATIC_STRING_THROW(std::length_error{"n > max_size()"}); BOOST_STATIC_STRING_THROW(std::length_error("n > max_size()"));
} }
traits_type::assign(*ptr, *first); traits_type::assign(*ptr, *first);
} }
@ -5012,7 +5012,7 @@ insert(
const auto curr_size = size(); const auto curr_size = size();
const auto curr_data = data(); const auto curr_data = data();
BOOST_STATIC_STRING_THROW_IF( BOOST_STATIC_STRING_THROW_IF(
count > max_size() - curr_size, std::length_error{"count() > max_size() - size()"}); count > max_size() - curr_size, std::length_error("count() > max_size() - size()"));
const auto index = pos - curr_data; const auto index = pos - curr_data;
traits_type::move(&curr_data[index + count], &curr_data[index], curr_size - index + 1); traits_type::move(&curr_data[index + count], &curr_data[index], curr_size - index + 1);
traits_type::assign(&curr_data[index], count, ch); traits_type::assign(&curr_data[index], count, ch);
@ -5038,31 +5038,37 @@ insert(
const std::size_t count = detail::distance(first, last); const std::size_t count = detail::distance(first, last);
const std::size_t index = pos - curr_data; const std::size_t index = pos - curr_data;
const auto first_addr = &*first; const auto first_addr = &*first;
BOOST_STATIC_STRING_THROW_IF( // gcc's static analyzer does not recognize exit via
count > max_size() - curr_size, std::length_error{"count > max_size() - size()"}); // exception as non-evaluation
const bool inside = detail::ptr_in_range(curr_data, curr_data + curr_size, first_addr); if (count > max_size() - curr_size)
if (!inside || (inside && (first_addr + count <= pos))) BOOST_STATIC_STRING_THROW(
{ std::length_error("count > max_size() - size()"));
traits_type::move(&curr_data[index + count], &curr_data[index], curr_size - index + 1);
detail::copy_with_traits<Traits>(first, last, &curr_data[index]);
}
else else
{ {
const size_type offset = first_addr - curr_data; const bool inside = detail::ptr_in_range(curr_data, curr_data + curr_size, first_addr);
traits_type::move(&curr_data[index + count], &curr_data[index], curr_size - index + 1); if (!inside || (inside && (first_addr + count <= pos)))
if (offset < index)
{ {
const size_type diff = index - offset; traits_type::move(&curr_data[index + count], &curr_data[index], curr_size - index + 1);
traits_type::copy(&curr_data[index], &curr_data[offset], diff); detail::copy_with_traits<Traits>(first, last, &curr_data[index]);
traits_type::copy(&curr_data[index + diff], &curr_data[index + count], count - diff);
} }
else else
{ {
traits_type::copy(&curr_data[index], &curr_data[offset + count], count); const size_type offset = first_addr - curr_data;
traits_type::move(&curr_data[index + count], &curr_data[index], curr_size - index + 1);
if (offset < index)
{
const size_type diff = index - offset;
traits_type::copy(&curr_data[index], &curr_data[offset], diff);
traits_type::copy(&curr_data[index + diff], &curr_data[index + count], count - diff);
}
else
{
traits_type::copy(&curr_data[index], &curr_data[offset + count], count);
}
} }
this->set_size(curr_size + count);
return curr_data + index;
} }
this->set_size(curr_size + count);
return curr_data + index;
} }
template<std::size_t N, typename CharT, typename Traits> template<std::size_t N, typename CharT, typename Traits>
@ -5114,7 +5120,7 @@ push_back(
{ {
const auto curr_size = size(); const auto curr_size = size();
BOOST_STATIC_STRING_THROW_IF( BOOST_STATIC_STRING_THROW_IF(
curr_size >= max_size(), std::length_error{"size() >= max_size()"}); curr_size >= max_size(), std::length_error("size() >= max_size()"));
traits_type::assign(data()[curr_size], ch); traits_type::assign(data()[curr_size], ch);
this->set_size(curr_size + 1); this->set_size(curr_size + 1);
term(); term();
@ -5131,7 +5137,7 @@ append(
{ {
const auto curr_size = size(); const auto curr_size = size();
BOOST_STATIC_STRING_THROW_IF( BOOST_STATIC_STRING_THROW_IF(
count > max_size() - curr_size, std::length_error{"count > max_size() - size()"}); count > max_size() - curr_size, std::length_error("count > max_size() - size()"));
traits_type::assign(end(), count, ch); traits_type::assign(end(), count, ch);
this->set_size(curr_size + count); this->set_size(curr_size + count);
return term(); return term();
@ -5148,7 +5154,7 @@ append(
{ {
const auto curr_size = size(); const auto curr_size = size();
BOOST_STATIC_STRING_THROW_IF( BOOST_STATIC_STRING_THROW_IF(
count > max_size() - curr_size, std::length_error{"count > max_size() - size()"}); count > max_size() - curr_size, std::length_error("count > max_size() - size()"));
traits_type::copy(end(), s, count); traits_type::copy(end(), s, count);
this->set_size(curr_size + count); this->set_size(curr_size + count);
return term(); return term();
@ -5161,7 +5167,7 @@ basic_static_string<N, CharT, Traits>::
resize(size_type n, value_type c) resize(size_type n, value_type c)
{ {
BOOST_STATIC_STRING_THROW_IF( BOOST_STATIC_STRING_THROW_IF(
n > max_size(), std::length_error{"n > max_size()"}); n > max_size(), std::length_error("n > max_size()"));
const auto curr_size = size(); const auto curr_size = size();
if(n > curr_size) if(n > curr_size)
traits_type::assign(data() + curr_size, n - curr_size, c); traits_type::assign(data() + curr_size, n - curr_size, c);
@ -5192,9 +5198,9 @@ swap(basic_static_string<M, CharT, Traits>& s)
{ {
const auto curr_size = size(); const auto curr_size = size();
BOOST_STATIC_STRING_THROW_IF( BOOST_STATIC_STRING_THROW_IF(
curr_size > s.max_size(), std::length_error{"size() > s.max_size()"}); curr_size > s.max_size(), std::length_error("size() > s.max_size()"));
BOOST_STATIC_STRING_THROW_IF( BOOST_STATIC_STRING_THROW_IF(
s.size() > max_size(), std::length_error{"s.size() > max_size()"}); s.size() > max_size(), std::length_error("s.size() > max_size()"));
basic_static_string tmp(s); basic_static_string tmp(s);
s.set_size(curr_size); s.set_size(curr_size);
traits_type::copy(&s.data()[0], data(), curr_size + 1); traits_type::copy(&s.data()[0], data(), curr_size + 1);
@ -5219,7 +5225,7 @@ replace(
BOOST_STATIC_STRING_THROW_IF( BOOST_STATIC_STRING_THROW_IF(
n > max_size() || n > max_size() ||
curr_size - n1 >= max_size() - n, curr_size - n1 >= max_size() - n,
std::length_error{"replaced string exceeds max_size()"}); std::length_error("replaced string exceeds max_size()"));
const auto pos = i1 - curr_data; const auto pos = i1 - curr_data;
traits_type::move(&curr_data[pos + n], i2, (end() - i2) + 1); traits_type::move(&curr_data[pos + n], i2, (end() - i2) + 1);
traits_type::assign(&curr_data[pos], n, c); traits_type::assign(&curr_data[pos], n, c);
@ -5250,7 +5256,7 @@ replace(
BOOST_STATIC_STRING_THROW_IF( BOOST_STATIC_STRING_THROW_IF(
n2 > max_size() || n2 > max_size() ||
curr_size - (std::min)(n1, curr_size - pos) >= max_size() - n2, curr_size - (std::min)(n1, curr_size - pos) >= max_size() - n2,
std::length_error{"replaced string exceeds max_size()"}); std::length_error("replaced string exceeds max_size()"));
const bool inside = detail::ptr_in_range(curr_data, curr_data + curr_size, first_addr); const bool inside = detail::ptr_in_range(curr_data, curr_data + curr_size, first_addr);
if (inside && first_addr == i1 && n1 == n2) if (inside && first_addr == i1 && n1 == n2)
return *this; return *this;
@ -5314,7 +5320,7 @@ replace(
BOOST_STATIC_STRING_THROW_IF( BOOST_STATIC_STRING_THROW_IF(
n2 > max_size() || n2 > max_size() ||
curr_size - (std::min)(n1, curr_size - pos) >= max_size() - n2, curr_size - (std::min)(n1, curr_size - pos) >= max_size() - n2,
std::length_error{"replaced string exceeds max_size()"}); std::length_error("replaced string exceeds max_size()"));
// Rotate to the correct order. [i2, end] will now start with the replaced string, // Rotate to the correct order. [i2, end] will now start with the replaced string,
// continue to the existing string not being replaced, and end with a null terminator // continue to the existing string not being replaced, and end with a null terminator
std::rotate(&curr_data[pos], &curr_data[curr_size + 1], &curr_data[curr_size + n2 + 1]); std::rotate(&curr_data[pos], &curr_data[curr_size + 1], &curr_data[curr_size + n2 + 1]);
@ -5464,7 +5470,7 @@ read_back(
if (overwrite_null) if (overwrite_null)
term(); term();
BOOST_STATIC_STRING_THROW( BOOST_STATIC_STRING_THROW(
std::length_error{"count > max_size() - size()"}); std::length_error("count > max_size() - size()"));
} }
traits_type::assign(curr_data[new_size++ + (!overwrite_null)], *first); traits_type::assign(curr_data[new_size++ + (!overwrite_null)], *first);
} }
@ -5489,7 +5495,7 @@ replace_unchecked(
BOOST_STATIC_STRING_THROW_IF( BOOST_STATIC_STRING_THROW_IF(
n2 > max_size() || n2 > max_size() ||
curr_size - (std::min)(n1, curr_size - pos) >= max_size() - n2, curr_size - (std::min)(n1, curr_size - pos) >= max_size() - n2,
std::length_error{"replaced string exceeds max_size()"}); std::length_error("replaced string exceeds max_size()"));
traits_type::move(&curr_data[pos + n2], i2, (end() - i2) + 1); traits_type::move(&curr_data[pos + n2], i2, (end() - i2) + 1);
traits_type::copy(&curr_data[pos], s, n2); traits_type::copy(&curr_data[pos], s, n2);
this->set_size((curr_size - n1) + n2); this->set_size((curr_size - n1) + n2);
@ -5510,7 +5516,7 @@ insert_unchecked(
const auto curr_size = size(); const auto curr_size = size();
BOOST_STATIC_STRING_THROW_IF( BOOST_STATIC_STRING_THROW_IF(
count > max_size() - curr_size, count > max_size() - curr_size,
std::length_error{"count > max_size() - size()"}); std::length_error("count > max_size() - size()"));
const std::size_t index = pos - curr_data; const std::size_t index = pos - curr_data;
traits_type::move(&curr_data[index + count], pos, (end() - pos) + 1); traits_type::move(&curr_data[index + count], pos, (end() - pos) + 1);
traits_type::copy(&curr_data[index], s, count); traits_type::copy(&curr_data[index], s, count);