From 10b80414722376fb8919ad1c150d99159a313327 Mon Sep 17 00:00:00 2001 From: Andrey Semashev Date: Sun, 1 Jun 2014 22:44:30 +0400 Subject: [PATCH] boost::swap, boost::empty_deleter and explicit operator bool macros moved from Boost.Utility to Boost.Core. --- doc/Jamfile.v2 | 19 --- doc/explicit_operator_bool.qbk | 64 -------- doc/html/explicit_operator_bool.html | 115 ------------- include/boost/swap.hpp | 12 -- include/boost/utility/empty_deleter.hpp | 43 ----- .../boost/utility/explicit_operator_bool.hpp | 153 ------------------ include/boost/utility/swap.hpp | 60 ------- index.html | 2 - swap.html | 98 ----------- swap/test/Jamfile.v2 | 37 ----- swap/test/array_of_array_of_class.cpp | 69 -------- swap/test/array_of_array_of_int.cpp | 42 ----- swap/test/array_of_class.cpp | 61 ------- swap/test/array_of_int.cpp | 35 ---- swap/test/array_of_template.cpp | 71 -------- swap/test/lib_header_1.cpp | 10 -- swap/test/lib_header_2.cpp | 11 -- swap/test/mixed_headers_1.cpp | 11 -- swap/test/mixed_headers_2.cpp | 12 -- swap/test/no_ambiguity_in_boost.cpp | 44 ----- swap/test/primitive.cpp | 23 --- swap/test/root_header_1.cpp | 10 -- swap/test/root_header_2.cpp | 11 -- swap/test/specialized_in_boost.cpp | 45 ------ swap/test/specialized_in_boost_and_other.cpp | 64 -------- swap/test/specialized_in_global.cpp | 39 ----- swap/test/specialized_in_other.cpp | 45 ------ swap/test/specialized_in_std.cpp | 44 ----- swap/test/std_bitset.cpp | 33 ---- swap/test/std_dateorder.cpp | 32 ---- swap/test/std_string.cpp | 31 ---- swap/test/std_typeinfo_ptr.cpp | 32 ---- swap/test/std_vector_of_boost.cpp | 60 ------- swap/test/std_vector_of_global.cpp | 53 ------ swap/test/std_vector_of_other.cpp | 60 ------- swap/test/swap_test_class.hpp | 114 ------------- test/Jamfile.v2 | 6 - test/explicit_operator_bool.cpp | 54 ------- ...it_operator_bool_compile_fail_conv_int.cpp | 40 ----- ..._operator_bool_compile_fail_conv_pvoid.cpp | 40 ----- ...icit_operator_bool_compile_fail_delete.cpp | 40 ----- ...licit_operator_bool_compile_fail_shift.cpp | 40 ----- test/explicit_operator_bool_noexcept.cpp | 89 ---------- 43 files changed, 1974 deletions(-) delete mode 100644 doc/explicit_operator_bool.qbk delete mode 100644 doc/html/explicit_operator_bool.html delete mode 100644 include/boost/swap.hpp delete mode 100644 include/boost/utility/empty_deleter.hpp delete mode 100644 include/boost/utility/explicit_operator_bool.hpp delete mode 100644 include/boost/utility/swap.hpp delete mode 100644 swap.html delete mode 100644 swap/test/Jamfile.v2 delete mode 100644 swap/test/array_of_array_of_class.cpp delete mode 100644 swap/test/array_of_array_of_int.cpp delete mode 100644 swap/test/array_of_class.cpp delete mode 100644 swap/test/array_of_int.cpp delete mode 100644 swap/test/array_of_template.cpp delete mode 100644 swap/test/lib_header_1.cpp delete mode 100644 swap/test/lib_header_2.cpp delete mode 100644 swap/test/mixed_headers_1.cpp delete mode 100644 swap/test/mixed_headers_2.cpp delete mode 100644 swap/test/no_ambiguity_in_boost.cpp delete mode 100644 swap/test/primitive.cpp delete mode 100644 swap/test/root_header_1.cpp delete mode 100644 swap/test/root_header_2.cpp delete mode 100644 swap/test/specialized_in_boost.cpp delete mode 100644 swap/test/specialized_in_boost_and_other.cpp delete mode 100644 swap/test/specialized_in_global.cpp delete mode 100644 swap/test/specialized_in_other.cpp delete mode 100644 swap/test/specialized_in_std.cpp delete mode 100644 swap/test/std_bitset.cpp delete mode 100644 swap/test/std_dateorder.cpp delete mode 100644 swap/test/std_string.cpp delete mode 100644 swap/test/std_typeinfo_ptr.cpp delete mode 100644 swap/test/std_vector_of_boost.cpp delete mode 100644 swap/test/std_vector_of_global.cpp delete mode 100644 swap/test/std_vector_of_other.cpp delete mode 100644 swap/test/swap_test_class.hpp delete mode 100644 test/explicit_operator_bool.cpp delete mode 100644 test/explicit_operator_bool_compile_fail_conv_int.cpp delete mode 100644 test/explicit_operator_bool_compile_fail_conv_pvoid.cpp delete mode 100644 test/explicit_operator_bool_compile_fail_delete.cpp delete mode 100644 test/explicit_operator_bool_compile_fail_shift.cpp delete mode 100644 test/explicit_operator_bool_noexcept.cpp diff --git a/doc/Jamfile.v2 b/doc/Jamfile.v2 index a734cb2..3746a82 100644 --- a/doc/Jamfile.v2 +++ b/doc/Jamfile.v2 @@ -79,22 +79,3 @@ boostbook standalone_string_ref # How far down we go with TOC's generate.section.toc.level=1 ; - -xml explicit_operator_bool : explicit_operator_bool.qbk ; -boostbook standalone_explicit_operator_bool - : - explicit_operator_bool - : - # File name of HTML output: - root.filename=explicit_operator_bool - # How far down we chunk nested sections, basically all of them: - chunk.section.depth=0 - # Don't put the first section on the same page as the TOC: - chunk.first.sections=0 - # How far down sections get TOC's - toc.section.depth=1 - # Max depth in each TOC: - toc.max.depth=1 - # How far down we go with TOC's - generate.section.toc.level=1 - ; diff --git a/doc/explicit_operator_bool.qbk b/doc/explicit_operator_bool.qbk deleted file mode 100644 index 64c5be4..0000000 --- a/doc/explicit_operator_bool.qbk +++ /dev/null @@ -1,64 +0,0 @@ -[/ - / Copyright (c) 2013 Andrey Semashev - / - / 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) - /] - -[article BOOST_EXPLICIT_OPERATOR_BOOL, BOOST_EXPLICIT_OPERATOR_BOOL_NOEXCEPT and BOOST_CONSTEXPR_EXPLICIT_OPERATOR_BOOL - [quickbook 1.5] - [authors [Semashev, Andrey]] - [copyright 2013 Andrey Semashev] - [license - 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]) - ] -] - -[/===============] -[section Overview] -[/===============] - -`BOOST_EXPLICIT_OPERATOR_BOOL()`, `BOOST_EXPLICIT_OPERATOR_BOOL_NOEXCEPT()` and `BOOST_CONSTEXPR_EXPLICIT_OPERATOR_BOOL()` are compatibility helper macros that expand to an explicit conversion operator to `bool`. For compilers not supporting explicit conversion operators introduced in C++11 the macros expand to a conversion operator that implements the [@http://en.wikibooks.org/wiki/More_C%2B%2B_Idioms/Safe_bool safe bool idiom]. In case if the compiler is not able to handle safe bool idiom well the macros expand to a regular conversion operator to `bool`. - -[endsect] - - -[/===============] -[section Examples] -[/===============] - -Both macros are intended to be placed within a user's class definition. The generated conversion operators will be implemented in terms of `operator!()` that should be defined by user in this class. In case of `BOOST_CONSTEXPR_EXPLICIT_OPERATOR_BOOL()` the generated conversion operator will be declared `constexpr` which requires the corresponding `operator!()` to also be `constexpr`. - - template< typename T > - class my_ptr - { - T* m_p; - - public: - BOOST_EXPLICIT_OPERATOR_BOOL() - - bool operator!() const - { - return !m_p; - } - }; - -Now `my_ptr` can be used in conditional expressions, similarly to a regular pointer: - - my_ptr< int > p; - if (p) - std::cout << "true" << std::endl; - -[endsect] - -[/===============] -[section History] -[/===============] - -[heading boost 1.55] - -* The macro was extracted from Boost.Log. - -[endsect] diff --git a/doc/html/explicit_operator_bool.html b/doc/html/explicit_operator_bool.html deleted file mode 100644 index 78a844f..0000000 --- a/doc/html/explicit_operator_bool.html +++ /dev/null @@ -1,115 +0,0 @@ - - - -BOOST_EXPLICIT_OPERATOR_BOOL and BOOST_CONSTEXPR_EXPLICIT_OPERATOR_BOOL - - - - - - - - - - - - -
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
-
-
-
-
-
-

-BOOST_EXPLICIT_OPERATOR_BOOL and BOOST_CONSTEXPR_EXPLICIT_OPERATOR_BOOL

-

-Andrey Semashev -

-
-
-

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

-
-
-
-
-
-

Table of Contents

-
-
Overview
-
Examples
-
History
-
-
-
- -

- BOOST_EXPLICIT_OPERATOR_BOOL() and BOOST_CONSTEXPR_EXPLICIT_OPERATOR_BOOL() are compatibility helper macros that expand - to an explicit conversion operator to bool. - For compilers not supporting explicit conversion operators introduced in C++11 - the macros expand to a conversion operator that implements the safe - bool idiom. In case if the compiler is not able to handle safe bool - idiom well the macros expand to a regular conversion operator to bool. -

-
-
- -

- Both macros are intended to be placed within a user's class definition. The - generated conversion operators will be implemented in terms of operator!() - that should be defined by user in this class. In case of BOOST_CONSTEXPR_EXPLICIT_OPERATOR_BOOL() the generated conversion operator will be - declared constexpr which requires - the corresponding operator!() - to also be constexpr. -

-
template< typename T >
-class my_ptr
-{
-    T* m_p;
-
-public:
-    BOOST_EXPLICIT_OPERATOR_BOOL()
-
-    bool operator!() const
-    {
-        return !m_p;
-    }
-};
-
-

- Now my_ptr can be used in conditional - expressions, similarly to a regular pointer: -

-
my_ptr< int > p;
-if (p)
-    std::cout << "true" << std::endl;
-
-
-
- -

- - boost - 1.55 -

-
  • - The macro was extracted from Boost.Log. -
-
-
- - - -

Last revised: November 17, 2013 at 17:08:52 GMT

-
-
- - diff --git a/include/boost/swap.hpp b/include/boost/swap.hpp deleted file mode 100644 index dfc11f0..0000000 --- a/include/boost/swap.hpp +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright (C) 2007 Joseph Gauterin -// -// Distributed under the Boost Software License, Version 1.0. (See -// accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) - -#ifndef BOOST_SWAP_HPP -#define BOOST_SWAP_HPP - -#include "boost/utility/swap.hpp" - -#endif diff --git a/include/boost/utility/empty_deleter.hpp b/include/boost/utility/empty_deleter.hpp deleted file mode 100644 index ba919cd..0000000 --- a/include/boost/utility/empty_deleter.hpp +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright Andrey Semashev 2007 - 2013. - * 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) - */ -/*! - * \file empty_deleter.hpp - * \author Andrey Semashev - * \date 22.04.2007 - * - * This header contains an \c empty_deleter implementation. This is an empty - * function object that receives a pointer and does nothing with it. - * Such empty deletion strategy may be convenient, for example, when - * constructing shared_ptrs that point to some object that should not be - * deleted (i.e. a variable on the stack or some global singleton, like std::cout). - */ - -#ifndef BOOST_UTILITY_EMPTY_DELETER_HPP_INCLUDED_ -#define BOOST_UTILITY_EMPTY_DELETER_HPP_INCLUDED_ - -#include - -#ifdef BOOST_HAS_PRAGMA_ONCE -#pragma once -#endif - -namespace boost { - -//! A function object that does nothing and can be used as an empty deleter for \c shared_ptr -struct empty_deleter -{ - //! Function object result type - typedef void result_type; - /*! - * Does nothing - */ - void operator() (const volatile void*) const BOOST_NOEXCEPT {} -}; - -} // namespace boost - -#endif // BOOST_UTILITY_EMPTY_DELETER_HPP_INCLUDED_ diff --git a/include/boost/utility/explicit_operator_bool.hpp b/include/boost/utility/explicit_operator_bool.hpp deleted file mode 100644 index e16f34d..0000000 --- a/include/boost/utility/explicit_operator_bool.hpp +++ /dev/null @@ -1,153 +0,0 @@ -/* - * Copyright Andrey Semashev 2007 - 2013. - * 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) - */ -/*! - * \file explicit_operator_bool.hpp - * \author Andrey Semashev - * \date 08.03.2009 - * - * This header defines a compatibility macro that implements an unspecified - * \c bool operator idiom, which is superseded with explicit conversion operators in - * C++11. - */ - -#ifndef BOOST_UTILITY_EXPLICIT_OPERATOR_BOOL_HPP_INCLUDED_ -#define BOOST_UTILITY_EXPLICIT_OPERATOR_BOOL_HPP_INCLUDED_ - -#include - -#ifdef BOOST_HAS_PRAGMA_ONCE -#pragma once -#endif - -#if !defined(BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS) - -/*! - * \brief The macro defines an explicit operator of conversion to \c bool - * - * The macro should be used inside the definition of a class that has to - * support the conversion. The class should also implement operator!, - * in terms of which the conversion operator will be implemented. - */ -#define BOOST_EXPLICIT_OPERATOR_BOOL()\ - BOOST_FORCEINLINE explicit operator bool () const\ - {\ - return !this->operator! ();\ - } - -/*! - * \brief The macro defines a noexcept explicit operator of conversion to \c bool - * - * The macro should be used inside the definition of a class that has to - * support the conversion. The class should also implement operator!, - * in terms of which the conversion operator will be implemented. - */ -#define BOOST_EXPLICIT_OPERATOR_BOOL_NOEXCEPT()\ - BOOST_FORCEINLINE explicit operator bool () const BOOST_NOEXCEPT\ - {\ - return !this->operator! ();\ - } - -/*! - * \brief The macro defines a constexpr explicit operator of conversion to \c bool - * - * The macro should be used inside the definition of a class that has to - * support the conversion. The class should also implement operator!, - * in terms of which the conversion operator will be implemented. - */ -#define BOOST_CONSTEXPR_EXPLICIT_OPERATOR_BOOL()\ - BOOST_FORCEINLINE BOOST_CONSTEXPR explicit operator bool () const BOOST_NOEXCEPT\ - {\ - return !this->operator! ();\ - } - -#else // !defined(BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS) - -#if (defined(__SUNPRO_CC) && (__SUNPRO_CC <= 0x530)) && !defined(BOOST_NO_COMPILER_CONFIG) -// Sun C++ 5.3 can't handle the safe_bool idiom, so don't use it -#define BOOST_NO_UNSPECIFIED_BOOL -#endif // (defined(__SUNPRO_CC) && (__SUNPRO_CC <= 0x530)) && !defined(BOOST_NO_COMPILER_CONFIG) - -#if !defined(BOOST_NO_UNSPECIFIED_BOOL) - -namespace boost { - -namespace detail { - -#if !defined(_MSC_VER) && !defined(__IBMCPP__) - - struct unspecified_bool - { - // NOTE TO THE USER: If you see this in error messages then you tried - // to apply an unsupported operator on the object that supports - // explicit conversion to bool. - struct OPERATORS_NOT_ALLOWED; - static void true_value(OPERATORS_NOT_ALLOWED*) {} - }; - typedef void (*unspecified_bool_type)(unspecified_bool::OPERATORS_NOT_ALLOWED*); - -#else - - // MSVC and VACPP are too eager to convert pointer to function to void* even though they shouldn't - struct unspecified_bool - { - // NOTE TO THE USER: If you see this in error messages then you tried - // to apply an unsupported operator on the object that supports - // explicit conversion to bool. - struct OPERATORS_NOT_ALLOWED; - void true_value(OPERATORS_NOT_ALLOWED*) {} - }; - typedef void (unspecified_bool::*unspecified_bool_type)(unspecified_bool::OPERATORS_NOT_ALLOWED*); - -#endif - -} // namespace detail - -} // namespace boost - -#define BOOST_EXPLICIT_OPERATOR_BOOL()\ - BOOST_FORCEINLINE operator boost::detail::unspecified_bool_type () const\ - {\ - return (!this->operator! () ? &boost::detail::unspecified_bool::true_value : (boost::detail::unspecified_bool_type)0);\ - } - -#define BOOST_EXPLICIT_OPERATOR_BOOL_NOEXCEPT()\ - BOOST_FORCEINLINE operator boost::detail::unspecified_bool_type () const BOOST_NOEXCEPT\ - {\ - return (!this->operator! () ? &boost::detail::unspecified_bool::true_value : (boost::detail::unspecified_bool_type)0);\ - } - -#define BOOST_CONSTEXPR_EXPLICIT_OPERATOR_BOOL()\ - BOOST_FORCEINLINE BOOST_CONSTEXPR operator boost::detail::unspecified_bool_type () const BOOST_NOEXCEPT\ - {\ - return (!this->operator! () ? &boost::detail::unspecified_bool::true_value : (boost::detail::unspecified_bool_type)0);\ - } - -#else // !defined(BOOST_NO_UNSPECIFIED_BOOL) - -#define BOOST_EXPLICIT_OPERATOR_BOOL()\ - BOOST_FORCEINLINE operator bool () const\ - {\ - return !this->operator! ();\ - } - -#define BOOST_EXPLICIT_OPERATOR_BOOL()\ - BOOST_FORCEINLINE operator bool () const BOOST_NOEXCEPT\ - {\ - return !this->operator! ();\ - } - -#define BOOST_CONSTEXPR_EXPLICIT_OPERATOR_BOOL()\ - BOOST_FORCEINLINE BOOST_CONSTEXPR operator bool () const BOOST_NOEXCEPT\ - {\ - return !this->operator! ();\ - } - -#endif // !defined(BOOST_NO_UNSPECIFIED_BOOL) - -#endif // !defined(BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS) - -#endif // BOOST_UTILITY_EXPLICIT_OPERATOR_BOOL_HPP_INCLUDED_ diff --git a/include/boost/utility/swap.hpp b/include/boost/utility/swap.hpp deleted file mode 100644 index 5ee6dc1..0000000 --- a/include/boost/utility/swap.hpp +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright (C) 2007, 2008 Steven Watanabe, Joseph Gauterin, Niels Dekker -// -// 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) -// For more information, see http://www.boost.org - - -#ifndef BOOST_UTILITY_SWAP_HPP -#define BOOST_UTILITY_SWAP_HPP - -// Note: the implementation of this utility contains various workarounds: -// - swap_impl is put outside the boost namespace, to avoid infinite -// recursion (causing stack overflow) when swapping objects of a primitive -// type. -// - swap_impl has a using-directive, rather than a using-declaration, -// because some compilers (including MSVC 7.1, Borland 5.9.3, and -// Intel 8.1) don't do argument-dependent lookup when it has a -// using-declaration instead. -// - boost::swap has two template arguments, instead of one, to -// avoid ambiguity when swapping objects of a Boost type that does -// not have its own boost::swap overload. - -#include //for std::swap (C++11) -#include //for std::swap (C++98) -#include //for std::size_t -#include - -namespace boost_swap_impl -{ - template - BOOST_GPU_ENABLED - void swap_impl(T& left, T& right) - { - using namespace std;//use std::swap if argument dependent lookup fails - swap(left,right); - } - - template - BOOST_GPU_ENABLED - void swap_impl(T (& left)[N], T (& right)[N]) - { - for (std::size_t i = 0; i < N; ++i) - { - ::boost_swap_impl::swap_impl(left[i], right[i]); - } - } -} - -namespace boost -{ - template - BOOST_GPU_ENABLED - void swap(T1& left, T2& right) - { - ::boost_swap_impl::swap_impl(left, right); - } -} - -#endif diff --git a/index.html b/index.html index d38b541..f5fe62b 100644 --- a/index.html +++ b/index.html @@ -29,12 +29,10 @@ noncopyable
operators
result_of
- swap
throw_exception
utility
string_ref
value_init
- BOOST_EXPLICIT_OPERATOR_BOOL, BOOST_EXPLICIT_OPERATOR_BOOL_NOEXCEPT and BOOST_CONSTEXPR_EXPLICIT_OPERATOR_BOOL


diff --git a/swap.html b/swap.html deleted file mode 100644 index 36f8425..0000000 --- a/swap.html +++ /dev/null @@ -1,98 +0,0 @@ - - - - - - Boost: Swap Documentation - - - -

- C++ Boost - Header <boost/swap.hpp> -

- -

Swap

- -

- template<class T> void swap(T& left, T& right); -

- - -

- The template function boost::swap allows the values of two variables to be swapped, using argument dependent lookup to select a specialized swap function if available. If no specialized swap function is available, std::swap is used. -

- - -

Rationale

-

- The generic std::swap function requires that the elements to be swapped are assignable and copy constructible. It is usually implemented using one copy construction and two assignments - this is often both unnecessarily restrictive and unnecessarily slow. In addition, where the generic swap implementation provides only the basic guarantee, specialized swap functions are often able to provide the no-throw exception guarantee (and it is considered best practice to do so where possible1).

-

- The alternative to using argument dependent lookup in this situation is to provide a template specialization of std::swap for every type that requires a specialized swap. Although this is legal C++, no Boost libraries use this method, whereas many Boost libraries provide specialized swap functions in their own namespaces. -

-

- boost::swap also supports swapping built-in arrays. Note that std::swap originally did not do so, but a request to add an overload of std::swap for built-in arrays has been accepted by the C++ Standards Committee2. -

- - -

Exception Safety

-

- boost::swap provides the same exception guarantee as the underlying swap function used, with one exception; for an array of type T[n], where n > 1 and the underlying swap function for T provides the strong exception guarantee, boost::swap provides only the basic exception guarantee. -

- - -

Requirements

-

Either:

-
    -
  • T must be assignable
  • -
  • T must be copy constructible
  • -
-

Or:

-
    -
  • A function with the signature swap(T&,T&) is available via argument dependent lookup
  • -
-

Or:

-
    -
  • A template specialization of std::swap exists for T
  • -
-

Or:

-
    -
  • T is a built-in array of swappable elements
  • -
- - - -

Portability

-

- Several older compilers do not support argument dependent lookup ‒ on these compilers boost::swap will call std::swap, ignoring any specialized swap functions that could be found as a result of argument dependent lookup. -

- - -

Credits

-
    -
  • - Niels Dekker - for implementing and documenting support for built-in arrays -
  • -
  • - Joseph Gauterin - for the initial idea, implementation, tests, and documentation -
  • -
  • - Steven Watanabe - for the idea to make boost::swap less specialized than std::swap, thereby allowing the function to have the name 'swap' without introducing ambiguity -
  • -
- - -
-

[1]Scott Meyers, Effective C++ Third Edition, Item 25: "Consider support for a non-throwing swap"

-

[2]LWG Defect Report 809 (std::swap should be overloaded for array types)

- - -
-

Revised: 08 September 2009

-

- Copyright 2007 - 2009 Joseph Gauterin. Use, modification, and distribution are subject to the Boost Software License, Version 1.0. - (See accompanying file LICENSE_1_0.txt or a copy at <http://www.boost.org/LICENSE_1_0.txt>.) -

- - - diff --git a/swap/test/Jamfile.v2 b/swap/test/Jamfile.v2 deleted file mode 100644 index f5b0d46..0000000 --- a/swap/test/Jamfile.v2 +++ /dev/null @@ -1,37 +0,0 @@ -# Copyright (c) 2007, 2008 Joseph Gauterin -# -# 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) - -# bring in rules for testing -import testing ; - -test-suite utility/swap - : - [ compile root_header_1.cpp ] - [ compile root_header_2.cpp ] - [ compile lib_header_1.cpp ] - [ compile lib_header_2.cpp ] - [ compile mixed_headers_1.cpp ] - [ compile mixed_headers_2.cpp ] - [ run primitive.cpp ../../../test/build//boost_test_exec_monitor/static ] - [ run specialized_in_boost.cpp ../../../test/build//boost_test_exec_monitor/static ] - [ run specialized_in_global.cpp ../../../test/build//boost_test_exec_monitor/static ] - [ run specialized_in_other.cpp ../../../test/build//boost_test_exec_monitor/static ] - [ run specialized_in_std.cpp ../../../test/build//boost_test_exec_monitor/static ] - [ run specialized_in_boost_and_other.cpp ../../../test/build//boost_test_exec_monitor/static ] - [ run std_bitset.cpp ../../../test/build//boost_test_exec_monitor/static ] - [ run std_dateorder.cpp ../../../test/build//boost_test_exec_monitor/static ] - [ run std_string.cpp ../../../test/build//boost_test_exec_monitor/static ] - [ run std_typeinfo_ptr.cpp ../../../test/build//boost_test_exec_monitor/static ] - [ run std_vector_of_boost.cpp ../../../test/build//boost_test_exec_monitor/static ] - [ run std_vector_of_global.cpp ../../../test/build//boost_test_exec_monitor/static ] - [ run std_vector_of_other.cpp ../../../test/build//boost_test_exec_monitor/static ] - [ run no_ambiguity_in_boost.cpp ../../../test/build//boost_test_exec_monitor/static ] - [ run array_of_array_of_class.cpp ../../../test/build//boost_test_exec_monitor/static ] - [ run array_of_array_of_int.cpp ../../../test/build//boost_test_exec_monitor/static ] - [ run array_of_class.cpp ../../../test/build//boost_test_exec_monitor/static ] - [ run array_of_int.cpp ../../../test/build//boost_test_exec_monitor/static ] - [ run array_of_template.cpp ../../../test/build//boost_test_exec_monitor/static ] - ; diff --git a/swap/test/array_of_array_of_class.cpp b/swap/test/array_of_array_of_class.cpp deleted file mode 100644 index 4f02578..0000000 --- a/swap/test/array_of_array_of_class.cpp +++ /dev/null @@ -1,69 +0,0 @@ -// Copyright (c) 2008 Joseph Gauterin, Niels Dekker -// -// 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) - -// Tests swapping an array of arrays of swap_test_class objects by means of boost::swap. - -#include -#define BOOST_INCLUDE_MAIN -#include - -//Put test class in the global namespace -#include "./swap_test_class.hpp" - -#include //for std::copy and std::equal -#include //for std::size_t - -//Provide swap function in both the namespace of swap_test_class -//(which is the global namespace), and the std namespace. -//It's common to provide a swap function for a class in both -//namespaces. Scott Meyers recommends doing so: Effective C++, -//Third Edition, item 25, "Consider support for a non-throwing swap". -void swap(swap_test_class& left, swap_test_class& right) -{ - left.swap(right); -} - -namespace std -{ - template <> - void swap(swap_test_class& left, swap_test_class& right) - { - left.swap(right); - } -} - - -int test_main(int, char*[]) -{ - const std::size_t first_dimension = 3; - const std::size_t second_dimension = 4; - const std::size_t number_of_elements = first_dimension * second_dimension; - - swap_test_class array1[first_dimension][second_dimension]; - swap_test_class array2[first_dimension][second_dimension]; - - swap_test_class* const ptr1 = array1[0]; - swap_test_class* const ptr2 = array2[0]; - - for (std::size_t i = 0; i < number_of_elements; ++i) - { - ptr1[i].set_data( static_cast(i) ); - ptr2[i].set_data( static_cast(i + number_of_elements) ); - } - - boost::swap(array1, array2); - - for (std::size_t i = 0; i < number_of_elements; ++i) - { - BOOST_CHECK_EQUAL(ptr1[i].get_data(), static_cast(i + number_of_elements) ); - BOOST_CHECK_EQUAL(ptr2[i].get_data(), static_cast(i) ); - } - - BOOST_CHECK_EQUAL(swap_test_class::swap_count(), number_of_elements); - BOOST_CHECK_EQUAL(swap_test_class::copy_count(), 0); - - return 0; -} diff --git a/swap/test/array_of_array_of_int.cpp b/swap/test/array_of_array_of_int.cpp deleted file mode 100644 index c1778ec..0000000 --- a/swap/test/array_of_array_of_int.cpp +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright (c) 2008 Joseph Gauterin, Niels Dekker -// -// 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) - -// Tests swapping an array of arrays of integers by means of boost::swap. - -#include -#define BOOST_INCLUDE_MAIN -#include - -#include //for std::copy and std::equal -#include //for std::size_t - -int test_main(int, char*[]) -{ - const std::size_t first_dimension = 3; - const std::size_t second_dimension = 4; - const std::size_t number_of_elements = first_dimension * second_dimension; - - int array1[first_dimension][second_dimension]; - int array2[first_dimension][second_dimension]; - - int* const ptr1 = array1[0]; - int* const ptr2 = array2[0]; - - for (std::size_t i = 0; i < number_of_elements; ++i) - { - ptr1[i] = static_cast(i); - ptr2[i] = static_cast(i + number_of_elements); - } - - boost::swap(array1, array2); - - for (std::size_t i = 0; i < number_of_elements; ++i) - { - BOOST_CHECK_EQUAL(ptr1[i], static_cast(i + number_of_elements) ); - BOOST_CHECK_EQUAL(ptr2[i], static_cast(i) ); - } - return 0; -} diff --git a/swap/test/array_of_class.cpp b/swap/test/array_of_class.cpp deleted file mode 100644 index 356762d..0000000 --- a/swap/test/array_of_class.cpp +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright (c) 2008 Joseph Gauterin, Niels Dekker -// -// 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) - -// Tests swapping an array of arrays of swap_test_class objects by means of boost::swap. - -#include -#define BOOST_INCLUDE_MAIN -#include - -//Put test class in the global namespace -#include "./swap_test_class.hpp" - -#include //for std::copy and std::equal -#include //for std::size_t - -//Provide swap function in both the namespace of swap_test_class -//(which is the global namespace), and the std namespace. -//It's common to provide a swap function for a class in both -//namespaces. Scott Meyers recommends doing so: Effective C++, -//Third Edition, item 25, "Consider support for a non-throwing swap". -void swap(swap_test_class& left, swap_test_class& right) -{ - left.swap(right); -} - -namespace std -{ - template <> - void swap(swap_test_class& left, swap_test_class& right) - { - left.swap(right); - } -} - - -int test_main(int, char*[]) -{ - const std::size_t array_size = 2; - const swap_test_class initial_array1[array_size] = { swap_test_class(1), swap_test_class(2) }; - const swap_test_class initial_array2[array_size] = { swap_test_class(3), swap_test_class(4) }; - - swap_test_class array1[array_size]; - swap_test_class array2[array_size]; - - std::copy(initial_array1, initial_array1 + array_size, array1); - std::copy(initial_array2, initial_array2 + array_size, array2); - - swap_test_class::reset(); - boost::swap(array1, array2); - - BOOST_CHECK(std::equal(array1, array1 + array_size, initial_array2)); - BOOST_CHECK(std::equal(array2, array2 + array_size, initial_array1)); - - BOOST_CHECK_EQUAL(swap_test_class::swap_count(), array_size); - BOOST_CHECK_EQUAL(swap_test_class::copy_count(), 0); - - return 0; -} diff --git a/swap/test/array_of_int.cpp b/swap/test/array_of_int.cpp deleted file mode 100644 index 22a7dde..0000000 --- a/swap/test/array_of_int.cpp +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright (c) 2008 Joseph Gauterin, Niels Dekker -// -// 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) - -// Tests swapping an array of integers by means of boost::swap. - -#include -#define BOOST_INCLUDE_MAIN -#include - -#include //for std::copy and std::equal -#include //for std::size_t - - -int test_main(int, char*[]) -{ - const std::size_t array_size = 3; - const int initial_array1[array_size] = { 1, 2, 3 }; - const int initial_array2[array_size] = { 4, 5, 6 }; - - int array1[array_size]; - int array2[array_size]; - - std::copy(initial_array1, initial_array1 + array_size, array1); - std::copy(initial_array2, initial_array2 + array_size, array2); - - boost::swap(array1, array2); - - BOOST_CHECK(std::equal(array1, array1 + array_size, initial_array2)); - BOOST_CHECK(std::equal(array2, array2 + array_size, initial_array1)); - - return 0; -} diff --git a/swap/test/array_of_template.cpp b/swap/test/array_of_template.cpp deleted file mode 100644 index 8f350ad..0000000 --- a/swap/test/array_of_template.cpp +++ /dev/null @@ -1,71 +0,0 @@ -// Copyright (c) 2008 Joseph Gauterin, Niels Dekker -// -// 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) - -// Tests swapping an array of swap_test_template objects by means of boost::swap. - -#include -#define BOOST_INCLUDE_MAIN -#include - -//Put test class in the global namespace -#include "./swap_test_class.hpp" - -#include //for std::copy and std::equal -#include //for std::size_t - -template -class swap_test_template -{ -public: - typedef T template_argument; - swap_test_class swap_test_object; -}; - -template -inline bool operator==(const swap_test_template & lhs, const swap_test_template & rhs) -{ - return lhs.swap_test_object == rhs.swap_test_object; -} - -template -inline bool operator!=(const swap_test_template & lhs, const swap_test_template & rhs) -{ - return !(lhs == rhs); -} - -//Provide swap function in the namespace of swap_test_template -//(which is the global namespace). Note that it isn't allowed to put -//an overload of this function within the std namespace. -template -void swap(swap_test_template& left, swap_test_template& right) -{ - left.swap_test_object.swap(right.swap_test_object); -} - - -int test_main(int, char*[]) -{ - const std::size_t array_size = 2; - const swap_test_template initial_array1[array_size] = { swap_test_class(1), swap_test_class(2) }; - const swap_test_template initial_array2[array_size] = { swap_test_class(3), swap_test_class(4) }; - - swap_test_template array1[array_size]; - swap_test_template array2[array_size]; - - std::copy(initial_array1, initial_array1 + array_size, array1); - std::copy(initial_array2, initial_array2 + array_size, array2); - - swap_test_class::reset(); - boost::swap(array1, array2); - - BOOST_CHECK(std::equal(array1, array1 + array_size, initial_array2)); - BOOST_CHECK(std::equal(array2, array2 + array_size, initial_array1)); - - BOOST_CHECK_EQUAL(swap_test_class::swap_count(), array_size); - BOOST_CHECK_EQUAL(swap_test_class::copy_count(), 0); - - return 0; -} diff --git a/swap/test/lib_header_1.cpp b/swap/test/lib_header_1.cpp deleted file mode 100644 index 923dea6..0000000 --- a/swap/test/lib_header_1.cpp +++ /dev/null @@ -1,10 +0,0 @@ -// Copyright (c) 2007 Joseph Gauterin -// -// 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) - -// Tests that the swap header compiles as a standalone translation unit - -#include - diff --git a/swap/test/lib_header_2.cpp b/swap/test/lib_header_2.cpp deleted file mode 100644 index e88909d..0000000 --- a/swap/test/lib_header_2.cpp +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright (c) 2007 Joseph Gauterin -// -// 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) - -// Tests that the swap header include guards work correctly - -#include -#include - diff --git a/swap/test/mixed_headers_1.cpp b/swap/test/mixed_headers_1.cpp deleted file mode 100644 index cdb9fe5..0000000 --- a/swap/test/mixed_headers_1.cpp +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright (c) 2007 Joseph Gauterin -// -// 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) - -// Tests that the swap headers work when both are included - -#include -#include - diff --git a/swap/test/mixed_headers_2.cpp b/swap/test/mixed_headers_2.cpp deleted file mode 100644 index 94e9d87..0000000 --- a/swap/test/mixed_headers_2.cpp +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright (c) 2007 Joseph Gauterin -// -// 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) - -// Tests that the swap headers work when both are included - -#include -#include - - diff --git a/swap/test/no_ambiguity_in_boost.cpp b/swap/test/no_ambiguity_in_boost.cpp deleted file mode 100644 index e269252..0000000 --- a/swap/test/no_ambiguity_in_boost.cpp +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright (c) 2008 Joseph Gauterin, Niels Dekker -// -// 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) - -// boost::swap internally does an unqualified function call to swap. -// This could have led to ambiguity or infinite recursion, when the -// objects to be swapped would themselves be from the boost namespace. -// If so, boost::swap itself might be found by argument dependent lookup. -// The implementation of boost::swap resolves this issue by giving -// boost::swap two template argumetns, thereby making it less specialized -// than std::swap. - -#include -#define BOOST_INCLUDE_MAIN -#include - -//Put test class in namespace boost -namespace boost -{ - #include "./swap_test_class.hpp" -} - - -int test_main(int, char*[]) -{ - const boost::swap_test_class initial_value1(1); - const boost::swap_test_class initial_value2(2); - - boost::swap_test_class object1 = initial_value1; - boost::swap_test_class object2 = initial_value2; - - boost::swap_test_class::reset(); - boost::swap(object1,object2); - - BOOST_CHECK(object1 == initial_value2); - BOOST_CHECK(object2 == initial_value1); - BOOST_CHECK_EQUAL(boost::swap_test_class::swap_count(),0); - BOOST_CHECK_EQUAL(boost::swap_test_class::copy_count(),3); - - return 0; -} - diff --git a/swap/test/primitive.cpp b/swap/test/primitive.cpp deleted file mode 100644 index 380edb3..0000000 --- a/swap/test/primitive.cpp +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright (c) 2007 Joseph Gauterin -// -// 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 -#define BOOST_INCLUDE_MAIN -#include - -int test_main(int, char*[]) -{ - int object1 = 1; - int object2 = 2; - - boost::swap(object1,object2); - - BOOST_CHECK_EQUAL(object1,2); - BOOST_CHECK_EQUAL(object2,1); - - return 0; -} - diff --git a/swap/test/root_header_1.cpp b/swap/test/root_header_1.cpp deleted file mode 100644 index 575d2cb..0000000 --- a/swap/test/root_header_1.cpp +++ /dev/null @@ -1,10 +0,0 @@ -// Copyright (c) 2007 Joseph Gauterin -// -// 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) - -// Tests that the swap header compiles as a standalone translation unit - -#include - diff --git a/swap/test/root_header_2.cpp b/swap/test/root_header_2.cpp deleted file mode 100644 index d26b3a6..0000000 --- a/swap/test/root_header_2.cpp +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright (c) 2007 Joseph Gauterin -// -// 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) - -// Tests that the swap header include guards work correctly - -#include -#include - diff --git a/swap/test/specialized_in_boost.cpp b/swap/test/specialized_in_boost.cpp deleted file mode 100644 index 7b3e12e..0000000 --- a/swap/test/specialized_in_boost.cpp +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright (c) 2007 Joseph Gauterin -// -// 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 -#define BOOST_INCLUDE_MAIN -#include - -//Put test class in namespace boost -namespace boost -{ - #include "./swap_test_class.hpp" -} - -//Provide swap function in namespace boost -namespace boost -{ - void swap(swap_test_class& left, swap_test_class& right) - { - left.swap(right); - } -} - -int test_main(int, char*[]) -{ - const boost::swap_test_class initial_value1(1); - const boost::swap_test_class initial_value2(2); - - boost::swap_test_class object1 = initial_value1; - boost::swap_test_class object2 = initial_value2; - - boost::swap_test_class::reset(); - boost::swap(object1,object2); - - BOOST_CHECK(object1 == initial_value2); - BOOST_CHECK(object2 == initial_value1); - - BOOST_CHECK_EQUAL(boost::swap_test_class::swap_count(),1); - BOOST_CHECK_EQUAL(boost::swap_test_class::copy_count(),0); - - return 0; -} - diff --git a/swap/test/specialized_in_boost_and_other.cpp b/swap/test/specialized_in_boost_and_other.cpp deleted file mode 100644 index ba6247f..0000000 --- a/swap/test/specialized_in_boost_and_other.cpp +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright (c) 2008 Joseph Gauterin, Niels Dekker -// -// 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) - -// Tests whether instances of a class from a namespace other than boost are -// properly swapped, when both boost and the other namespace have a custom -// swap function for that class. Note that it shouldn't be necessary for a class -// in an other namespace to have a custom swap function in boost, because the -// boost::swap utility should find the swap function in the other namespace, by -// argument dependent lookup (ADL). Unfortunately ADL isn't fully implemented -// by some specific compiler versions, including Intel C++ 8.1, MSVC 7.1, and -// Borland 5.9.3. Users of those compilers might consider adding a swap overload -// to the boost namespace. - -#include -#define BOOST_INCLUDE_MAIN -#include - -//Put test class in namespace other -namespace other -{ - #include "./swap_test_class.hpp" -} - -//Provide swap function in namespace boost -namespace boost -{ - void swap(::other::swap_test_class& left, ::other::swap_test_class& right) - { - left.swap(right); - } -} - -//Provide swap function in namespace other -namespace other -{ - void swap(swap_test_class& left, swap_test_class& right) - { - left.swap(right); - } -} - -int test_main(int, char*[]) -{ - const other::swap_test_class initial_value1(1); - const other::swap_test_class initial_value2(2); - - other::swap_test_class object1 = initial_value1; - other::swap_test_class object2 = initial_value2; - - other::swap_test_class::reset(); - boost::swap(object1,object2); - - BOOST_CHECK(object1 == initial_value2); - BOOST_CHECK(object2 == initial_value1); - - BOOST_CHECK_EQUAL(other::swap_test_class::swap_count(),1); - BOOST_CHECK_EQUAL(other::swap_test_class::copy_count(),0); - - return 0; -} - diff --git a/swap/test/specialized_in_global.cpp b/swap/test/specialized_in_global.cpp deleted file mode 100644 index 0a0a029..0000000 --- a/swap/test/specialized_in_global.cpp +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright (c) 2007 Joseph Gauterin -// -// 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 -#define BOOST_INCLUDE_MAIN -#include - -//Put test class in the global namespace -#include "./swap_test_class.hpp" - -//Provide swap function in gloabl namespace -void swap(swap_test_class& left, swap_test_class& right) -{ - left.swap(right); -} - -int test_main(int, char*[]) -{ - const swap_test_class initial_value1(1); - const swap_test_class initial_value2(2); - - swap_test_class object1 = initial_value1; - swap_test_class object2 = initial_value2; - - swap_test_class::reset(); - boost::swap(object1,object2); - - BOOST_CHECK(object1 == initial_value2); - BOOST_CHECK(object2 == initial_value1); - - BOOST_CHECK_EQUAL(swap_test_class::swap_count(),1); - BOOST_CHECK_EQUAL(swap_test_class::copy_count(),0); - - return 0; -} - diff --git a/swap/test/specialized_in_other.cpp b/swap/test/specialized_in_other.cpp deleted file mode 100644 index a39896f..0000000 --- a/swap/test/specialized_in_other.cpp +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright (c) 2007 Joseph Gauterin -// -// 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 -#define BOOST_INCLUDE_MAIN -#include - -//Put test class in namespace other -namespace other -{ - #include "./swap_test_class.hpp" -} - -//Provide swap function in namespace other -namespace other -{ - void swap(swap_test_class& left, swap_test_class& right) - { - left.swap(right); - } -} - -int test_main(int, char*[]) -{ - const other::swap_test_class initial_value1(1); - const other::swap_test_class initial_value2(2); - - other::swap_test_class object1 = initial_value1; - other::swap_test_class object2 = initial_value2; - - other::swap_test_class::reset(); - boost::swap(object1,object2); - - BOOST_CHECK(object1 == initial_value2); - BOOST_CHECK(object2 == initial_value1); - - BOOST_CHECK_EQUAL(other::swap_test_class::swap_count(),1); - BOOST_CHECK_EQUAL(other::swap_test_class::copy_count(),0); - - return 0; -} - diff --git a/swap/test/specialized_in_std.cpp b/swap/test/specialized_in_std.cpp deleted file mode 100644 index e31e850..0000000 --- a/swap/test/specialized_in_std.cpp +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright (c) 2007 Joseph Gauterin -// -// 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 -#define BOOST_INCLUDE_MAIN -#include - -//Put test class in the global namespace -#include "./swap_test_class.hpp" - - -//Provide swap function in namespace std -namespace std -{ - template <> - void swap(swap_test_class& left, swap_test_class& right) - { - left.swap(right); - } -} - -int test_main(int, char*[]) -{ - const swap_test_class initial_value1(1); - const swap_test_class initial_value2(2); - - swap_test_class object1 = initial_value1; - swap_test_class object2 = initial_value2; - - swap_test_class::reset(); - boost::swap(object1,object2); - - BOOST_CHECK(object1 == initial_value2); - BOOST_CHECK(object2 == initial_value1); - - BOOST_CHECK_EQUAL(swap_test_class::swap_count(),1); - BOOST_CHECK_EQUAL(swap_test_class::copy_count(),0); - - return 0; -} - diff --git a/swap/test/std_bitset.cpp b/swap/test/std_bitset.cpp deleted file mode 100644 index c46b686..0000000 --- a/swap/test/std_bitset.cpp +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright (c) 2008 - 2010 Joseph Gauterin, Niels Dekker -// -// 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) - -// Tests swapping std::bitset objects by means of boost::swap. -// Unlike most other Standard C++ Library template classes, -// std::bitset does not have its own std::swap overload. - -#include -#define BOOST_INCLUDE_MAIN -#include - -#include - -int test_main(int, char*[]) -{ - typedef std::bitset<8> bitset_type; - const bitset_type initial_value1 = 1; - const bitset_type initial_value2 = 2; - - bitset_type object1 = initial_value1; - bitset_type object2 = initial_value2; - - boost::swap(object1,object2); - - BOOST_CHECK_EQUAL(object1,initial_value2); - BOOST_CHECK_EQUAL(object2,initial_value1); - - return 0; -} - diff --git a/swap/test/std_dateorder.cpp b/swap/test/std_dateorder.cpp deleted file mode 100644 index b593f6f..0000000 --- a/swap/test/std_dateorder.cpp +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (c) 2008 Joseph Gauterin, Niels Dekker -// -// 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) - -// Tests swapping std::time_base::dateorder objects by means of boost::swap. -// std::time_base::dateorder is an enumerated type. It does not have an -// std::swap overload or template specialization. - -#include -#define BOOST_INCLUDE_MAIN -#include - -#include - -int test_main(int, char*[]) -{ - const std::time_base::dateorder initial_value1 = std::time_base::dmy; - const std::time_base::dateorder initial_value2 = std::time_base::mdy; - - std::time_base::dateorder object1 = initial_value1; - std::time_base::dateorder object2 = initial_value2; - - boost::swap(object1,object2); - - BOOST_CHECK_EQUAL(object1,initial_value2); - BOOST_CHECK_EQUAL(object2,initial_value1); - - return 0; -} - diff --git a/swap/test/std_string.cpp b/swap/test/std_string.cpp deleted file mode 100644 index b7d3d4d..0000000 --- a/swap/test/std_string.cpp +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright (c) 2008 Joseph Gauterin, Niels Dekker -// -// 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) - -// Tests swapping std::string objects by means of boost::swap. -// std::string has its own std::swap overload. - -#include -#define BOOST_INCLUDE_MAIN -#include - -#include - -int test_main(int, char*[]) -{ - const std::string initial_value1 = "one"; - const std::string initial_value2 = "two"; - - std::string object1 = initial_value1; - std::string object2 = initial_value2; - - boost::swap(object1,object2); - - BOOST_CHECK_EQUAL(object1,initial_value2); - BOOST_CHECK_EQUAL(object2,initial_value1); - - return 0; -} - diff --git a/swap/test/std_typeinfo_ptr.cpp b/swap/test/std_typeinfo_ptr.cpp deleted file mode 100644 index 38e293a..0000000 --- a/swap/test/std_typeinfo_ptr.cpp +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (c) 2008 Joseph Gauterin, Niels Dekker -// -// 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) - -// Tests swapping std::type_info pointers by means of boost::swap. -// There is no std::swap overload or template specialization -// for std::type_info pointers. - -#include -#define BOOST_INCLUDE_MAIN -#include - -#include - -int test_main(int, char*[]) -{ - const std::type_info * const initial_value1 = 0; - const std::type_info * const initial_value2 = &typeid(double); - - const std::type_info * ptr1 = initial_value1; - const std::type_info * ptr2 = initial_value2; - - boost::swap(ptr1,ptr2); - - BOOST_CHECK_EQUAL(ptr1,initial_value2); - BOOST_CHECK_EQUAL(ptr2,initial_value1); - - return 0; -} - diff --git a/swap/test/std_vector_of_boost.cpp b/swap/test/std_vector_of_boost.cpp deleted file mode 100644 index b0c6355..0000000 --- a/swap/test/std_vector_of_boost.cpp +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright (c) 2008 Joseph Gauterin, Niels Dekker -// -// 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) - -// Tests swapping std::vector objects by means of boost::swap, -// having boost::swap_test_class as vector element type. - -#include -#define BOOST_INCLUDE_MAIN -#include - -#include - -//Put test class in namespace boost -namespace boost -{ - #include "./swap_test_class.hpp" -} - -//Provide swap function in namespace boost -namespace boost -{ - void swap(swap_test_class& left, swap_test_class& right) - { - left.swap(right); - } -} - -int test_main(int, char*[]) -{ - typedef boost::swap_test_class swap_test_class_type; - typedef std::vector vector_type; - - const vector_type::size_type initial_size1 = 1; - const vector_type::size_type initial_size2 = 2; - - const vector_type initial_value1(initial_size1, swap_test_class_type(1)); - const vector_type initial_value2(initial_size2, swap_test_class_type(2)); - - vector_type object1 = initial_value1; - vector_type object2 = initial_value2; - - swap_test_class_type::reset(); - - boost::swap(object1,object2); - - BOOST_CHECK_EQUAL(object1.size(),initial_size2); - BOOST_CHECK_EQUAL(object2.size(),initial_size1); - - BOOST_CHECK(object1 == initial_value2); - BOOST_CHECK(object2 == initial_value1); - - BOOST_CHECK_EQUAL(swap_test_class_type::swap_count(),0); - BOOST_CHECK_EQUAL(swap_test_class_type::copy_count(),0); - - return 0; -} - diff --git a/swap/test/std_vector_of_global.cpp b/swap/test/std_vector_of_global.cpp deleted file mode 100644 index 96a9b6a..0000000 --- a/swap/test/std_vector_of_global.cpp +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright (c) 2008 Joseph Gauterin, Niels Dekker -// -// 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) - -// Tests swapping std::vector objects by means of boost::swap, -// having ::swap_test_class as vector element type. - -#include -#define BOOST_INCLUDE_MAIN -#include - -#include - -//Put test class in the global namespace -#include "./swap_test_class.hpp" - -//Provide swap function in the global namespace -void swap(swap_test_class& left, swap_test_class& right) -{ - left.swap(right); -} - -int test_main(int, char*[]) -{ - typedef std::vector vector_type; - - const vector_type::size_type initial_size1 = 1; - const vector_type::size_type initial_size2 = 2; - - const vector_type initial_value1(initial_size1, swap_test_class(1)); - const vector_type initial_value2(initial_size2, swap_test_class(2)); - - vector_type object1 = initial_value1; - vector_type object2 = initial_value2; - - swap_test_class::reset(); - - boost::swap(object1,object2); - - BOOST_CHECK_EQUAL(object1.size(),initial_size2); - BOOST_CHECK_EQUAL(object2.size(),initial_size1); - - BOOST_CHECK(object1 == initial_value2); - BOOST_CHECK(object2 == initial_value1); - - BOOST_CHECK_EQUAL(swap_test_class::swap_count(),0); - BOOST_CHECK_EQUAL(swap_test_class::copy_count(),0); - - return 0; -} - diff --git a/swap/test/std_vector_of_other.cpp b/swap/test/std_vector_of_other.cpp deleted file mode 100644 index 2176f6e..0000000 --- a/swap/test/std_vector_of_other.cpp +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright (c) 2008 Joseph Gauterin, Niels Dekker -// -// 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) - -// Tests swapping std::vector objects by means of boost::swap, -// having other::swap_test_class as vector element type. - -#include -#define BOOST_INCLUDE_MAIN -#include - -#include - -//Put test class in namespace other -namespace other -{ - #include "./swap_test_class.hpp" -} - -//Provide swap function in namespace other -namespace other -{ - void swap(swap_test_class& left, swap_test_class& right) - { - left.swap(right); - } -} - -int test_main(int, char*[]) -{ - typedef other::swap_test_class swap_test_class_type; - typedef std::vector vector_type; - - const vector_type::size_type initial_size1 = 1; - const vector_type::size_type initial_size2 = 2; - - const vector_type initial_value1(initial_size1, swap_test_class_type(1)); - const vector_type initial_value2(initial_size2, swap_test_class_type(2)); - - vector_type object1 = initial_value1; - vector_type object2 = initial_value2; - - swap_test_class_type::reset(); - - boost::swap(object1,object2); - - BOOST_CHECK_EQUAL(object1.size(),initial_size2); - BOOST_CHECK_EQUAL(object2.size(),initial_size1); - - BOOST_CHECK(object1 == initial_value2); - BOOST_CHECK(object2 == initial_value1); - - BOOST_CHECK_EQUAL(swap_test_class_type::swap_count(),0); - BOOST_CHECK_EQUAL(swap_test_class_type::copy_count(),0); - - return 0; -} - diff --git a/swap/test/swap_test_class.hpp b/swap/test/swap_test_class.hpp deleted file mode 100644 index a25dbbd..0000000 --- a/swap/test/swap_test_class.hpp +++ /dev/null @@ -1,114 +0,0 @@ -// Copyright (c) 2007-2008 Joseph Gauterin -// -// 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) - -// Tests class used by the Boost.Swap tests - -#ifndef BOOST_UTILITY_SWAP_TEST_CLASS_HPP -#define BOOST_UTILITY_SWAP_TEST_CLASS_HPP - - -class swap_test_class -{ - int m_data; -public: - explicit swap_test_class(int arg = 0) - : - m_data(arg) - { - ++constructCount(); - } - - ~swap_test_class() - { - ++destructCount(); - } - - swap_test_class(const swap_test_class& arg) - : - m_data(arg.m_data) - { - ++copyCount(); - ++destructCount(); - } - - swap_test_class& operator=(const swap_test_class& arg) - { - m_data = arg.m_data; - ++copyCount(); - return *this; - } - - void swap(swap_test_class& other) - { - const int temp = m_data; - m_data = other.m_data; - other.m_data = temp; - - ++swapCount(); - } - - int get_data() const - { - return m_data; - } - - void set_data(int arg) - { - m_data = arg; - } - - static unsigned int swap_count(){ return swapCount(); } - static unsigned int copy_count(){ return copyCount(); } - static unsigned int construct_count(){ return constructCount(); } - static unsigned int destruct_count(){ return destructCount(); } - - static void reset() - { - swapCount() = 0; - copyCount() = 0; - constructCount() = 0; - destructCount() = 0; - } - -private: - static unsigned int& swapCount() - { - static unsigned int value = 0; - return value; - } - - static unsigned int& copyCount() - { - static unsigned int value = 0; - return value; - } - - static unsigned int& constructCount() - { - static unsigned int value = 0; - return value; - } - - static unsigned int& destructCount() - { - static unsigned int value = 0; - return value; - } - -}; - - -inline bool operator==(const swap_test_class & lhs, const swap_test_class & rhs) -{ - return lhs.get_data() == rhs.get_data(); -} - -inline bool operator!=(const swap_test_class & lhs, const swap_test_class & rhs) -{ - return !(lhs == rhs); -} - -#endif diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 3ca12c8..cedc25e 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -45,11 +45,5 @@ test-suite utility [ compile-fail ../value_init_test_fail3.cpp ] [ compile-fail ../initialized_test_fail1.cpp ] [ compile-fail ../initialized_test_fail2.cpp ] - [ run explicit_operator_bool.cpp ] - [ run explicit_operator_bool_noexcept.cpp ] - [ compile-fail explicit_operator_bool_compile_fail_conv_int.cpp ] - [ compile-fail explicit_operator_bool_compile_fail_conv_pvoid.cpp ] - [ compile-fail explicit_operator_bool_compile_fail_delete.cpp ] - [ compile-fail explicit_operator_bool_compile_fail_shift.cpp ] ; diff --git a/test/explicit_operator_bool.cpp b/test/explicit_operator_bool.cpp deleted file mode 100644 index 5e85259..0000000 --- a/test/explicit_operator_bool.cpp +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright Andrey Semashev 2007 - 2013. - * 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) - */ -/*! - * \file explicit_operator_bool.cpp - * \author Andrey Semashev - * \date 17.07.2010 - * - * \brief This test checks that explicit operator bool can be used in - * the valid contexts. - */ - -#define BOOST_TEST_MODULE explicit_operator_bool - -#include - -namespace { - - // A test object that has the operator of explicit conversion to bool - struct checkable1 - { - BOOST_EXPLICIT_OPERATOR_BOOL() - bool operator! () const - { - return false; - } - }; - - struct checkable2 - { - BOOST_CONSTEXPR_EXPLICIT_OPERATOR_BOOL() - BOOST_CONSTEXPR bool operator! () const - { - return false; - } - }; - -} // namespace - -int main(int, char*[]) -{ - checkable1 val1; - if (val1) - { - checkable2 val2; - if (val2) - return 0; - } - - return 1; -} diff --git a/test/explicit_operator_bool_compile_fail_conv_int.cpp b/test/explicit_operator_bool_compile_fail_conv_int.cpp deleted file mode 100644 index 384f2ab..0000000 --- a/test/explicit_operator_bool_compile_fail_conv_int.cpp +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright Andrey Semashev 2007 - 2013. - * 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) - */ -/*! - * \file explicit_operator_bool_compile_fail_conv_int.cpp - * \author Andrey Semashev - * \date 17.07.2010 - * - * \brief This test checks that explicit operator bool cannot be used in - * an unintended context. - */ - -#define BOOST_TEST_MODULE explicit_operator_bool_compile_fail_conv_int - -#include - -namespace { - - // A test object that has the operator of explicit conversion to bool - struct checkable - { - BOOST_EXPLICIT_OPERATOR_BOOL() - bool operator! () const - { - return false; - } - }; - -} // namespace - -int main(int, char*[]) -{ - checkable val; - int n = val; - - return 0; -} diff --git a/test/explicit_operator_bool_compile_fail_conv_pvoid.cpp b/test/explicit_operator_bool_compile_fail_conv_pvoid.cpp deleted file mode 100644 index 0c007ba..0000000 --- a/test/explicit_operator_bool_compile_fail_conv_pvoid.cpp +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright Andrey Semashev 2007 - 2013. - * 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) - */ -/*! - * \file explicit_operator_bool_compile_fail_conv_pvoid.cpp - * \author Andrey Semashev - * \date 17.07.2010 - * - * \brief This test checks that explicit operator bool cannot be used in - * an unintended context. - */ - -#define BOOST_TEST_MODULE explicit_operator_bool_compile_fail_conv_pvoid - -#include - -namespace { - - // A test object that has the operator of explicit conversion to bool - struct checkable - { - BOOST_EXPLICIT_OPERATOR_BOOL() - bool operator! () const - { - return false; - } - }; - -} // namespace - -int main(int, char*[]) -{ - checkable val; - void* p = val; - - return 0; -} diff --git a/test/explicit_operator_bool_compile_fail_delete.cpp b/test/explicit_operator_bool_compile_fail_delete.cpp deleted file mode 100644 index d780f94..0000000 --- a/test/explicit_operator_bool_compile_fail_delete.cpp +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright Andrey Semashev 2007 - 2013. - * 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) - */ -/*! - * \file explicit_operator_bool_compile_fail_delete.cpp - * \author Andrey Semashev - * \date 17.07.2010 - * - * \brief This test checks that explicit operator bool cannot be used in - * an unintended context. - */ - -#define BOOST_TEST_MODULE util_explicit_operator_bool_delete - -#include - -namespace { - - // A test object that has the operator of explicit conversion to bool - struct checkable - { - BOOST_EXPLICIT_OPERATOR_BOOL() - bool operator! () const - { - return false; - } - }; - -} // namespace - -int main(int, char*[]) -{ - checkable val; - delete val; - - return 0; -} diff --git a/test/explicit_operator_bool_compile_fail_shift.cpp b/test/explicit_operator_bool_compile_fail_shift.cpp deleted file mode 100644 index ce563a6..0000000 --- a/test/explicit_operator_bool_compile_fail_shift.cpp +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright Andrey Semashev 2007 - 2013. - * 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) - */ -/*! - * \file explicit_operator_bool_compile_fail_shift.cpp - * \author Andrey Semashev - * \date 17.07.2010 - * - * \brief This test checks that explicit operator bool cannot be used in - * an unintended context. - */ - -#define BOOST_TEST_MODULE explicit_operator_bool_compile_fail_shift - -#include - -namespace { - - // A test object that has the operator of explicit conversion to bool - struct checkable - { - BOOST_EXPLICIT_OPERATOR_BOOL() - bool operator! () const - { - return false; - } - }; - -} // namespace - -int main(int, char*[]) -{ - checkable val; - val << 2; - - return 0; -} diff --git a/test/explicit_operator_bool_noexcept.cpp b/test/explicit_operator_bool_noexcept.cpp deleted file mode 100644 index c645cca..0000000 --- a/test/explicit_operator_bool_noexcept.cpp +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright Andrey Semashev 2007 - 2013. - * 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) - */ -/*! - * \file explicit_operator_bool_noexcept.cpp - * \author Andrey Semashev - * \date 26.04.2014 - * - * \brief This test checks that explicit operator bool is noexcept when possible. - */ - -#define BOOST_TEST_MODULE explicit_operator_bool_noexcept - -#include - -#if !defined(BOOST_NO_CXX11_NOEXCEPT) - -#include -#include - -namespace { - - struct checkable1 - { - BOOST_EXPLICIT_OPERATOR_BOOL() - bool operator! () const - { - return false; - } - }; - - struct checkable2 - { - BOOST_CONSTEXPR_EXPLICIT_OPERATOR_BOOL() - BOOST_CONSTEXPR bool operator! () const - { - return false; - } - }; - - struct noexcept_checkable1 - { - BOOST_EXPLICIT_OPERATOR_BOOL_NOEXCEPT() - bool operator! () const noexcept - { - return false; - } - }; - - struct noexcept_checkable2 - { - BOOST_CONSTEXPR_EXPLICIT_OPERATOR_BOOL() - BOOST_CONSTEXPR bool operator! () const noexcept - { - return false; - } - }; - -} // namespace - -int main(int, char*[]) -{ - checkable1 val1; - checkable2 val2; - - noexcept_checkable1 noexcept_val1; - noexcept_checkable2 noexcept_val2; - - BOOST_TEST(!noexcept(static_cast< bool >(val1))); - // constexpr functions are implicitly noexcept - BOOST_TEST(noexcept(static_cast< bool >(val2))); - - BOOST_TEST(noexcept(static_cast< bool >(noexcept_val1))); - BOOST_TEST(noexcept(static_cast< bool >(noexcept_val2))); - - return boost::report_errors(); -} - -#else - -int main(int, char*[]) -{ - return 0; -} - -#endif