forked from boostorg/conversion
Performance optimizations and testsfor conversions to/from boost::container::basic_string
[SVN r74940]
This commit is contained in:
@ -46,6 +46,7 @@
|
||||
#include <boost/static_assert.hpp>
|
||||
#include <boost/detail/lcast_precision.hpp>
|
||||
#include <boost/detail/workaround.hpp>
|
||||
#include <boost/container/container_fwd.hpp>
|
||||
#include <cwchar>
|
||||
|
||||
|
||||
@ -145,6 +146,12 @@ namespace boost
|
||||
{
|
||||
typedef CharT type;
|
||||
};
|
||||
|
||||
template<class CharT, class Traits, class Alloc>
|
||||
struct stream_char< ::boost::container::basic_string<CharT,Traits,Alloc> >
|
||||
{
|
||||
typedef CharT type;
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifndef BOOST_LCAST_NO_WCHAR_T
|
||||
@ -259,6 +266,24 @@ namespace boost
|
||||
typedef Traits type;
|
||||
};
|
||||
|
||||
template<class CharT, class Traits, class Alloc, class Source>
|
||||
struct deduce_char_traits< CharT
|
||||
, ::boost::container::basic_string<CharT,Traits,Alloc>
|
||||
, Source
|
||||
>
|
||||
{
|
||||
typedef Traits type;
|
||||
};
|
||||
|
||||
template<class CharT, class Target, class Traits, class Alloc>
|
||||
struct deduce_char_traits< CharT
|
||||
, Target
|
||||
, ::boost::container::basic_string<CharT,Traits,Alloc>
|
||||
>
|
||||
{
|
||||
typedef Traits type;
|
||||
};
|
||||
|
||||
template<class CharT, class Traits, class Alloc1, class Alloc2>
|
||||
struct deduce_char_traits< CharT
|
||||
, std::basic_string<CharT,Traits,Alloc1>
|
||||
@ -267,6 +292,15 @@ namespace boost
|
||||
{
|
||||
typedef Traits type;
|
||||
};
|
||||
|
||||
template<class CharT, class Traits, class Alloc1, class Alloc2>
|
||||
struct deduce_char_traits< CharT
|
||||
, ::boost::container::basic_string<CharT,Traits,Alloc1>
|
||||
, ::boost::container::basic_string<CharT,Traits,Alloc2>
|
||||
>
|
||||
{
|
||||
typedef Traits type;
|
||||
};
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -1257,6 +1291,14 @@ namespace boost
|
||||
return true;
|
||||
}
|
||||
|
||||
template<class Alloc>
|
||||
bool operator<<(::boost::container::basic_string<CharT,Traits,Alloc> const& str)
|
||||
{
|
||||
start = const_cast<CharT*>(str.data());
|
||||
finish = start + str.length();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool operator<<(bool value)
|
||||
{
|
||||
CharT const czero = lcast_char_constants<CharT>::zero;
|
||||
@ -1462,6 +1504,9 @@ namespace boost
|
||||
#else
|
||||
template<class Alloc>
|
||||
bool operator>>(std::basic_string<CharT,Traits,Alloc>& str) { str.assign(start, finish); return true; }
|
||||
|
||||
template<class Alloc>
|
||||
bool operator>>(::boost::container::basic_string<CharT,Traits,Alloc>& str) { str.assign(start, finish); return true; }
|
||||
#endif
|
||||
/*
|
||||
* case "-0" || "0" || "+0" : output = false; return true;
|
||||
@ -1598,6 +1643,12 @@ namespace boost
|
||||
BOOST_STATIC_CONSTANT(bool, value = true );
|
||||
};
|
||||
|
||||
template<typename CharT, typename Traits, typename Alloc>
|
||||
struct is_stdstring< ::boost::container::basic_string<CharT, Traits, Alloc> >
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(bool, value = true );
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct is_char_or_wchar
|
||||
{
|
||||
@ -1698,6 +1749,18 @@ namespace boost
|
||||
BOOST_STATIC_CONSTANT(bool, value = true );
|
||||
};
|
||||
|
||||
template<typename CharT, typename Traits, typename Alloc>
|
||||
struct is_char_array_to_stdstring< ::boost::container::basic_string<CharT, Traits, Alloc>, CharT* >
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(bool, value = true );
|
||||
};
|
||||
|
||||
template<typename CharT, typename Traits, typename Alloc>
|
||||
struct is_char_array_to_stdstring< ::boost::container::basic_string<CharT, Traits, Alloc>, const CharT* >
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(bool, value = true );
|
||||
};
|
||||
|
||||
#if (defined _MSC_VER)
|
||||
# pragma warning( push )
|
||||
# pragma warning( disable : 4701 ) // possible use of ... before initialization
|
||||
|
@ -28,6 +28,7 @@ test-suite conversion
|
||||
[ run lexical_cast_wchars_test.cpp ../../test/build//boost_unit_test_framework/<link>static ]
|
||||
[ run lexical_cast_float_types_test.cpp ../../test/build//boost_unit_test_framework/<link>static ]
|
||||
[ run lexical_cast_inf_nan_test.cpp ../../test/build//boost_unit_test_framework/<link>static ]
|
||||
[ run lexical_cast_containers_test.cpp ../../test/build//boost_unit_test_framework/<link>static ]
|
||||
;
|
||||
|
||||
|
||||
|
38
test/lexical_cast_containers_test.cpp
Normal file
38
test/lexical_cast_containers_test.cpp
Normal file
@ -0,0 +1,38 @@
|
||||
// Testing boost::lexical_cast with boost::container::string.
|
||||
//
|
||||
// See http://www.boost.org for most recent version, including documentation.
|
||||
//
|
||||
// Copyright Antony Polukhin, 2011.
|
||||
//
|
||||
// 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).
|
||||
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <boost/container/string.hpp>
|
||||
|
||||
void testing_boost_containers_basic_string();
|
||||
|
||||
using namespace boost;
|
||||
|
||||
boost::unit_test::test_suite *init_unit_test_suite(int, char *[])
|
||||
{
|
||||
unit_test::test_suite *suite =
|
||||
BOOST_TEST_SUITE("Testing boost::lexical_cast with boost::container::string");
|
||||
suite->add(BOOST_TEST_CASE(testing_boost_containers_basic_string));
|
||||
|
||||
return suite;
|
||||
}
|
||||
|
||||
void testing_boost_containers_basic_string()
|
||||
{
|
||||
BOOST_CHECK("100" == lexical_cast<boost::container::string>("100"));
|
||||
BOOST_CHECK(L"100" == lexical_cast<boost::container::wstring>(L"100"));
|
||||
|
||||
BOOST_CHECK("100" == lexical_cast<boost::container::string>(100));
|
||||
boost::container::string str("1000");
|
||||
BOOST_CHECK(1000 == lexical_cast<int>(str));
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user