( base ); }
- catch (std::bad_cast)
- { cout<<"caught bad_cast\n"; caught_exception = true; }
- if ( !caught_exception ) ++err_count;
- // the following is just so generated code can be inspected
- if ( derived->kind() == 'B' ) ++err_count;
-
- cout << err_count << " errors detected\nTest "
- << (err_count==0 ? "passed\n" : "failed\n");
- return err_count;
-} // main
diff --git a/index.html b/index.html
deleted file mode 100644
index cf8527f..0000000
--- a/index.html
+++ /dev/null
@@ -1,38 +0,0 @@
-
-
-
-
-
-
-
-Boost Conversion Library
-
-
-
-
-
Boost
-Conversion Library
-
-The Conversion Library improves program safety and clarity by performing
-otherwise messy conversions. It includes cast-style function templates designed to complement the C++
-Standard's built-in casts.
-To reduce coupling, particularly to standard library IOStreams, the Boost
-Conversion Library is
-supplied by several headers:
-
- - The boost/cast header provides polymorphic_cast<>
- and polymorphic_downcast<> to perform safe casting between
- polymorphic types.
-
- - The boost/lexical_cast header provides lexical_cast<>
- general literal text conversions, such as an
int
represented as
- a string
, or vice-versa.
-
-
-Revised June 23, 2005
-
-
-
-
-
\ No newline at end of file
diff --git a/lexical_cast.htm b/lexical_cast.htm
deleted file mode 100644
index 0ec5553..0000000
--- a/lexical_cast.htm
+++ /dev/null
@@ -1,239 +0,0 @@
-
-
-
-
- lexical_cast
-
-
-
-
-
-
-
-
- Sometimes a value must be converted to a literal text form, such as an int
- represented as a string
, or vice-versa, when a string
- is interpreted as an int
. Such examples are common when converting
- between data types internal to a program and representation external to a
- program, such as windows and configuration files.
-
- The standard C and C++ libraries offer a number of facilities for performing
- such conversions. However, they vary with their ease of use, extensibility, and
- safety.
-
- For instance, there are a number of limitations with the family of standard C
- functions typified by atoi
:
-
- -
- Conversion is supported in one direction only: from text to internal data type.
- Converting the other way using the C library requires either the inconvenience
- and compromised safety of the
sprintf
function, or the loss of
- portability associated with non-standard functions such as itoa
.
-
- -
- The range of types supported is only a subset of the built-in numeric types,
- namely
int
, long
, and double
.
-
- -
- The range of types cannot be extended in a uniform manner. For instance,
- conversion from string representation to
complex
or rational
.
-
-
- The standard C functions typified by strtol
have the same basic
- limitations, but offer finer control over the conversion process. However, for
- the common case such control is often either not required or not used. The scanf
- family of functions offer even greater control, but also lack safety and ease
- of use.
-
- The standard C++ library offers stringstream
for the kind of
- in-core formatting being discussed. It offers a great deal of control over the
- formatting and conversion of I/O to and from arbitrary types through text.
- However, for simple conversions direct use of stringstream
can be
- either clumsy (with the introduction of extra local variables and the loss of
- infix-expression convenience) or obscure (where stringstream
- objects are created as temporary objects in an expression). Facets provide a
- comprehensive concept and facility for controlling textual representation, but
- their perceived complexity and high entry level requires an extreme degree of
- involvement for simple conversions, and excludes all but a few programmers.
-
- The lexical_cast
function template offers a convenient and
- consistent form for supporting common conversions to and from arbitrary types
- when they are represented as text. The simplification it offers is in
- expression-level convenience for such conversions. For more involved
- conversions, such as where precision or formatting need tighter control than is
- offered by the default behavior of lexical_cast
, the conventional
- stringstream
approach is recommended. Where the conversions are
- numeric to numeric, numeric_cast
- may offer more reasonable behavior than lexical_cast
.
-
- For a good discussion of the options and issues involved in string-based
- formatting, including comparison of stringstream
, lexical_cast
,
- and others, see Herb Sutter's article,
- The String Formatters of Manor Farm.
-
-
-
- The following example treats command line arguments as a sequence of numeric
- data:
-
-int main(int argc, char * argv[])
-{
- using boost::lexical_cast;
- using boost::bad_lexical_cast;
-
- std::vector<short> args;
-
- while(*++argv)
- {
- try
- {
- args.push_back(lexical_cast<short>(*argv));
- }
- catch(bad_lexical_cast &)
- {
- args.push_back(0);
- }
- }
- ...
-}
-
-
The following example uses numeric data in a string expression:
-
-void log_message(const std::string &);
-
-void log_errno(int yoko)
-{
- log_message("Error " + boost::lexical_cast<std::string>(yoko) + ": " + strerror(yoko));
-}
-
-
-
-
- Library features defined in "boost/lexical_cast.hpp"
:
-
-
-namespace boost
-{
- class bad_lexical_cast;
- template<typename Target, typename Source>
- Target lexical_cast(Source arg);
-}
-
-
Unit test defined in "lexical_cast_test.cpp"
.
-
-
-
-
-
-template<typename Target, typename Source>
- Target lexical_cast(Source arg);
-
-
Returns the result of streaming arg
into a
- standard library string-based stream and then out as a Target
object.
- Where Target
is either std::string
- or std::wstring
, stream extraction takes the whole content
- of the string, including spaces, rather than relying on the default
- operator>>
behavior.
- If the conversion is unsuccessful, a
- bad_lexical_cast
exception is thrown.
-
- The requirements on the argument and result types are:
-
- -
-
Source
is OutputStreamable, meaning that an operator<<
- is defined that takes a std::ostream
or std::wostream
object on the
- left hand side and an instance of the argument type on the right.
-
- -
-
Target
is InputStreamable, meaning that an operator>>
- is defined that takes a std::istream
or std::wistream
object on the left hand side
- and an instance of the result type on the right.
-
- -
- Both
Source
and Target
are CopyConstructible [20.1.3].
-
- -
-
Target
is DefaultConstructible, meaning that it is possible
- to default-initialize an object of that type [8.5, 20.1.4].
-
-
- The character type of the underlying stream is assumed to be char
unless
- either the Source
or the Target
requires wide-character
- streaming, in which case the underlying stream uses wchar_t
.
- Source
types that require wide-character streaming are wchar_t
,
- wchar_t *
, and std::wstring
. Target
types that
- require wide-character streaming are wchar_t
and std::wstring
.
-
- Where a higher degree of control is required over conversions, std::stringstream
- and std::wstringstream
offer a more appropriate path. Where non-stream-based conversions are
- required, lexical_cast
- is the wrong tool for the job and is not special-cased for such scenarios.
-
-
-
-
-
-class bad_lexical_cast : public std::bad_cast
-{
-public:
- ... // same member function interface as std::exception
-};
-
-
Exception used to indicate runtime lexical_cast
- failure.
-
-
-
-June 2005:
-
- - Call-by-const reference for the parameters. This requires partial specialization
- of class templates, so it doesn't work for MSVC 6, and it uses the original
- pass by value there.
-
- - The MSVC 6 support is deprecated, and will be removed in a future Boost
- version.
-
-Earlier:
-
-
- - The previous version of
lexical_cast
used the default stream
- precision for reading and writing floating-point numbers. For numerics that
- have a corresponding specialization of std::numeric_limits
, the
- current version now chooses a precision to match.
- - The previous version of
lexical_cast
did not support conversion
- to or from any wide-character-based types. For compilers with full language
- and library support for wide characters, lexical_cast
now supports
- conversions from wchar_t
, wchar_t *
, and std::wstring
- and to wchar_t
and std::wstring
.
- - The previous version of
lexical_cast
assumed that the conventional
- stream extractor operators were sufficient for reading values. However, string
- I/O is asymmetric, with the result that spaces play the role of I/O separators
- rather than string content. The current version fixes this error for std::string
- and, where supported, std::wstring
: lexical_cast<std::string>("Hello,
- World")
succeeds instead of failing with a bad_lexical_cast
- exception.
- - The previous version of
lexical_cast
allowed unsafe and meaningless
- conversions to pointers. The current version now throws a bad_lexical_cast
- for conversions to pointers: lexical_cast<char *>("Goodbye, World")
- now throws an exception instead of causing undefined behavior.
-
-
-
-
-© Copyright Kevlin Henney, 20002005
-
-
diff --git a/lexical_cast_test.cpp b/lexical_cast_test.cpp
deleted file mode 100644
index 1e7f7ed..0000000
--- a/lexical_cast_test.cpp
+++ /dev/null
@@ -1,319 +0,0 @@
-// Unit test for boost::lexical_cast.
-//
-// See http://www.boost.org for most recent version, including documentation.
-//
-// Copyright Terje Slettebų and Kevlin Henney, 2005.
-//
-// 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).
-//
-// Note: The unit test no longer compile on MSVC 6, but lexical_cast itself works for it.
-
-#include
-
-#if defined(__INTEL_COMPILER)
-#pragma warning(disable: 193 383 488 981 1418 1419)
-#elif defined(BOOST_MSVC)
-#pragma warning(disable: 4097 4100 4121 4127 4146 4244 4245 4511 4512 4701 4800)
-#endif
-
-#include
-#include
-#include
-
-#if defined(BOOST_NO_STRINGSTREAM) || \
- defined(BOOST_NO_STD_WSTRING) || \
- defined(BOOST_NO_STD_LOCALE)
-#define DISABLE_WIDE_CHAR_SUPPORT
-#endif
-
-using namespace boost;
-
-void test_conversion_to_char();
-void test_conversion_to_int();
-void test_conversion_to_double();
-void test_conversion_to_bool();
-void test_conversion_to_string();
-void test_conversion_from_to_wchar_t_alias();
-void test_conversion_to_pointer();
-void test_conversion_from_wchar_t();
-void test_conversion_to_wchar_t();
-void test_conversion_from_wstring();
-void test_conversion_to_wstring();
-void test_bad_lexical_cast();
-void test_no_whitespace_stripping();
-
-unit_test_framework::test_suite *init_unit_test_suite(int, char **)
-{
- unit_test_framework::test_suite *suite =
- BOOST_TEST_SUITE("lexical_cast unit test");
- suite->add(BOOST_TEST_CASE(test_conversion_to_char));
- suite->add(BOOST_TEST_CASE(test_conversion_to_int));
- suite->add(BOOST_TEST_CASE(test_conversion_to_double));
- suite->add(BOOST_TEST_CASE(test_conversion_to_bool));
- suite->add(BOOST_TEST_CASE(test_conversion_from_to_wchar_t_alias));
- suite->add(BOOST_TEST_CASE(test_conversion_to_pointer));
- suite->add(BOOST_TEST_CASE(test_conversion_to_string));
- #ifndef DISABLE_WIDE_CHAR_SUPPORT
- suite->add(BOOST_TEST_CASE(test_conversion_from_wchar_t));
- suite->add(BOOST_TEST_CASE(test_conversion_to_wchar_t));
- suite->add(BOOST_TEST_CASE(test_conversion_from_wstring));
- suite->add(BOOST_TEST_CASE(test_conversion_to_wstring));
- #endif
- suite->add(BOOST_TEST_CASE(test_bad_lexical_cast));
- suite->add(BOOST_TEST_CASE(test_no_whitespace_stripping));
- return suite;
-}
-
-void test_conversion_to_char()
-{
- BOOST_CHECK_EQUAL('A', lexical_cast('A'));
- BOOST_CHECK_EQUAL(' ', lexical_cast(' '));
- BOOST_CHECK_EQUAL('1', lexical_cast(1));
- BOOST_CHECK_EQUAL('0', lexical_cast(0));
- BOOST_CHECK_THROW(lexical_cast(123), bad_lexical_cast);
- BOOST_CHECK_EQUAL('1', lexical_cast(1.0));
- BOOST_CHECK_EQUAL('1', lexical_cast(true));
- BOOST_CHECK_EQUAL('0', lexical_cast(false));
- BOOST_CHECK_EQUAL('A', lexical_cast("A"));
- BOOST_CHECK_EQUAL(' ', lexical_cast(" "));
- BOOST_CHECK_THROW(lexical_cast(""), bad_lexical_cast);
- BOOST_CHECK_THROW(lexical_cast("Test"), bad_lexical_cast);
- BOOST_CHECK_EQUAL('A', lexical_cast(std::string("A")));
- BOOST_CHECK_EQUAL(' ', lexical_cast(std::string(" ")));
- BOOST_CHECK_THROW(
- lexical_cast(std::string("")), bad_lexical_cast);
- BOOST_CHECK_THROW(
- lexical_cast(std::string("Test")), bad_lexical_cast);
-}
-
-void test_conversion_to_int()
-{
- BOOST_CHECK_EQUAL(1, lexical_cast('1'));
- BOOST_CHECK_EQUAL(0, lexical_cast('0'));
- BOOST_CHECK_THROW(lexical_cast('A'), bad_lexical_cast);
- BOOST_CHECK_EQUAL(1, lexical_cast(1));
- BOOST_CHECK_EQUAL(
- (std::numeric_limits::max)(),
- lexical_cast((std::numeric_limits::max)()));
- BOOST_CHECK_EQUAL(1, lexical_cast(1.0));
-
- BOOST_CHECK_THROW(lexical_cast(1.23), bad_lexical_cast);
-
- BOOST_CHECK_THROW(lexical_cast(1e20), bad_lexical_cast);
- BOOST_CHECK_EQUAL(1, lexical_cast(true));
- BOOST_CHECK_EQUAL(0, lexical_cast(false));
- BOOST_CHECK_EQUAL(123, lexical_cast("123"));
- BOOST_CHECK_THROW(
- lexical_cast(" 123"), bad_lexical_cast);
- BOOST_CHECK_THROW(lexical_cast(""), bad_lexical_cast);
- BOOST_CHECK_THROW(lexical_cast("Test"), bad_lexical_cast);
- BOOST_CHECK_EQUAL(123, lexical_cast("123"));
- BOOST_CHECK_EQUAL(123, lexical_cast(std::string("123")));
- BOOST_CHECK_THROW(
- lexical_cast(std::string(" 123")), bad_lexical_cast);
- BOOST_CHECK_THROW(
- lexical_cast(std::string("")), bad_lexical_cast);
- BOOST_CHECK_THROW(
- lexical_cast(std::string("Test")), bad_lexical_cast);
-}
-
-void test_conversion_to_double()
-{
- BOOST_CHECK_CLOSE(1.0, lexical_cast('1'), (std::numeric_limits::epsilon()));
- BOOST_CHECK_THROW(lexical_cast('A'), bad_lexical_cast);
- BOOST_CHECK_CLOSE(1.0, lexical_cast(1), (std::numeric_limits::epsilon()));
- BOOST_CHECK_CLOSE(1.23, lexical_cast(1.23), (std::numeric_limits::epsilon()));
- BOOST_CHECK_CLOSE(1.234567890, 1.234567890, std::numeric_limits::epsilon());
- BOOST_CHECK_CLOSE(1.0, lexical_cast(true), (std::numeric_limits::epsilon()));
- BOOST_CHECK_CLOSE(0.0, lexical_cast(false), (std::numeric_limits::epsilon()));
- BOOST_CHECK_CLOSE(1.23, lexical_cast("1.23"), (std::numeric_limits::epsilon()));
- BOOST_CHECK_THROW(lexical_cast(""), bad_lexical_cast);
- BOOST_CHECK_THROW(lexical_cast("Test"), bad_lexical_cast);
- BOOST_CHECK_CLOSE(1.23, lexical_cast(std::string("1.23")), (std::numeric_limits::epsilon()));
- BOOST_CHECK_THROW(
- lexical_cast(std::string("")), bad_lexical_cast);
- BOOST_CHECK_THROW(
- lexical_cast(std::string("Test")), bad_lexical_cast);
-}
-
-void test_conversion_to_bool()
-{
- BOOST_CHECK_EQUAL(true, lexical_cast('1'));
- BOOST_CHECK_EQUAL(false, lexical_cast('0'));
- BOOST_CHECK_THROW(lexical_cast('A'), bad_lexical_cast);
- BOOST_CHECK_EQUAL(true, lexical_cast(1));
- BOOST_CHECK_EQUAL(false, lexical_cast(0));
- BOOST_CHECK_THROW(lexical_cast(123), bad_lexical_cast);
- BOOST_CHECK_EQUAL(true, lexical_cast(1.0));
- BOOST_CHECK_EQUAL(false, lexical_cast(0.0));
- BOOST_CHECK_EQUAL(true, lexical_cast(true));
- BOOST_CHECK_EQUAL(false, lexical_cast(false));
- BOOST_CHECK_EQUAL(true, lexical_cast("1"));
- BOOST_CHECK_EQUAL(false, lexical_cast("0"));
- BOOST_CHECK_THROW(lexical_cast(""), bad_lexical_cast);
- BOOST_CHECK_THROW(lexical_cast("Test"), bad_lexical_cast);
- BOOST_CHECK_EQUAL(true, lexical_cast("1"));
- BOOST_CHECK_EQUAL(false, lexical_cast("0"));
- BOOST_CHECK_EQUAL(true, lexical_cast(std::string("1")));
- BOOST_CHECK_EQUAL(false, lexical_cast(std::string("0")));
- BOOST_CHECK_THROW(
- lexical_cast(std::string("")), bad_lexical_cast);
- BOOST_CHECK_THROW(
- lexical_cast(std::string("Test")), bad_lexical_cast);
-}
-
-void test_conversion_to_string()
-{
- BOOST_CHECK_EQUAL("A", lexical_cast('A'));
- BOOST_CHECK_EQUAL(" ", lexical_cast(' '));
- BOOST_CHECK_EQUAL("123", lexical_cast(123));
- BOOST_CHECK_EQUAL("1.23", lexical_cast(1.23));
- BOOST_CHECK_EQUAL("1.111111111", lexical_cast(1.111111111));
- BOOST_CHECK_EQUAL("1", lexical_cast(true));
- BOOST_CHECK_EQUAL("0", lexical_cast(false));
- BOOST_CHECK_EQUAL("Test", lexical_cast("Test"));
- BOOST_CHECK_EQUAL(" ", lexical_cast(" "));
- BOOST_CHECK_EQUAL("", lexical_cast(""));
- BOOST_CHECK_EQUAL("Test", lexical_cast(std::string("Test")));
- BOOST_CHECK_EQUAL(" ", lexical_cast(std::string(" ")));
- BOOST_CHECK_EQUAL("", lexical_cast(std::string("")));
-}
-
-void test_conversion_from_to_wchar_t_alias()
-{
- BOOST_CHECK_EQUAL(123u, lexical_cast("123"));
- BOOST_CHECK_EQUAL(123u, lexical_cast("123"));
- BOOST_CHECK_EQUAL(123u, lexical_cast("123"));
- BOOST_CHECK_EQUAL(std::string("123"),
- lexical_cast(static_cast(123)));
- BOOST_CHECK_EQUAL(std::string("123"), lexical_cast(123u));
- BOOST_CHECK_EQUAL(std::string("123"), lexical_cast(123ul));
-}
-
-void test_conversion_to_pointer()
-{
- BOOST_CHECK_THROW(lexical_cast("Test"), bad_lexical_cast);
- #ifndef DISABLE_WIDE_CHAR_SUPPORT
- BOOST_CHECK_THROW(lexical_cast("Test"), bad_lexical_cast);
- #endif
-}
-
-void test_conversion_from_wchar_t()
-{
-#ifndef DISABLE_WIDE_CHAR_SUPPORT
-#if !defined(BOOST_NO_INTRINSIC_WCHAR_T)
- BOOST_CHECK_EQUAL(1, lexical_cast(L'1'));
- BOOST_CHECK_THROW(lexical_cast(L'A'), bad_lexical_cast);
-#endif
-
- BOOST_CHECK_EQUAL(123, lexical_cast(L"123"));
- BOOST_CHECK_THROW(lexical_cast(L""), bad_lexical_cast);
- BOOST_CHECK_THROW(lexical_cast(L"Test"), bad_lexical_cast);
-
-#if !defined(BOOST_NO_INTRINSIC_WCHAR_T)
- BOOST_CHECK_EQUAL(1.0, lexical_cast(L'1'));
- BOOST_CHECK_THROW(lexical_cast(L'A'), bad_lexical_cast);
-#endif
-
- BOOST_CHECK_EQUAL(1.23, lexical_cast(L"1.23"));
- BOOST_CHECK_THROW(lexical_cast(L""), bad_lexical_cast);
- BOOST_CHECK_THROW(lexical_cast(L"Test"), bad_lexical_cast);
-
-#if !defined(BOOST_NO_INTRINSIC_WCHAR_T)
- BOOST_CHECK_EQUAL(true, lexical_cast(L'1'));
- BOOST_CHECK_EQUAL(false, lexical_cast(L'0'));
- BOOST_CHECK_THROW(lexical_cast(L'A'), bad_lexical_cast);
-#endif
- BOOST_CHECK_EQUAL(true, lexical_cast(L"1"));
- BOOST_CHECK_EQUAL(false, lexical_cast(L"0"));
- BOOST_CHECK_THROW(lexical_cast(L""), bad_lexical_cast);
- BOOST_CHECK_THROW(lexical_cast(L"Test"), bad_lexical_cast);
-#endif
-}
-
-void test_conversion_to_wchar_t()
-{
-#if !defined(DISABLE_WIDE_CHAR_SUPPORT) && !defined(BOOST_NO_INTRINSIC_WCHAR_T)
- BOOST_CHECK_EQUAL(L'1', lexical_cast(1));
- BOOST_CHECK_EQUAL(L'0', lexical_cast(0));
- BOOST_CHECK_THROW(lexical_cast(123), bad_lexical_cast);
- BOOST_CHECK_EQUAL(L'1', lexical_cast(1.0));
- BOOST_CHECK_EQUAL(L'0', lexical_cast(0.0));
- BOOST_CHECK_EQUAL(L'1', lexical_cast(true));
- BOOST_CHECK_EQUAL(L'0', lexical_cast(false));
- BOOST_CHECK_EQUAL(L'A', lexical_cast(L'A'));
- BOOST_CHECK_EQUAL(L' ', lexical_cast(L' '));
- BOOST_CHECK_EQUAL(L'A', lexical_cast(L"A"));
- BOOST_CHECK_EQUAL(L' ', lexical_cast(L" "));
- BOOST_CHECK_THROW(lexical_cast(L""), bad_lexical_cast);
- BOOST_CHECK_THROW(lexical_cast(L"Test"), bad_lexical_cast);
- BOOST_CHECK_EQUAL(L'A', lexical_cast(std::wstring(L"A")));
- BOOST_CHECK_EQUAL(L' ', lexical_cast(std::wstring(L" ")));
- BOOST_CHECK_THROW(
- lexical_cast(std::wstring(L"")), bad_lexical_cast);
- BOOST_CHECK_THROW(
- lexical_cast(std::wstring(L"Test")), bad_lexical_cast);
- #endif
-}
-
-void test_conversion_from_wstring()
-{
- #ifndef DISABLE_WIDE_CHAR_SUPPORT
- BOOST_CHECK_EQUAL(123, lexical_cast(std::wstring(L"123")));
- BOOST_CHECK_THROW(
- lexical_cast(std::wstring(L"")), bad_lexical_cast);
- BOOST_CHECK_THROW(
- lexical_cast(std::wstring(L"Test")), bad_lexical_cast);
-
- BOOST_CHECK_EQUAL(true, lexical_cast(std::wstring(L"1")));
- BOOST_CHECK_EQUAL(false, lexical_cast(std::wstring(L"0")));
- BOOST_CHECK_THROW(
- lexical_cast(std::wstring(L"")), bad_lexical_cast);
- BOOST_CHECK_THROW(
- lexical_cast(std::wstring(L"Test")), bad_lexical_cast);
- #endif
-}
-
-void test_conversion_to_wstring()
-{
- #ifndef DISABLE_WIDE_CHAR_SUPPORT
- BOOST_CHECK(L"123" == lexical_cast(123));
- BOOST_CHECK(L"1.23" == lexical_cast(1.23));
- BOOST_CHECK(L"1.111111111" == lexical_cast(1.111111111));
- BOOST_CHECK(L"1" == lexical_cast(true));
- BOOST_CHECK(L"0" == lexical_cast(false));
-#if !defined(BOOST_NO_INTRINSIC_WCHAR_T)
- BOOST_CHECK(L"A" == lexical_cast(L'A'));
- BOOST_CHECK(L" " == lexical_cast(L' '));
-#endif
- BOOST_CHECK(L"Test" == lexical_cast(L"Test"));
- BOOST_CHECK(L" " == lexical_cast(L" "));
- BOOST_CHECK(L"" == lexical_cast(L""));
- BOOST_CHECK(L"Test" == lexical_cast(std::wstring(L"Test")));
- BOOST_CHECK(L" " == lexical_cast(std::wstring(L" ")));
- BOOST_CHECK(L"" == lexical_cast(std::wstring(L"")));
- #endif
-}
-
-void test_bad_lexical_cast()
-{
- try
- {
- lexical_cast(std::string("Test"));
-
- BOOST_CHECK(false); // Exception expected
- }
- catch(const bad_lexical_cast &e)
- {
- BOOST_CHECK(e.source_type() == typeid(std::string));
- BOOST_CHECK(e.target_type() == typeid(int));
- }
-}
-
-void test_no_whitespace_stripping()
-{
- BOOST_CHECK_THROW(lexical_cast(" 123"), bad_lexical_cast);
- BOOST_CHECK_THROW(lexical_cast("123 "), bad_lexical_cast);
-}
diff --git a/numeric_cast_test.cpp b/numeric_cast_test.cpp
deleted file mode 100644
index 0b5bcde..0000000
--- a/numeric_cast_test.cpp
+++ /dev/null
@@ -1,100 +0,0 @@
-// boost utility cast test program -----------------------------------------//
-
-// (C) Copyright Beman Dawes, Dave Abrahams 1999. 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)
-
-// See http://www.boost.org for most recent version including documentation.
-
-// Revision History
-// 28 Set 04 factored out numeric_cast<> test (Fernando Cacciola)
-// 20 Jan 01 removed use of for portability to raw GCC (David Abrahams)
-// 28 Jun 00 implicit_cast removed (Beman Dawes)
-// 30 Aug 99 value_cast replaced by numeric_cast
-// 3 Aug 99 Initial Version
-
-#include
-#include
-#include // for DBL_MAX (Peter Schmid)
-#include
-
-#include "boost/test/minimal.hpp"
-
-# if SCHAR_MAX == LONG_MAX
-# error "This test program doesn't work if SCHAR_MAX == LONG_MAX"
-# endif
-
-using namespace boost;
-using std::cout;
-
-
-int test_main( int argc, char * argv[] )
-{
-
-# ifdef NDEBUG
- cout << "NDEBUG is defined\n";
-# else
- cout << "NDEBUG is not defined\n";
-# endif
-
- cout << "\nBeginning tests...\n";
-
-// test implicit_cast and numeric_cast -------------------------------------//
-
- // tests which should succeed
- long small_value = 1;
- long small_negative_value = -1;
- long large_value = LONG_MAX;
- long large_negative_value = LONG_MIN;
- signed char c = 0;
-
- c = large_value; // see if compiler generates warning
-
- c = numeric_cast( small_value );
- BOOST_CHECK( c == 1 );
- c = 0;
- c = numeric_cast( small_value );
- BOOST_CHECK( c == 1 );
- c = 0;
- c = numeric_cast( small_negative_value );
- BOOST_CHECK( c == -1 );
-
- // These tests courtesy of Joe R NWP Swatosh
- BOOST_CHECK( 0.0f == numeric_cast( 0.0 ) );
- BOOST_CHECK( 0.0 == numeric_cast( 0.0 ) );
-
- // tests which should result in errors being detected
-
- bool caught_exception = false;
- try { c = numeric_cast( large_value ); }
- catch (bad_numeric_cast)
- { cout<<"caught bad_numeric_cast #1\n"; caught_exception = true; }
- BOOST_CHECK ( caught_exception );
-
- caught_exception = false;
- try { c = numeric_cast( large_negative_value ); }
- catch (bad_numeric_cast)
- { cout<<"caught bad_numeric_cast #2\n"; caught_exception = true; }
- BOOST_CHECK ( caught_exception );
-
- unsigned long ul;
- caught_exception = false;
- try { ul = numeric_cast( large_negative_value ); }
- catch (bad_numeric_cast)
- { cout<<"caught bad_numeric_cast #3\n"; caught_exception = true; }
- BOOST_CHECK ( caught_exception );
-
- caught_exception = false;
- try { ul = numeric_cast( small_negative_value ); }
- catch (bad_numeric_cast)
- { cout<<"caught bad_numeric_cast #4\n"; caught_exception = true; }
- BOOST_CHECK ( caught_exception );
-
- caught_exception = false;
- try { numeric_cast( DBL_MAX ); }
- catch (bad_numeric_cast)
- { cout<<"caught bad_numeric_cast #5\n"; caught_exception = true; }
- BOOST_CHECK ( caught_exception );
-
- return 0 ;
-}
diff --git a/test.hpp b/test.hpp
deleted file mode 100644
index 4c7eecb..0000000
--- a/test.hpp
+++ /dev/null
@@ -1,308 +0,0 @@
-// what: simple unit test framework
-// who: developed by Kevlin Henney
-// when: November 2000
-// where: tested with BCC 5.5, MSVC 6.0, and g++ 2.91
-//
-// ChangeLog:
-// 20 Jan 2001 - Fixed a warning for MSVC (Dave Abrahams)
-
-#ifndef TEST_INCLUDED
-#define TEST_INCLUDED
-
-#include
-#include
-#include // for out-of-the-box g++
-#include
-
-namespace test // test tuple comprises name and nullary function (object)
-{
- template
- struct test
- {
- string_type name;
- function_type action;
-
- static test make(string_type name, function_type action)
- {
- test result; // MSVC aggreggate initializer bugs
- result.name = name;
- result.action = action;
- return result;
- }
- };
-}
-
-namespace test // failure exception used to indicate checked test failures
-{
- class failure : public std::exception
- {
- public: // struction (default cases are OK)
-
- failure(const std::string & why)
- : reason(why)
- {
- }
-
- // std::~string has no exception-specification (could throw anything),
- // but we need to be compatible with std::~exception's empty one
- // see std::15.4p13 and std::15.4p3
- ~failure() throw()
- {
- }
-
- public: // usage
-
- virtual const char * what() const throw()
- {
- return reason.c_str();
- }
-
- private: // representation
-
- std::string reason;
-
- };
-}
-
-namespace test // not_implemented exception used to mark unimplemented tests
-{
- class not_implemented : public std::exception
- {
- public: // usage (default ctor and dtor are OK)
-
- virtual const char * what() const throw()
- {
- return "not implemented";
- }
-
- };
-}
-
-namespace test // test utilities
-{
- inline void check(bool condition, const std::string & description)
- {
- if(!condition)
- {
- throw failure(description);
- }
- }
-
- inline void check_true(bool value, const std::string & description)
- {
- check(value, "expected true: " + description);
- }
-
- inline void check_false(bool value, const std::string & description)
- {
- check(!value, "expected false: " + description);
- }
-
- template
- void check_equal(
- const lhs_type & lhs, const rhs_type & rhs,
- const std::string & description)
- {
- check(lhs == rhs, "expected equal values: " + description);
- }
-
- template
- void check_unequal(
- const lhs_type & lhs, const rhs_type & rhs,
- const std::string & description)
- {
- check(lhs != rhs, "expected unequal values: " + description);
- }
-
- inline void check_null(const void* ptr, const std::string & description)
- {
- check(!ptr, "expected null pointer: " + description);
- }
-
- inline void check_non_null(const void* ptr, const std::string & description)
- {
- check(ptr != 0, "expected non-null pointer: " + description);
- }
-}
-
-#define TEST_CHECK_THROW(expression, exception, description) \
- try \
- { \
- expression; \
- throw ::test::failure(description); \
- } \
- catch(exception &) \
- { \
- }
-
-namespace test // memory tracking (enabled if test new and delete linked in)
-{
- class allocations
- {
- public: // singleton access
-
- static allocations & instance()
- {
- static allocations singleton;
- return singleton;
- }
-
- public: // logging
-
- void clear()
- {
- alloc_count = dealloc_count = 0;
- }
-
- void allocation()
- {
- ++alloc_count;
- }
-
- void deallocation()
- {
- ++dealloc_count;
- }
-
- public: // reporting
-
- unsigned long allocated() const
- {
- return alloc_count;
- }
-
- unsigned long deallocated() const
- {
- return dealloc_count;
- }
-
- bool balanced() const
- {
- return alloc_count == dealloc_count;
- }
-
- private: // structors (default dtor is fine)
-
- allocations()
- : alloc_count(0), dealloc_count(0)
- {
- }
-
- private: // prevention
-
- allocations(const allocations &);
- allocations & operator=(const allocations &);
-
- private: // state
-
- unsigned long alloc_count, dealloc_count;
-
- };
-}
-
-namespace test // tester is the driver class for a sequence of tests
-{
- template
- class tester
- {
- public: // structors (default destructor is OK)
-
- tester(test_iterator first_test, test_iterator after_last_test)
- : begin(first_test), end(after_last_test)
- {
- }
-
- public: // usage
-
- bool operator()(); // returns true if all tests passed
-
- private: // representation
-
- test_iterator begin, end;
-
- private: // prevention
-
- tester(const tester &);
- tester &operator=(const tester &);
-
- };
-
- template
- bool tester::operator()()
- {
- using namespace std;
-
- unsigned long passed = 0, failed = 0, unimplemented = 0;
-
- for(test_iterator current = begin; current != end; ++current)
- {
- cerr << "[" << current->name << "] " << flush;
- string result = "passed"; // optimistic
-
- try
- {
- allocations::instance().clear();
- current->action();
-
- if(!allocations::instance().balanced())
- {
- unsigned long allocated = allocations::instance().allocated();
- unsigned long deallocated = allocations::instance().deallocated();
- ostrstream report;
- report << "new/delete ("
- << allocated << " allocated, "
- << deallocated << " deallocated)"
- << ends;
- const char * text = report.str();
- report.freeze(false);
- throw failure(text);
- }
-
- ++passed;
- }
- catch(const failure & caught)
- {
- (result = "failed: ") += caught.what();
- ++failed;
- }
- catch(const not_implemented &)
- {
- result = "not implemented";
- ++unimplemented;
- }
- catch(const exception & caught)
- {
- (result = "exception: ") += caught.what();
- ++failed;
- }
- catch(...)
- {
- result = "failed with unknown exception";
- ++failed;
- }
-
- cerr << result << endl;
- }
-
- cerr << passed + failed << " tests: "
- << passed << " passed, "
- << failed << " failed";
-
- if(unimplemented)
- {
- cerr << " (" << unimplemented << " not implemented)";
- }
-
- cerr << endl;
-
- return failed == 0;
- }
-}
-
-#endif
-
-// Copyright Kevlin Henney, 2000. All rights reserved.
-//
-// 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)
diff --git a/test/Jamfile b/test/Jamfile
deleted file mode 100644
index 73bc860..0000000
--- a/test/Jamfile
+++ /dev/null
@@ -1,33 +0,0 @@
-# Signals library
-
-# Copyright (C) 2001-2003 Douglas Gregor
-
-# Permission to copy, use, sell and distribute this software is granted
-# provided this copyright notice appears in all copies. Permission to modify
-# the code and to distribute modified code is granted provided this copyright
-# notice appears in all copies, and a notice that the code was modified is
-# included with the copyright notice. This software is provided "as is"
-# without express or implied warranty, and with no claim as to its suitability
-# for any purpose.
-
-# For more information, see http://www.boost.org/
-
-
-# Testing Jamfile autogenerated from XML source
-subproject libs/conversion/test ;
-
-# bring in rules for testing
-import testing ;
-
-# Make tests run by default.
-DEPENDS all : test ;
-
-{
- test-suite conversion
- : [ run implicit_cast.cpp ]
- [ compile-fail implicit_cast_fail.cpp ]
- [ run ../cast_test.cpp ]
- [ run ../lexical_cast_test.cpp ]
- ;
-}
-
diff --git a/test/Jamfile.v2 b/test/Jamfile.v2
deleted file mode 100644
index 56f3a3f..0000000
--- a/test/Jamfile.v2
+++ /dev/null
@@ -1,26 +0,0 @@
-# Signals library
-
-# Copyright (C) 2001-2003 Douglas Gregor
-
-# Permission to copy, use, sell and distribute this software is granted
-# provided this copyright notice appears in all copies. Permission to modify
-# the code and to distribute modified code is granted provided this copyright
-# notice appears in all copies, and a notice that the code was modified is
-# included with the copyright notice. This software is provided "as is"
-# without express or implied warranty, and with no claim as to its suitability
-# for any purpose.
-
-# For more information, see http://www.boost.org/
-
-# bring in rules for testing
-import testing ;
-
-test-suite conversion
- : [ run implicit_cast.cpp ]
- [ compile-fail implicit_cast_fail.cpp ]
- [ run ../cast_test.cpp ]
- [ run ../numeric_cast_test.cpp ]
- [ run ../lexical_cast_test.cpp ]
- ;
-
-
\ No newline at end of file
diff --git a/test/implicit_cast.cpp b/test/implicit_cast.cpp
deleted file mode 100644
index 564c9eb..0000000
--- a/test/implicit_cast.cpp
+++ /dev/null
@@ -1,33 +0,0 @@
-// Copyright David Abrahams 2003.
-// 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
-#include
-#include
-
-using boost::implicit_cast;
-using boost::type;
-
-template
-type check_return(T) { return type(); }
-
-struct foo
-{
- foo(char const*) {}
- operator long() const { return 0; }
-};
-
-typedef type long_type;
-typedef type foo_type;
-
-int main()
-{
- type x = check_return(boost::implicit_cast(1));
- assert(boost::implicit_cast(1) == 1L);
-
- type f = check_return(boost::implicit_cast("hello"));
- type z = check_return(boost::implicit_cast(foo("hello")));
- return 0;
-}
diff --git a/test/implicit_cast_fail.cpp b/test/implicit_cast_fail.cpp
deleted file mode 100644
index 80143da..0000000
--- a/test/implicit_cast_fail.cpp
+++ /dev/null
@@ -1,22 +0,0 @@
-// Copyright David Abrahams 2003.
-// 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
-#include
-
-#define BOOST_INCLUDE_MAIN
-#include
-
-using boost::implicit_cast;
-
-struct foo
-{
- explicit foo(char const*) {}
-};
-
-int test_main(int, char*[])
-{
- foo x = implicit_cast("foobar");
-}