forked from boostorg/static_string
Added assert macros
This commit is contained in:
@ -10,8 +10,10 @@
|
|||||||
#ifndef BOOST_FIXED_STRING_CONFIG_HPP
|
#ifndef BOOST_FIXED_STRING_CONFIG_HPP
|
||||||
#define 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
|
#if __cplusplus >= 201703L
|
||||||
#define BOOST_FIXED_STRING_CPP17
|
#define BOOST_FIXED_STRING_CPP17
|
||||||
#elif __cplusplus >= 201402L
|
#elif __cplusplus >= 201402L
|
||||||
@ -20,16 +22,43 @@
|
|||||||
#define BOOST_FIXED_STRING_CPP11
|
#define BOOST_FIXED_STRING_CPP11
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// See if we can use `string_view`
|
||||||
#if defined(BOOST_FIXED_STRING_CPP17) || defined(BOOST_FIXED_STRING_USE_BOOST)
|
#if defined(BOOST_FIXED_STRING_CPP17) || defined(BOOST_FIXED_STRING_USE_BOOST)
|
||||||
#define BOOST_FIXED_STRING_STRING_VIEW
|
#define BOOST_FIXED_STRING_STRING_VIEW
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef BOOST_FIXED_STRING_USE_BOOST
|
#ifdef BOOST_FIXED_STRING_USE_BOOST
|
||||||
#include <boost/utility/string_view.hpp>
|
#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>
|
#include <string_view>
|
||||||
#endif
|
#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 boost {
|
||||||
namespace fixed_string {
|
namespace fixed_string {
|
||||||
@ -54,17 +83,6 @@ using basic_string_view =
|
|||||||
std::basic_string_view<CharT, Traits>;
|
std::basic_string_view<CharT, Traits>;
|
||||||
#endif
|
#endif
|
||||||
#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
|
} // fixed_string
|
||||||
} // boost
|
} // boost
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
#ifndef BOOST_FIXED_STRING_DETAIL_FIXED_STRING_HPP
|
#ifndef BOOST_FIXED_STRING_DETAIL_FIXED_STRING_HPP
|
||||||
#define 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 <boost/core/ignore_unused.hpp>
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
@ -126,11 +126,7 @@ 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_FIXED_STRING_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>{});
|
||||||
}
|
}
|
||||||
|
@ -607,7 +607,7 @@ public:
|
|||||||
//--------------------------------------------------------------------------
|
//--------------------------------------------------------------------------
|
||||||
|
|
||||||
/// Returns `true` if the string is empty.
|
/// Returns `true` if the string is empty.
|
||||||
BOOST_NODISCARD
|
BOOST_FIXED_STRING_NODISCARD
|
||||||
bool
|
bool
|
||||||
empty() const
|
empty() const
|
||||||
{
|
{
|
||||||
@ -916,11 +916,7 @@ public:
|
|||||||
void
|
void
|
||||||
pop_back()
|
pop_back()
|
||||||
{
|
{
|
||||||
#ifdef BOOST_FIXED_STRING_USE_BOOST
|
BOOST_FIXED_STRING_ASSERT(n_ > 0);
|
||||||
BOOST_ASSERT(n_ > 0);
|
|
||||||
#else
|
|
||||||
assert(n > 0);
|
|
||||||
#endif
|
|
||||||
Traits::assign(s_[--n_], 0);
|
Traits::assign(s_[--n_], 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1326,16 +1322,17 @@ public:
|
|||||||
swap(
|
swap(
|
||||||
fixed_string<M, CharT, Traits>& s);
|
fixed_string<M, CharT, Traits>& s);
|
||||||
|
|
||||||
|
template<size_t N>
|
||||||
fixed_string&
|
fixed_string&
|
||||||
replace(
|
replace(
|
||||||
size_type pos1,
|
size_type pos1,
|
||||||
size_type n1,
|
size_type n1,
|
||||||
const fixed_string& str)
|
const fixed_string<N, CharT, Traits>& str)
|
||||||
{
|
{
|
||||||
return replace(pos1, n1, str.data(), str.size());
|
return replace(pos1, n1, str.data(), str.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fixed_string&
|
fixed_string&
|
||||||
replace(
|
replace(
|
||||||
size_type pos1,
|
size_type pos1,
|
||||||
@ -1344,7 +1341,7 @@ public:
|
|||||||
size_type pos2,
|
size_type pos2,
|
||||||
size_type n2 = npos)
|
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
|
#ifdef BOOST_FIXED_STRING_STRING_VIEW
|
||||||
@ -1369,7 +1366,8 @@ public:
|
|||||||
|
|
||||||
#ifdef BOOST_FIXED_STRING_STRING_VIEW
|
#ifdef BOOST_FIXED_STRING_STRING_VIEW
|
||||||
template<typename T>
|
template<typename T>
|
||||||
#if GENERATING_DOCUMENTATION
|
#if GENERATI
|
||||||
|
NG_DOCUMENTATION
|
||||||
fixed_string&
|
fixed_string&
|
||||||
#else
|
#else
|
||||||
typename std::enable_if<
|
typename std::enable_if<
|
||||||
|
@ -12,9 +12,6 @@
|
|||||||
|
|
||||||
#include <boost/fixed_string/config.hpp>
|
#include <boost/fixed_string/config.hpp>
|
||||||
#include <boost/fixed_string/detail/fixed_string.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 boost {
|
||||||
namespace fixed_string {
|
namespace fixed_string {
|
||||||
@ -795,11 +792,7 @@ 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_FIXED_STRING_STATIC_ASSERT(std::is_integral<Integer>::value, "Integer must be an integral type");
|
||||||
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<
|
||||||
|
Reference in New Issue
Block a user