diff --git a/cast.htm b/cast.htm
deleted file mode 100644
index 9122c01..0000000
--- a/cast.htm
+++ /dev/null
@@ -1,150 +0,0 @@
-
-
-
-
-
-
-
-
-Header boost/cast.hpp Documentation
-
-
-
-
-
-
-
-
-The header boost/cast.hpp
-provides polymorphic_cast, polymorphic_downcast,
-and numeric_cast function templates designed
-to complement the C++ built-in casts.
-
-The program cast_test.cpp can be used to
-verify these function templates work as expected.
-
-Pointers to polymorphic objects (objects of classes which define at least one
-virtual function) are sometimes downcast or crosscast. Downcasting means
-casting from a base class to a derived class. Crosscasting means casting
-across an inheritance hierarchy diagram, such as from one base to the other in a
-Y diagram hierarchy.
-Such casts can be done with old-style casts, but this approach is never to be
-recommended. Old-style casts are sorely lacking in type safety, suffer
-poor readability, and are difficult to locate with search tools.
-The C++ built-in static_cast can be used for efficiently downcasting
-pointers to polymorphic objects, but provides no error detection for the case
-where the pointer being cast actually points to the wrong derived class. The polymorphic_downcast
-template retains the efficiency of static_cast for non-debug
-compilations, but for debug compilations adds safety via an assert() that a dynamic_cast
-succeeds.
-The C++ built-in dynamic_cast can be used for downcasts and crosscasts
-of pointers to polymorphic objects, but error notification in the form of a
-returned value of 0 is inconvenient to test, or worse yet, easy to forget to
-test. The polymorphic_cast template performs a dynamic_cast,
-and throws an exception if the dynamic_cast returns 0.
-A polymorphic_downcast is preferred when debug-mode tests will cover
-100% of the object types possibly cast and when non-debug-mode efficiency is an
-issue. If these two conditions are not present, polymorphic_cast is
-preferred. It must also be used for crosscasts. It does an assert(
-dynamic_cast<Derived>(x) == x ) where x is the base pointer, ensuring that
-not only is a non-zero pointer returned, but also that it correct in the
-presence of multiple inheritance. Warning:: Because polymorphic_downcast
-uses assert(), it violates the one definition rule (ODR) if NDEBUG is inconsistently
-defined across translation units. [See ISO Std 3.2]
-The C++ built-in dynamic_cast must be used to cast references rather
-than pointers. It is also the only cast that can be used to check whether
-a given interface is supported; in that case a return of 0 isn't an error
-condition.
-polymorphic_cast and polymorphic_downcast synopsis
-
- namespace boost {
-
-template <class Derived, class Base>
-inline Derived polymorphic_cast(Base* x);
-// Throws: std::bad_cast if ( dynamic_cast<Derived>(x) == 0 )
-// Returns: dynamic_cast<Derived>(x)
-
-template <class Derived, class Base>
-inline Derived polymorphic_downcast(Base* x);
-// Effects: assert( dynamic_cast<Derived>(x) == x );
-// Returns: static_cast<Derived>(x)
-
-}
-
-polymorphic_downcast example
-
- #include <boost/cast.hpp>
-...
-class Fruit { public: virtual ~Fruit(){}; ... };
-class Banana : public Fruit { ... };
-...
-void f( Fruit * fruit ) {
-// ... logic which leads us to believe it is a Banana
- Banana * banana = boost::polymorphic_downcast<Banana*>(fruit);
- ...
-
-
-A static_cast or implicit conversion will not
-detect failure to preserve range for numeric casts. The numeric_cast function
-templates are similar to static_cast and certain (dubious)
-implicit conversions in this respect, except that they detect loss of numeric
-range. An exception is thrown when a runtime value-preservation check fails.
-The requirements on the argument and result types are:
-
-
- - Both argument and result types are CopyConstructible [ISO Std 20.1.3].
- - Both argument and result types are Numeric, defined by
std::numeric_limits<>::is_specialized
- being true.
- - The argument can be converted to the result type using static_cast.
-
-
-numeric_cast synopsis
-
- namespace boost {
-
-class bad_numeric_cast : public std::bad_cast {...};
-
-template<typename Target, typename Source>
- inline Target numeric_cast(Source arg);
- // Throws: bad_numeric_cast unless, in converting arg from Source to Target,
- // there is no loss of negative range, and no underflow, and no
- // overflow, as determined by std::numeric_limits
- // Returns: static_cast<Target>(arg)
-
-}
-
-numeric_cast example
-
- #include <boost/cast.hpp>
-using namespace boost::cast;
-
-void ariane(double vx)
-{
- ...
- unsigned short dx = numeric_cast<unsigned short>(vx);
- ...
-}
-
-numeric_cast rationale
-The form of the throws condition is specified so that != is not a required
-operation.
-History
-polymorphic_cast was suggested by Bjarne Stroustrup in "The C++
-Programming Language".
-polymorphic_downcast was contributed by Dave
-Abrahams.
-numeric_cast was contributed by Kevlin
-Henney.
-
-Revised 06 January, 2001
-© Copyright boost.org 1999. Permission to copy, use, modify, sell and
-distribute this document is granted provided this copyright notice appears in
-all copies. This document is provided "as is" without express or
-implied warranty, and with no claim as to its suitability for any purpose.
-
-
-
-
diff --git a/cast_test.cpp b/cast_test.cpp
deleted file mode 100644
index 091cfe6..0000000
--- a/cast_test.cpp
+++ /dev/null
@@ -1,154 +0,0 @@
-// boost utility cast test program -----------------------------------------//
-
-// (C) Copyright boost.org 1999. Permission to copy, use, modify, sell
-// and distribute this software is granted provided this copyright
-// notice appears in all copies. This software is provided "as is" without
-// express or implied warranty, and with no claim as to its suitability for
-// any purpose.
-
-// See http://www.boost.org for most recent version including documentation.
-
-// Revision History
-// 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
-
-# if SCHAR_MAX == LONG_MAX
-# error "This test program doesn't work if SCHAR_MAX == LONG_MAX"
-# endif
-
-using namespace boost;
-using std::cout;
-
-namespace
-{
- struct Base
- {
- virtual char kind() { return 'B'; }
- };
-
- struct Base2
- {
- virtual char kind2() { return '2'; }
- };
-
- struct Derived : public Base, Base2
- {
- virtual char kind() { return 'D'; }
- };
-}
-
-
-int main( int argc, char * argv[] )
-{
- cout << "Usage: test_casts [n], where n omitted or is:\n"
- " 1 = execute #1 assert failure (#ifndef NDEBUG)\n"
- " 2 = execute #2 assert failure (#ifndef NDEBUG)\n"
- "Example: test_casts 2\n\n";
-
-# ifdef NDEBUG
- cout << "NDEBUG is defined\n";
-# else
- cout << "NDEBUG is not defined\n";
-# endif
-
- cout << "\nBeginning tests...\n";
-
-// test polymorphic_cast ---------------------------------------------------//
-
- // tests which should succeed
- Base * base = new Derived;
- Base2 * base2 = 0;
- Derived * derived = 0;
- derived = polymorphic_downcast( base ); // downcast
- assert( derived->kind() == 'D' );
-
- derived = 0;
- derived = polymorphic_cast( base ); // downcast, throw on error
- assert( derived->kind() == 'D' );
-
- base2 = polymorphic_cast( base ); // crosscast
- assert( base2->kind2() == '2' );
-
- // tests which should result in errors being detected
- int err_count = 0;
- base = new Base;
-
- if ( argc > 1 && *argv[1] == '1' )
- { derived = polymorphic_downcast( base ); } // #1 assert failure
-
- bool caught_exception = false;
- try { derived = polymorphic_cast( 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;
-
-// 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 );
- assert( c == 1 );
- c = 0;
- c = numeric_cast( small_value );
- assert( c == 1 );
- c = 0;
- c = numeric_cast( small_negative_value );
- assert( c == -1 );
-
- // These tests courtesy of Joe R NWP Swatosh
- assert( 0.0f == numeric_cast( 0.0 ) );
- assert( 0.0 == numeric_cast( 0.0 ) );
-
- // tests which should result in errors being detected
-
- caught_exception = false;
- try { c = numeric_cast( large_value ); }
- catch (bad_numeric_cast)
- { cout<<"caught bad_numeric_cast #1\n"; caught_exception = true; }
- if ( !caught_exception ) ++err_count;
-
- caught_exception = false;
- try { c = numeric_cast( large_negative_value ); }
- catch (bad_numeric_cast)
- { cout<<"caught bad_numeric_cast #2\n"; caught_exception = true; }
- if ( !caught_exception ) ++err_count;
-
- 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; }
- if ( !caught_exception ) ++err_count;
-
- caught_exception = false;
- try { ul = numeric_cast( small_negative_value ); }
- catch (bad_numeric_cast)
- { cout<<"caught bad_numeric_cast #4\n"; caught_exception = true; }
- if ( !caught_exception ) ++err_count;
-
- caught_exception = false;
- try { numeric_cast( DBL_MAX ); }
- catch (bad_numeric_cast)
- { cout<<"caught bad_numeric_cast #5\n"; caught_exception = true; }
- if ( !caught_exception ) ++err_count;
-
- cout << err_count << " errors detected\nTest "
- << (err_count==0 ? "passed\n" : "failed\n");
- return err_count;
-} // main
diff --git a/index.htm b/index.htm
deleted file mode 100644
index 079576c..0000000
--- a/index.htm
+++ /dev/null
@@ -1,39 +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, and numeric_cast<> to perform safe casting
- between numeric 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 06 January, 2001
-
-
-
-
-
diff --git a/lexical_cast.htm b/lexical_cast.htm
deleted file mode 100644
index 1215a52..0000000
--- a/lexical_cast.htm
+++ /dev/null
@@ -1,223 +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.
-
-
-
- - 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, 20002003
-
-
diff --git a/lexical_cast_test.cpp b/lexical_cast_test.cpp
deleted file mode 100644
index 9072821..0000000
--- a/lexical_cast_test.cpp
+++ /dev/null
@@ -1,290 +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, 2003.
-//
-// Permission to use, copy, modify, and distribute this software for any
-// purpose is hereby granted without fee, provided that this copyright and
-// permissions notice appear in all copies and derivatives.
-//
-// This software is provided "as is" without express or implied warranty.
-
-#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) || \
- defined(BOOST_NO_INTRINSIC_WCHAR_T)
-#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();
-
-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
- 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), boost::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(""), boost::bad_lexical_cast);
- BOOST_CHECK_THROW(lexical_cast("Test"), boost::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("")), boost::bad_lexical_cast);
- BOOST_CHECK_THROW(
- lexical_cast(std::string("Test")), boost::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'),boost::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), boost::bad_lexical_cast);
-
- BOOST_CHECK_THROW(lexical_cast(1e20), boost::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"), boost::bad_lexical_cast);
- BOOST_CHECK_THROW(lexical_cast(""), boost::bad_lexical_cast);
- BOOST_CHECK_THROW(lexical_cast("Test"), boost::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")), boost::bad_lexical_cast);
- BOOST_CHECK_THROW(
- lexical_cast(std::string("")), boost::bad_lexical_cast);
- BOOST_CHECK_THROW(
- lexical_cast(std::string("Test")), boost::bad_lexical_cast);
-}
-
-void test_conversion_to_double()
-{
- BOOST_CHECK_EQUAL(1.0, lexical_cast('1'));
- BOOST_CHECK_THROW(lexical_cast('A'), boost::bad_lexical_cast);
- BOOST_CHECK_EQUAL(1.0, lexical_cast(1));
- BOOST_CHECK_EQUAL(1.23, lexical_cast(1.23));
- BOOST_CHECK_CLOSE(
- std::numeric_limits::max() / 2,
- lexical_cast(std::numeric_limits::max() / 2),
- std::numeric_limits::epsilon());
- BOOST_CHECK_EQUAL(1.0, lexical_cast(true));
- BOOST_CHECK_EQUAL(0.0, lexical_cast(false));
- BOOST_CHECK_EQUAL(1.23, lexical_cast("1.23"));
- BOOST_CHECK_THROW(lexical_cast(""), boost::bad_lexical_cast);
- BOOST_CHECK_THROW(lexical_cast("Test"), boost::bad_lexical_cast);
- BOOST_CHECK_EQUAL(1.23, lexical_cast(std::string("1.23")));
- BOOST_CHECK_THROW(
- lexical_cast(std::string("")), boost::bad_lexical_cast);
- BOOST_CHECK_THROW(
- lexical_cast(std::string("Test")), boost::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'), boost::bad_lexical_cast);
- BOOST_CHECK_EQUAL(true, lexical_cast(1));
- BOOST_CHECK_EQUAL(false, lexical_cast(0));
- BOOST_CHECK_THROW(lexical_cast(123), boost::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(""), boost::bad_lexical_cast);
- BOOST_CHECK_THROW(lexical_cast("Test"), boost::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("")), boost::bad_lexical_cast);
- BOOST_CHECK_THROW(
- lexical_cast(std::string("Test")), boost::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(123, lexical_cast("123"));
- BOOST_CHECK_EQUAL(123, lexical_cast("123"));
- BOOST_CHECK_EQUAL(123, 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"), boost::bad_lexical_cast);
- #ifndef DISABLE_WIDE_CHAR_SUPPORT
- BOOST_CHECK_THROW(lexical_cast("Test"), boost::bad_lexical_cast);
- #endif
-}
-
-void test_conversion_from_wchar_t()
-{
- #ifndef DISABLE_WIDE_CHAR_SUPPORT
- BOOST_CHECK_EQUAL(1, lexical_cast(L'1'));
- BOOST_CHECK_THROW(lexical_cast(L'A'), boost::bad_lexical_cast);
-
- BOOST_CHECK_EQUAL(123, lexical_cast(L"123"));
- BOOST_CHECK_THROW(lexical_cast(L""), boost::bad_lexical_cast);
- BOOST_CHECK_THROW(lexical_cast(L"Test"), boost::bad_lexical_cast);
-
- BOOST_CHECK_EQUAL(1.0, lexical_cast(L'1'));
- BOOST_CHECK_THROW(lexical_cast(L'A'), boost::bad_lexical_cast);
-
- BOOST_CHECK_EQUAL(1.23, lexical_cast(L"1.23"));
- BOOST_CHECK_THROW(lexical_cast(L""), boost::bad_lexical_cast);
- BOOST_CHECK_THROW(lexical_cast(L"Test"), boost::bad_lexical_cast);
-
- BOOST_CHECK_EQUAL(true, lexical_cast(L'1'));
- BOOST_CHECK_EQUAL(false, lexical_cast(L'0'));
- BOOST_CHECK_THROW(lexical_cast(L'A'), boost::bad_lexical_cast);
- BOOST_CHECK_EQUAL(true, lexical_cast(L"1"));
- BOOST_CHECK_EQUAL(false, lexical_cast(L"0"));
- BOOST_CHECK_THROW(lexical_cast(L""), boost::bad_lexical_cast);
- BOOST_CHECK_THROW(lexical_cast(L"Test"), boost::bad_lexical_cast);
- #endif
-}
-
-void test_conversion_to_wchar_t()
-{
- #ifndef DISABLE_WIDE_CHAR_SUPPORT
- BOOST_CHECK_EQUAL(L'1', lexical_cast(1));
- BOOST_CHECK_EQUAL(L'0', lexical_cast(0));
- BOOST_CHECK_THROW(lexical_cast(123), boost::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""), boost::bad_lexical_cast);
- BOOST_CHECK_THROW(lexical_cast(L"Test"), boost::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"")), boost::bad_lexical_cast);
- BOOST_CHECK_THROW(
- lexical_cast(std::wstring(L"Test")), boost::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"")), boost::bad_lexical_cast);
- BOOST_CHECK_THROW(
- lexical_cast(std::wstring(L"Test")), boost::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"")), boost::bad_lexical_cast);
- BOOST_CHECK_THROW(
- lexical_cast(std::wstring(L"Test")), boost::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));
- BOOST_CHECK(L"A" == lexical_cast(L'A'));
- BOOST_CHECK(L" " == lexical_cast(L' '));
- 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
-}
diff --git a/test.hpp b/test.hpp
deleted file mode 100644
index 42870b9..0000000
--- a/test.hpp
+++ /dev/null
@@ -1,312 +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.
-//
-// Permission to use, copy, modify, and distribute this software for any
-// purpose is hereby granted without fee, provided that this copyright and
-// permissions notice appear in all copies and derivatives, and that no
-// charge may be made for the software and its documentation except to cover
-// cost of distribution.
-//
-// This software is provided "as is" without express or implied warranty.
diff --git a/test/Jamfile b/test/Jamfile
deleted file mode 100644
index 2a274a9..0000000
--- a/test/Jamfile
+++ /dev/null
@@ -1,34 +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
-SEARCH on testing.jam = $(BOOST_BUILD_PATH) ;
-include testing.jam ;
-
-# 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 ]
- ;
-}
-
\ No newline at end of file
diff --git a/test/implicit_cast.cpp b/test/implicit_cast.cpp
deleted file mode 100644
index 39aee56..0000000
--- a/test/implicit_cast.cpp
+++ /dev/null
@@ -1,34 +0,0 @@
-// Copyright David Abrahams 2003. Permission to copy, use,
-// modify, sell and distribute this software is granted provided this
-// copyright notice appears in all copies. This software is provided
-// "as is" without express or implied warranty, and with no claim as
-// to its suitability for any purpose.
-
-#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 9805256..0000000
--- a/test/implicit_cast_fail.cpp
+++ /dev/null
@@ -1,23 +0,0 @@
-// Copyright David Abrahams 2003. Permission to copy, use,
-// modify, sell and distribute this software is granted provided this
-// copyright notice appears in all copies. This software is provided
-// "as is" without express or implied warranty, and with no claim as
-// to its suitability for any purpose.
-
-#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");
-}