Drop Boost.Range dependecy (#63)

This commit is contained in:
Antony Polukhin 2023-09-10 16:52:10 +03:00 committed by GitHub
parent c65a020401
commit 1ca93a8e27
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 94 additions and 34 deletions

View File

@ -19,7 +19,6 @@ target_link_libraries(boost_lexical_cast
Boost::core Boost::core
Boost::integer Boost::integer
Boost::numeric_conversion Boost::numeric_conversion
Boost::range
Boost::throw_exception Boost::throw_exception
Boost::type_traits Boost::type_traits
) )

View File

@ -27,7 +27,8 @@
#define BOOST_LCAST_NO_WCHAR_T #define BOOST_LCAST_NO_WCHAR_T
#endif #endif
#include <boost/range/iterator_range_core.hpp> #include <boost/lexical_cast/detail/buffer_view.hpp>
#include <boost/lexical_cast/bad_lexical_cast.hpp> #include <boost/lexical_cast/bad_lexical_cast.hpp>
#include <boost/lexical_cast/try_lexical_convert.hpp> #include <boost/lexical_cast/try_lexical_convert.hpp>
@ -49,7 +50,7 @@ namespace boost
inline Target lexical_cast(const char* chars, std::size_t count) inline Target lexical_cast(const char* chars, std::size_t count)
{ {
return ::boost::lexical_cast<Target>( return ::boost::lexical_cast<Target>(
::boost::iterator_range<const char*>(chars, chars + count) ::boost::conversion::detail::make_buffer_view(chars, chars + count)
); );
} }
@ -57,7 +58,7 @@ namespace boost
inline Target lexical_cast(const unsigned char* chars, std::size_t count) inline Target lexical_cast(const unsigned char* chars, std::size_t count)
{ {
return ::boost::lexical_cast<Target>( return ::boost::lexical_cast<Target>(
::boost::iterator_range<const unsigned char*>(chars, chars + count) ::boost::conversion::detail::make_buffer_view(chars, chars + count)
); );
} }
@ -65,7 +66,7 @@ namespace boost
inline Target lexical_cast(const signed char* chars, std::size_t count) inline Target lexical_cast(const signed char* chars, std::size_t count)
{ {
return ::boost::lexical_cast<Target>( return ::boost::lexical_cast<Target>(
::boost::iterator_range<const signed char*>(chars, chars + count) ::boost::conversion::detail::make_buffer_view(chars, chars + count)
); );
} }
@ -74,7 +75,7 @@ namespace boost
inline Target lexical_cast(const wchar_t* chars, std::size_t count) inline Target lexical_cast(const wchar_t* chars, std::size_t count)
{ {
return ::boost::lexical_cast<Target>( return ::boost::lexical_cast<Target>(
::boost::iterator_range<const wchar_t*>(chars, chars + count) ::boost::conversion::detail::make_buffer_view(chars, chars + count)
); );
} }
#endif #endif
@ -82,14 +83,14 @@ namespace boost
inline Target lexical_cast(const char16_t* chars, std::size_t count) inline Target lexical_cast(const char16_t* chars, std::size_t count)
{ {
return ::boost::lexical_cast<Target>( return ::boost::lexical_cast<Target>(
::boost::iterator_range<const char16_t*>(chars, chars + count) ::boost::conversion::detail::make_buffer_view(chars, chars + count)
); );
} }
template <typename Target> template <typename Target>
inline Target lexical_cast(const char32_t* chars, std::size_t count) inline Target lexical_cast(const char32_t* chars, std::size_t count)
{ {
return ::boost::lexical_cast<Target>( return ::boost::lexical_cast<Target>(
::boost::iterator_range<const char32_t*>(chars, chars + count) ::boost::conversion::detail::make_buffer_view(chars, chars + count)
); );
} }

View File

@ -0,0 +1,59 @@
// Copyright Antony Polukhin, 2011-2023.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_LEXICAL_CAST_DETAIL_BUFFER_VIEW_HPP
#define BOOST_LEXICAL_CAST_DETAIL_BUFFER_VIEW_HPP
#include <boost/config.hpp>
#ifdef BOOST_HAS_PRAGMA_ONCE
# pragma once
#endif
#include <iosfwd>
namespace boost { namespace conversion { namespace detail {
template < typename CharT >
struct buffer_view {
const CharT* begin;
const CharT* end;
};
template < typename CharT >
buffer_view<CharT> make_buffer_view(const CharT* begin, const CharT* end) {
return buffer_view<CharT>{begin, end};
}
inline buffer_view<char> make_buffer_view(const signed char* begin, const signed char* end) {
return buffer_view<char>{
reinterpret_cast<const char*>(begin),
reinterpret_cast<const char*>(end)
};
}
inline buffer_view<char> make_buffer_view(const unsigned char* begin, const unsigned char* end) {
return buffer_view<char>{
reinterpret_cast<const char*>(begin),
reinterpret_cast<const char*>(end)
};
}
template< typename CharT, typename Elem, typename Traits >
std::basic_ostream<Elem,Traits>& operator<<(
std::basic_ostream<Elem, Traits>& os,
buffer_view<CharT> r)
{
while (r.begin != r.end) {
os << r.begin[0];
++r.begin;
}
return os;
}
}}} // namespace boost::conversion::detail
#endif // BOOST_LEXICAL_CAST_DETAIL_BUFFER_VIEW_HPP

View File

@ -44,7 +44,7 @@
#include <array> #include <array>
#include <boost/range/iterator_range_core.hpp> #include <boost/lexical_cast/detail/buffer_view.hpp>
#include <boost/container/container_fwd.hpp> #include <boost/container/container_fwd.hpp>
#include <boost/lexical_cast/detail/converter_lexical_streams.hpp> #include <boost/lexical_cast/detail/converter_lexical_streams.hpp>
@ -54,6 +54,8 @@ namespace boost {
// Forward declaration // Forward declaration
template<class T, std::size_t N> template<class T, std::size_t N>
class array; class array;
template<class IteratorT>
class iterator_range;
namespace detail // normalize_single_byte_char<Char> namespace detail // normalize_single_byte_char<Char>
{ {
@ -110,6 +112,12 @@ namespace boost {
boost::detail::deduce_character_type_later< const Char* > boost::detail::deduce_character_type_later< const Char* >
> {}; > {};
template < typename Char >
struct stream_char_common< boost::conversion::detail::buffer_view< Char > >
{
typedef Char type;
};
template < typename Char > template < typename Char >
struct stream_char_common< boost::iterator_range< Char* > >: public boost::conditional< struct stream_char_common< boost::iterator_range< Char* > >: public boost::conditional<
boost::detail::is_character< Char >::value, boost::detail::is_character< Char >::value,

View File

@ -69,11 +69,12 @@
#include <boost/type_traits/make_unsigned.hpp> #include <boost/type_traits/make_unsigned.hpp>
#include <boost/type_traits/is_integral.hpp> #include <boost/type_traits/is_integral.hpp>
#include <boost/type_traits/is_float.hpp> #include <boost/type_traits/is_float.hpp>
#include <boost/range/iterator_range_core.hpp> #include <boost/lexical_cast/detail/buffer_view.hpp>
#include <boost/container/container_fwd.hpp> #include <boost/container/container_fwd.hpp>
#include <boost/integer.hpp> #include <boost/integer.hpp>
#include <boost/detail/basic_pointerbuf.hpp> #include <boost/detail/basic_pointerbuf.hpp>
#include <boost/core/noncopyable.hpp> #include <boost/core/noncopyable.hpp>
#include <boost/core/enable_if.hpp>
#ifndef BOOST_NO_CWCHAR #ifndef BOOST_NO_CWCHAR
# include <cwchar> # include <cwchar>
#endif #endif
@ -83,6 +84,8 @@ namespace boost {
// Forward declaration // Forward declaration
template<class T, std::size_t N> template<class T, std::size_t N>
class array; class array;
template<class IteratorT>
class iterator_range;
namespace detail // basic_unlockedbuf namespace detail // basic_unlockedbuf
{ {
@ -217,7 +220,11 @@ namespace boost {
bool shl_char_array_limited(CharT const* str, std::size_t max_size) noexcept { bool shl_char_array_limited(CharT const* str, std::size_t max_size) noexcept {
start = str; start = str;
finish = std::find(start, start + max_size, Traits::to_char_type(0)); finish = start;
const auto zero = Traits::to_char_type(0);
while (finish < start + max_size && zero != *finish) {
++ finish;
}
return true; return true;
} }
@ -363,30 +370,15 @@ namespace boost {
return true; return true;
} }
template <class C> bool operator<<(boost::conversion::detail::buffer_view<CharT> rng) noexcept {
typename boost::disable_if<boost::is_const<C>, bool>::type start = rng.begin;
operator<<(const iterator_range<C*>& rng) noexcept { finish = rng.end;
return (*this) << iterator_range<const C*>(rng.begin(), rng.end());
}
bool operator<<(const iterator_range<const CharT*>& rng) noexcept {
start = rng.begin();
finish = rng.end();
return true; return true;
} }
bool operator<<(const iterator_range<const signed char*>& rng) noexcept { template <class C>
return (*this) << iterator_range<const char*>( bool operator<<(const iterator_range<C*>& rng) noexcept {
reinterpret_cast<const char*>(rng.begin()), return (*this) << boost::conversion::detail::make_buffer_view(rng.begin(), rng.end());
reinterpret_cast<const char*>(rng.end())
);
}
bool operator<<(const iterator_range<const unsigned char*>& rng) noexcept {
return (*this) << iterator_range<const char*>(
reinterpret_cast<const char*>(rng.begin()),
reinterpret_cast<const char*>(rng.end())
);
} }
bool operator<<(char ch) { return shl_char(ch); } bool operator<<(char ch) { return shl_char(ch); }

View File

@ -39,11 +39,11 @@
#include <boost/type_traits/is_same.hpp> #include <boost/type_traits/is_same.hpp>
#include <boost/type_traits/is_arithmetic.hpp> #include <boost/type_traits/is_arithmetic.hpp>
#include <boost/lexical_cast/detail/buffer_view.hpp>
#include <boost/lexical_cast/detail/is_character.hpp> #include <boost/lexical_cast/detail/is_character.hpp>
#include <boost/lexical_cast/detail/converter_numeric.hpp> #include <boost/lexical_cast/detail/converter_numeric.hpp>
#include <boost/lexical_cast/detail/converter_lexical.hpp> #include <boost/lexical_cast/detail/converter_lexical.hpp>
#include <boost/range/iterator_range_core.hpp>
#include <boost/container/container_fwd.hpp> #include <boost/container/container_fwd.hpp>
namespace boost { namespace boost {
@ -209,7 +209,8 @@ namespace boost {
"This overload of try_lexical_convert is meant to be used only with arrays of characters." "This overload of try_lexical_convert is meant to be used only with arrays of characters."
); );
return ::boost::conversion::detail::try_lexical_convert( return ::boost::conversion::detail::try_lexical_convert(
::boost::iterator_range<const CharacterT*>(chars, chars + count), result ::boost::conversion::detail::make_buffer_view(chars, chars + count),
result
); );
} }