mirror of
https://github.com/boostorg/static_string.git
synced 2025-07-29 20:17:35 +02:00
Added assert macros
This commit is contained in:
@ -10,8 +10,10 @@
|
||||
#ifndef BOOST_FIXED_STRING_CONFIG_HPP
|
||||
#define BOOST_FIXED_STRING_CONFIG_HPP
|
||||
|
||||
#define BOOST_FIXED_STRING_USE_BOOST
|
||||
// Are we dependent on Boost?
|
||||
//#define BOOST_FIXED_STRING_USE_BOOST
|
||||
|
||||
// C++ version
|
||||
#if __cplusplus >= 201703L
|
||||
#define BOOST_FIXED_STRING_CPP17
|
||||
#elif __cplusplus >= 201402L
|
||||
@ -20,16 +22,43 @@
|
||||
#define BOOST_FIXED_STRING_CPP11
|
||||
#endif
|
||||
|
||||
// See if we can use `string_view`
|
||||
#if defined(BOOST_FIXED_STRING_CPP17) || defined(BOOST_FIXED_STRING_USE_BOOST)
|
||||
#define BOOST_FIXED_STRING_STRING_VIEW
|
||||
#endif
|
||||
|
||||
#ifdef BOOST_FIXED_STRING_USE_BOOST
|
||||
#include <boost/utility/string_view.hpp>
|
||||
#elif defined(BOOST_FIXED_STRING_CPP17)
|
||||
#include <boost/assert.hpp>
|
||||
#include <boost/static_assert.hpp>
|
||||
#include <boost/throw_exception.hpp>
|
||||
#else
|
||||
#include <cassert>
|
||||
#ifdef BOOST_FIXED_STRING_CPP17
|
||||
#include <string_view>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// Boost and non-Boost versions of utilities
|
||||
#ifdef BOOST_FIXED_STRING_USE_BOOST
|
||||
#define BOOST_FIXED_STRING_THROW(ex) BOOST_THROW_EXCEPTION(ex)
|
||||
#define BOOST_FIXED_STRING_STATIC_ASSERT(cond, msg) BOOST_STATIC_ASSERT_MSG(cond, msg)
|
||||
#define BOOST_FIXED_STRING_ASSERT(cond) BOOST_ASSERT(cond)
|
||||
#ifdef BOOST_NODISCARD
|
||||
#define BOOST_FIXED_STRING_NODISCARD BOOST_NODISCARD
|
||||
#else
|
||||
#define BOOST_FIXED_STRING_NODISCARD
|
||||
#endif
|
||||
#else
|
||||
#define BOOST_FIXED_STRING_THROW(ex) throw ex
|
||||
#define BOOST_FIXED_STRING_STATIC_ASSERT(cond, msg) static_assert(cond, msg)
|
||||
#define BOOST_FIXED_STRING_ASSERT(cond) assert(cond)
|
||||
#ifdef BOOST_FIXED_STRING_CPP17
|
||||
#define BOOST_FIXED_STRING_NODISCARD [[nodiscard]]
|
||||
#else
|
||||
#define BOOST_FIXED_STRING_NODISCARD
|
||||
#endif
|
||||
#endif
|
||||
|
||||
namespace boost {
|
||||
namespace fixed_string {
|
||||
@ -54,17 +83,6 @@ using basic_string_view =
|
||||
std::basic_string_view<CharT, Traits>;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef BOOST_NODISCARD
|
||||
#define BOOST_NODISCARD
|
||||
#endif
|
||||
|
||||
#ifdef BOOST_FIXED_STRING_USE_BOOST
|
||||
#define BOOST_FIXED_STRING_THROW(e) (BOOST_THROW_EXCEPTION(e))
|
||||
#else
|
||||
#define BOOST_FIXED_STRING_THROW(e) (throw e)
|
||||
#endif
|
||||
|
||||
} // fixed_string
|
||||
} // boost
|
||||
|
||||
|
@ -10,7 +10,7 @@
|
||||
#ifndef BOOST_FIXED_STRING_DETAIL_FIXED_STRING_HPP
|
||||
#define BOOST_FIXED_STRING_DETAIL_FIXED_STRING_HPP
|
||||
|
||||
#include <boost/assert.hpp>
|
||||
#include <boost/fixed_string/config.hpp>
|
||||
#include <boost/core/ignore_unused.hpp>
|
||||
#include <iterator>
|
||||
#include <type_traits>
|
||||
@ -126,11 +126,7 @@ CharT*
|
||||
raw_to_string(CharT* last, std::size_t size, Integer i)
|
||||
{
|
||||
boost::ignore_unused(size);
|
||||
#ifdef BOOST_FIXED_STRING_USE_BOOST
|
||||
BOOST_ASSERT(size >= max_digits(sizeof(Integer)));
|
||||
#else
|
||||
assert(size >= max_digits(sizeof(Integer)));
|
||||
#endif
|
||||
BOOST_FIXED_STRING_ASSERT(size >= max_digits(sizeof(Integer)));
|
||||
return raw_to_string<CharT, Integer, Traits>(
|
||||
last, i, std::is_signed<Integer>{});
|
||||
}
|
||||
|
@ -607,7 +607,7 @@ public:
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
/// Returns `true` if the string is empty.
|
||||
BOOST_NODISCARD
|
||||
BOOST_FIXED_STRING_NODISCARD
|
||||
bool
|
||||
empty() const
|
||||
{
|
||||
@ -916,12 +916,8 @@ public:
|
||||
void
|
||||
pop_back()
|
||||
{
|
||||
#ifdef BOOST_FIXED_STRING_USE_BOOST
|
||||
BOOST_ASSERT(n_ > 0);
|
||||
#else
|
||||
assert(n > 0);
|
||||
#endif
|
||||
Traits::assign(s_[--n_], 0);
|
||||
BOOST_FIXED_STRING_ASSERT(n_ > 0);
|
||||
Traits::assign(s_[--n_], 0);
|
||||
}
|
||||
|
||||
/** Appends `count` copies of character `ch`
|
||||
@ -1326,16 +1322,17 @@ public:
|
||||
swap(
|
||||
fixed_string<M, CharT, Traits>& s);
|
||||
|
||||
|
||||
template<size_t N>
|
||||
fixed_string&
|
||||
replace(
|
||||
size_type pos1,
|
||||
size_type n1,
|
||||
const fixed_string& str)
|
||||
const fixed_string<N, CharT, Traits>& str)
|
||||
{
|
||||
return replace(pos1, n1, str.data(), str.size());
|
||||
}
|
||||
|
||||
|
||||
fixed_string&
|
||||
replace(
|
||||
size_type pos1,
|
||||
@ -1344,7 +1341,7 @@ public:
|
||||
size_type pos2,
|
||||
size_type n2 = npos)
|
||||
{
|
||||
return replace(pos1, n1, string_view_type(str).substr(pos2, n2));
|
||||
return replace(pos1, n1, str.substr(pos2, n2));
|
||||
}
|
||||
|
||||
#ifdef BOOST_FIXED_STRING_STRING_VIEW
|
||||
@ -1369,7 +1366,8 @@ public:
|
||||
|
||||
#ifdef BOOST_FIXED_STRING_STRING_VIEW
|
||||
template<typename T>
|
||||
#if GENERATING_DOCUMENTATION
|
||||
#if GENERATI
|
||||
NG_DOCUMENTATION
|
||||
fixed_string&
|
||||
#else
|
||||
typename std::enable_if<
|
||||
|
@ -12,9 +12,6 @@
|
||||
|
||||
#include <boost/fixed_string/config.hpp>
|
||||
#include <boost/fixed_string/detail/fixed_string.hpp>
|
||||
#include <boost/assert.hpp>
|
||||
#include <boost/static_assert.hpp>
|
||||
#include <boost/throw_exception.hpp>
|
||||
|
||||
namespace boost {
|
||||
namespace fixed_string {
|
||||
@ -795,11 +792,7 @@ to_fixed_string(Integer x)
|
||||
{
|
||||
using CharT = char;
|
||||
using Traits = std::char_traits<CharT>;
|
||||
#ifdef BOOST_FIXED_STRING_USE_BOOST
|
||||
BOOST_STATIC_ASSERT(std::is_integral<Integer>::value);
|
||||
#else
|
||||
static_assert(std::is_integral<Integer>::value);
|
||||
#endif
|
||||
BOOST_FIXED_STRING_STATIC_ASSERT(std::is_integral<Integer>::value, "Integer must be an integral type");
|
||||
char buf[detail::max_digits(sizeof(Integer))];
|
||||
auto last = buf + sizeof(buf);
|
||||
auto it = detail::raw_to_string<
|
||||
|
Reference in New Issue
Block a user