Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop C++03 and C++98 support #62

Merged
merged 7 commits into from
Sep 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,12 @@ target_include_directories(boost_lexical_cast INTERFACE include)

target_link_libraries(boost_lexical_cast
INTERFACE
Boost::array
Boost::assert
Boost::config
Boost::container
Boost::core
Boost::integer
Boost::numeric_conversion
Boost::range
Boost::static_assert
Boost::throw_exception
Boost::type_traits
)
Expand Down
4 changes: 4 additions & 0 deletions doc/lexical_cast.qbk
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,10 @@ limitation of compiler options that you use.

[section Changes]

* [*boost 1.84.0 :]

* Dropped support of C++98 and C++03.

* [*boost 1.56.0 :]

* Added `boost::conversion::try_lexical_convert` functions.
Expand Down
4 changes: 2 additions & 2 deletions example/generic_stringize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ std::string stringize(const Sequence& seq) {
}

//` Step 3: Using the `stringize` with different types:
#include <boost/fusion/adapted/boost_tuple.hpp>
#include <boost/fusion/adapted/std_tuple.hpp>
#include <boost/fusion/adapted/std_pair.hpp>

int main() {
boost::tuple<char, int, char, int> decim('-', 10, 'e', 5);
std::tuple<char, int, char, int> decim('-', 10, 'e', 5);
if (stringize(decim) != "-10e5") {
return 1;
}
Expand Down
6 changes: 4 additions & 2 deletions example/small_examples.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
// or a copy at <http://www.boost.org/LICENSE_1_0.txt>.)

#include <boost/lexical_cast.hpp>

#include <array>
#include <string>
#include <cstdio>

Expand All @@ -30,9 +32,9 @@ void log_errno(int yoko)

void number_to_file(int number, std::FILE* file)
{
typedef boost::array<char, 50> buf_t; // You can use std::array if your compiler supports it
using buf_t = std::array<char, 50>;
buf_t buffer = boost::lexical_cast<buf_t>(number); // No dynamic memory allocation
std::fputs(buffer.begin(), file);
std::fputs(buffer.data(), file);
}

//] [/lexical_cast_fixed_buffer]
Expand Down
5 changes: 0 additions & 5 deletions include/boost/detail/basic_pointerbuf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,8 @@ class basic_pointerbuf : public BufferT {
basic_pointerbuf() : base_type() { this_type::setbuf(0, 0); }
const charT* getnext() { return this->gptr(); }

#ifndef BOOST_NO_USING_TEMPLATE
using base_type::pptr;
using base_type::pbase;
#else
charT* pptr() const { return base_type::pptr(); }
charT* pbase() const { return base_type::pbase(); }
#endif

protected:
// VC mistakenly assumes that `setbuf` and other functions are not referenced.
Expand Down
89 changes: 6 additions & 83 deletions include/boost/detail/lcast_precision.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,10 @@
#include <boost/type_traits/is_abstract.hpp>
#endif

#if defined(BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS) || \
(defined(BOOST_MSVC) && (BOOST_MSVC<1310))

#define BOOST_LCAST_NO_COMPILE_TIME_PRECISION
#endif

#ifdef BOOST_LCAST_NO_COMPILE_TIME_PRECISION
#include <boost/assert.hpp>
#else
#include <boost/static_assert.hpp>
#endif

namespace boost { namespace detail {

class lcast_abstract_stub {};

#ifndef BOOST_LCAST_NO_COMPILE_TIME_PRECISION
// Calculate an argument to pass to std::ios_base::precision from
// lexical_cast. See alternative implementation for broken standard
// libraries in lcast_get_precision below. Keep them in sync, please.
Expand All @@ -47,7 +34,7 @@ struct lcast_precision
#ifdef BOOST_NO_IS_ABSTRACT
typedef std::numeric_limits<T> limits; // No fix for SF:1358600.
#else
typedef BOOST_DEDUCED_TYPENAME boost::conditional<
typedef typename boost::conditional<
boost::is_abstract<T>::value
, std::numeric_limits<lcast_abstract_stub>
, std::numeric_limits<T>
Expand All @@ -74,95 +61,31 @@ struct lcast_precision

BOOST_STATIC_CONSTANT(unsigned int, precision_dec = limits::digits10 + 1U);

BOOST_STATIC_ASSERT(!is_specialized_dec ||
static_assert(!is_specialized_dec ||
precision_dec <= streamsize_max + 0UL
);
, "");

BOOST_STATIC_CONSTANT(unsigned long, precision_bin =
2UL + limits::digits * 30103UL / 100000UL
);

BOOST_STATIC_ASSERT(!is_specialized_bin ||
static_assert(!is_specialized_bin ||
(limits::digits + 0UL < ULONG_MAX / 30103UL &&
precision_bin > limits::digits10 + 0UL &&
precision_bin <= streamsize_max + 0UL)
);
, "");

BOOST_STATIC_CONSTANT(std::streamsize, value =
is_specialized_bin ? precision_bin
: is_specialized_dec ? precision_dec : 6
);
};
#endif


template<class T>
inline std::streamsize lcast_get_precision(T* = 0)
{
#ifndef BOOST_LCAST_NO_COMPILE_TIME_PRECISION
return lcast_precision<T>::value;
#else // Follow lcast_precision algorithm at run-time:

#ifdef BOOST_NO_IS_ABSTRACT
typedef std::numeric_limits<T> limits; // No fix for SF:1358600.
#else
typedef BOOST_DEDUCED_TYPENAME boost::conditional<
boost::is_abstract<T>::value
, std::numeric_limits<lcast_abstract_stub>
, std::numeric_limits<T>
>::type limits;
#endif

bool const use_default_precision =
!limits::is_specialized || limits::is_exact;

if(!use_default_precision)
{ // Includes all built-in floating-point types, float, double ...
// and UDT types for which digits (significand bits) is defined (not zero)

bool const is_specialized_bin =
limits::radix == 2 && limits::digits > 0;
bool const is_specialized_dec =
limits::radix == 10 && limits::digits10 > 0;
std::streamsize const streamsize_max =
(boost::integer_traits<std::streamsize>::max)();
(void)streamsize_max;

if(is_specialized_bin)
{ // Floating-point types with
// limits::digits defined by the specialization.

unsigned long const digits = limits::digits;
unsigned long const precision = 2UL + digits * 30103UL / 100000UL;
// unsigned long is selected because it is at least 32-bits
// and thus ULONG_MAX / 30103UL is big enough for all types.
BOOST_ASSERT(
digits < ULONG_MAX / 30103UL &&
precision > limits::digits10 + 0UL &&
precision <= streamsize_max + 0UL
);
return precision;
}
else if(is_specialized_dec)
{ // Decimal Floating-point type, most likely a User Defined Type
// rather than a real floating-point hardware type.
unsigned int const precision = limits::digits10 + 1U;
BOOST_ASSERT(precision <= streamsize_max + 0UL);
return precision;
}
}

// Integral type (for which precision has no effect)
// or type T for which limits is NOT specialized,
// so assume stream precision remains the default 6 decimal digits.
// Warning: if your User-defined Floating-point type T is NOT specialized,
// then you may lose accuracy by only using 6 decimal digits.
// To avoid this, you need to specialize T with either
// radix == 2 and digits == the number of significand bits,
// OR
// radix = 10 and digits10 == the number of decimal digits.

return 6;
#endif
}

template<class T>
Expand Down
22 changes: 0 additions & 22 deletions include/boost/lexical_cast.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,6 @@
# pragma once
#endif

#include <boost/config/pragma_message.hpp>
#if defined(BOOST_NO_CXX11_RVALUE_REFERENCES) || \
defined(BOOST_NO_CXX11_AUTO_DECLARATIONS) || \
defined(BOOST_NO_CXX11_CONSTEXPR) || \
defined(BOOST_NO_CXX11_NULLPTR) || \
defined(BOOST_NO_CXX11_NOEXCEPT) || \
defined(BOOST_NO_CXX11_DEFAULTED_FUNCTIONS) || \
defined(BOOST_NO_CXX11_FINAL) || \
defined(BOOST_NO_CXX11_ALIGNOF) || \
defined(BOOST_NO_CXX11_STATIC_ASSERT) || \
defined(BOOST_NO_CXX11_SMART_PTR) || \
defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) || \
defined(BOOST_NO_CXX11_HDR_TYPE_TRAITS)

BOOST_PRAGMA_MESSAGE("C++03 support is deprecated in Boost.LexicalCast 1.82 and will be removed in Boost.LexicalCast 1.84.")

#endif

#if defined(BOOST_NO_STRINGSTREAM) || defined(BOOST_NO_STD_WSTRING)
#define BOOST_LCAST_NO_WCHAR_T
#endif
Expand Down Expand Up @@ -96,24 +78,20 @@ namespace boost
);
}
#endif
#ifndef BOOST_NO_CXX11_CHAR16_T
template <typename Target>
inline Target lexical_cast(const char16_t* chars, std::size_t count)
{
return ::boost::lexical_cast<Target>(
::boost::iterator_range<const char16_t*>(chars, chars + count)
);
}
#endif
#ifndef BOOST_NO_CXX11_CHAR32_T
template <typename Target>
inline Target lexical_cast(const char32_t* chars, std::size_t count)
{
return ::boost::lexical_cast<Target>(
::boost::iterator_range<const char32_t*>(chars, chars + count)
);
}
#endif

} // namespace boost

Expand Down
22 changes: 8 additions & 14 deletions include/boost/lexical_cast/bad_lexical_cast.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,29 +37,23 @@ namespace boost
#else
public std::bad_cast
#endif

#if defined(BOOST_BORLANDC) && BOOST_WORKAROUND( BOOST_BORLANDC, < 0x560 )
// under bcc32 5.5.1 bad_cast doesn't derive from exception
, public std::exception
#endif

{
public:
bad_lexical_cast() BOOST_NOEXCEPT
bad_lexical_cast() noexcept
#ifndef BOOST_NO_TYPEID
: source(&typeid(void)), target(&typeid(void))
#endif
{}

const char *what() const BOOST_NOEXCEPT_OR_NOTHROW BOOST_OVERRIDE {
const char *what() const noexcept override {
return "bad lexical cast: "
"source type value could not be interpreted as target";
}

~bad_lexical_cast() BOOST_NOEXCEPT_OR_NOTHROW BOOST_OVERRIDE = default;
~bad_lexical_cast() override = default;

bad_lexical_cast(const bad_lexical_cast&) BOOST_NOEXCEPT_OR_NOTHROW = default;
bad_lexical_cast& operator=(const bad_lexical_cast&) BOOST_NOEXCEPT_OR_NOTHROW = default;
bad_lexical_cast(const bad_lexical_cast&) = default;
bad_lexical_cast& operator=(const bad_lexical_cast&) = default;

#ifndef BOOST_NO_TYPEID
private:
Expand All @@ -71,15 +65,15 @@ namespace boost
public:
bad_lexical_cast(
const type_info_t &source_type_arg,
const type_info_t &target_type_arg) BOOST_NOEXCEPT
const type_info_t &target_type_arg) noexcept
: source(&source_type_arg), target(&target_type_arg)
{}

const type_info_t &source_type() const BOOST_NOEXCEPT {
const type_info_t &source_type() const noexcept {
return *source;
}

const type_info_t &target_type() const BOOST_NOEXCEPT {
const type_info_t &target_type() const noexcept {
return *target;
}

Expand Down
Loading
Loading