From 2688da7c0d6e7da65fecd81b3eb9884cc03027c5 Mon Sep 17 00:00:00 2001 From: nobody Date: Tue, 19 Jun 2007 01:09:15 +0000 Subject: [PATCH] This commit was manufactured by cvs2svn to create tag 'SPIRIT_1_8_5_MINIBOOST'. [SVN r38031] --- cast.htm | 140 ---------------- cast_test.cpp | 91 ---------- include/boost/cast.hpp | 107 ------------ index.html | 38 ----- lexical_cast.htm | 234 -------------------------- lexical_cast_test.cpp | 320 ------------------------------------ numeric_cast_test.cpp | 100 ----------- test.hpp | 308 ---------------------------------- test/Jamfile.v2 | 26 --- test/implicit_cast.cpp | 32 ---- test/implicit_cast_fail.cpp | 22 --- 11 files changed, 1418 deletions(-) delete mode 100644 cast.htm delete mode 100644 cast_test.cpp delete mode 100644 include/boost/cast.hpp delete mode 100644 index.html delete mode 100644 lexical_cast.htm delete mode 100644 lexical_cast_test.cpp delete mode 100644 numeric_cast_test.cpp delete mode 100644 test.hpp delete mode 100644 test/Jamfile.v2 delete mode 100644 test/implicit_cast.cpp delete mode 100644 test/implicit_cast_fail.cpp diff --git a/cast.htm b/cast.htm deleted file mode 100644 index 587d08a..0000000 --- a/cast.htm +++ /dev/null @@ -1,140 +0,0 @@ - - - - - - - - - - Header boost/cast.hpp Documentation - - - -

boost.png (6897 bytes)Header boost/cast.hpp

- -

Cast Functions

- -

The header boost/cast.hpp provides - polymorphic_cast and polymorphic_downcast 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.

- -

Polymorphic casts

- -

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 throwing form of dynamic_cast, which - works on references, can be used on pointers through the ugly expression - &dynamic_cast<T&>(*p), which causes undefined - behavior if p is 0. The polymorphic_cast - template performs a dynamic_cast on a pointer, and throws an - exception if the dynamic_cast returns 0.

- -

A polymorphic_downcast should be used for - downcasts that you are certain should succeed. Error checking is - only performed in translation units where NDEBUG is - not defined, via -

  assert( dynamic_cast<Derived>(x) == x )
-
where x is the source pointer. This approach - ensures that not only is a non-zero pointer returned, but also - that it is correct in the presence of multiple inheritance. - Attempts to crosscast using polymorphic_downcast will - fail to compile. - 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] -

- For crosscasts, or when the success of a cast can only be known at - runtime, or when efficiency is not important, - polymorphic_cast is preferred.

- -

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);
-  ...
-
-
- -

History

- -

polymorphic_cast was suggested by Bjarne Stroustrup in "The C++ - Programming Language".
- polymorphic_downcast was contributed by Dave Abrahams.
- An old - numeric_cast
that was contributed by Kevlin Henney is now superseeded by the Boost Numeric Conversion Library

-
- -

Revised - June 23, 2005

- -

© 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.

- - \ No newline at end of file diff --git a/cast_test.cpp b/cast_test.cpp deleted file mode 100644 index ad6b18f..0000000 --- a/cast_test.cpp +++ /dev/null @@ -1,91 +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 - -# 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[] ) -{ -# 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; - - cout << err_count << " errors detected\nTest " - << (err_count==0 ? "passed\n" : "failed\n"); - return err_count; -} // main diff --git a/include/boost/cast.hpp b/include/boost/cast.hpp deleted file mode 100644 index 2615d18..0000000 --- a/include/boost/cast.hpp +++ /dev/null @@ -1,107 +0,0 @@ -// boost cast.hpp header file ----------------------------------------------// - -// (C) Copyright Kevlin Henney and 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/libs/conversion for Documentation. - -// Revision History -// 23 JUn 05 numeric_cast removed and redirected to the new verion (Fernando Cacciola) -// 02 Apr 01 Removed BOOST_NO_LIMITS workarounds and included -// instead (the workaround did not -// actually compile when BOOST_NO_LIMITS was defined in -// any case, so we loose nothing). (John Maddock) -// 21 Jan 01 Undid a bug I introduced yesterday. numeric_cast<> never -// worked with stock GCC; trying to get it to do that broke -// vc-stlport. -// 20 Jan 01 Moved BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS to config.hpp. -// Removed unused BOOST_EXPLICIT_TARGET macro. Moved -// boost::detail::type to boost/type.hpp. Made it compile with -// stock gcc again (Dave Abrahams) -// 29 Nov 00 Remove nested namespace cast, cleanup spacing before Formal -// Review (Beman Dawes) -// 19 Oct 00 Fix numeric_cast for floating-point types (Dave Abrahams) -// 15 Jul 00 Suppress numeric_cast warnings for GCC, Borland and MSVC -// (Dave Abrahams) -// 30 Jun 00 More MSVC6 wordarounds. See comments below. (Dave Abrahams) -// 28 Jun 00 Removed implicit_cast<>. See comment below. (Beman Dawes) -// 27 Jun 00 More MSVC6 workarounds -// 15 Jun 00 Add workarounds for MSVC6 -// 2 Feb 00 Remove bad_numeric_cast ";" syntax error (Doncho Angelov) -// 26 Jan 00 Add missing throw() to bad_numeric_cast::what(0 (Adam Levar) -// 29 Dec 99 Change using declarations so usages in other namespaces work -// correctly (Dave Abrahams) -// 23 Sep 99 Change polymorphic_downcast assert to also detect M.I. errors -// as suggested Darin Adler and improved by Valentin Bonnard. -// 2 Sep 99 Remove controversial asserts, simplify, rename. -// 30 Aug 99 Move to cast.hpp, replace value_cast with numeric_cast, -// place in nested namespace. -// 3 Aug 99 Initial version - -#ifndef BOOST_CAST_HPP -#define BOOST_CAST_HPP - -# include -# include -# include -# include -# include -# include - -// It has been demonstrated numerous times that MSVC 6.0 fails silently at link -// time if you use a template function which has template parameters that don't -// appear in the function's argument list. -// -// TODO: Add this to config.hpp? -# if defined(BOOST_MSVC) && BOOST_MSVC < 1300 -# define BOOST_EXPLICIT_DEFAULT_TARGET , ::boost::type* = 0 -# else -# define BOOST_EXPLICIT_DEFAULT_TARGET -# endif - -namespace boost -{ -// See the documentation for descriptions of how to choose between -// static_cast<>, dynamic_cast<>, polymorphic_cast<> and polymorphic_downcast<> - -// polymorphic_cast --------------------------------------------------------// - - // Runtime checked polymorphic downcasts and crosscasts. - // Suggested in The C++ Programming Language, 3rd Ed, Bjarne Stroustrup, - // section 15.8 exercise 1, page 425. - - template - inline Target polymorphic_cast(Source* x BOOST_EXPLICIT_DEFAULT_TARGET) - { - Target tmp = dynamic_cast(x); - if ( tmp == 0 ) throw std::bad_cast(); - return tmp; - } - -// polymorphic_downcast ----------------------------------------------------// - - // BOOST_ASSERT() checked polymorphic downcast. Crosscasts prohibited. - - // WARNING: Because this cast uses BOOST_ASSERT(), it violates - // the One Definition Rule if used in multiple translation units - // where BOOST_DISABLE_ASSERTS, BOOST_ENABLE_ASSERT_HANDLER - // NDEBUG are defined inconsistently. - - // Contributed by Dave Abrahams - - template - inline Target polymorphic_downcast(Source* x BOOST_EXPLICIT_DEFAULT_TARGET) - { - BOOST_ASSERT( dynamic_cast(x) == x ); // detect logic error - return static_cast(x); - } - -# undef BOOST_EXPLICIT_DEFAULT_TARGET - -} // namespace boost - -# include - -#endif // BOOST_CAST_HPP 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 949b70c..0000000 --- a/lexical_cast.htm +++ /dev/null @@ -1,234 +0,0 @@ - - - - - lexical_cast - - - - -

boost.png (6897 bytes)Header - boost/lexical_cast.hpp

- -
-

Motivation

- 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. -

-


-

Examples

- 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));
-}
-
-
-
-

Synopsis

- Library features defined in "boost/lexical_cast.hpp": -
-
namespace boost
-{
-    class bad_lexical_cast;
-    template<typename Target, typename Source>
-      Target lexical_cast(const Source& arg);
-}
-
-
Unit test defined in "lexical_cast_test.cpp". -

-


-

lexical_cast

-
-
template<typename Target, typename Source>
-  Target lexical_cast(const 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. -

-


-

bad_lexical_cast

-
-
class bad_lexical_cast : public std::bad_cast
-{
-public:
-    ... // same member function interface as std::exception
-};
-
-
Exception used to indicate runtime lexical_cast - failure. -
- -

Changes

-

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, 2000–2005
- - \ No newline at end of file diff --git a/lexical_cast_test.cpp b/lexical_cast_test.cpp deleted file mode 100644 index 4182942..0000000 --- a/lexical_cast_test.cpp +++ /dev/null @@ -1,320 +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::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.v2 b/test/Jamfile.v2 deleted file mode 100644 index 56a03d8..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 ../../test/build//boost_unit_test_framework/static ] - ; - - diff --git a/test/implicit_cast.cpp b/test/implicit_cast.cpp deleted file mode 100644 index e18e17a..0000000 --- a/test/implicit_cast.cpp +++ /dev/null @@ -1,32 +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)); - BOOST_TEST(boost::implicit_cast(1) == 1L); - - type f = check_return(boost::implicit_cast("hello")); - type z = check_return(boost::implicit_cast(foo("hello"))); - return boost::report_errors(); -} 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"); -}