From 5ef6819e942c1bff5047257e935764c169d0ba17 Mon Sep 17 00:00:00 2001 From: Beman Dawes Date: Tue, 22 May 2001 18:58:21 +0000 Subject: [PATCH 001/144] Smart pointer and utility changes related to adding checked_delere and checked_array_delete [SVN r10189] --- checked_delete_test.cpp | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 checked_delete_test.cpp diff --git a/checked_delete_test.cpp b/checked_delete_test.cpp new file mode 100644 index 0000000..f9107c8 --- /dev/null +++ b/checked_delete_test.cpp @@ -0,0 +1,31 @@ +// Boost checked_delete test program ---------------------------------------// + +// (C) Copyright Beman Dawes 2001. Permission to copy, use, modify, sell +// and distribute this software is granted provided this copyright +// notice appears in all copies. This software is provided "as is" without +// express or implied warranty, and with no claim as to its suitability for +// any purpose. + +// See http://www.boost.org for most recent version including documentation. + +// Revision History +// 21 May 01 Initial version (Beman Dawes) + +#include // for checked_delete + +// This program demonstrates compiler errors when trying to delete an +// incomplete type. + +namespace +{ + class Incomplete; +} + +int main() +{ + Incomplete * p; + boost::checked_delete(p); // should cause compile time error + Incomplete ** pa; + boost::checked_array_delete(pa); // should cause compile time error + return 0; +} // main From 490e273e25e5733a4329524c92e74f9674ed1732 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Thu, 23 Aug 2001 18:42:16 +0000 Subject: [PATCH 002/144] initial commit [SVN r10914] --- include/boost/ref.hpp | 55 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 include/boost/ref.hpp diff --git a/include/boost/ref.hpp b/include/boost/ref.hpp new file mode 100644 index 0000000..f8ab454 --- /dev/null +++ b/include/boost/ref.hpp @@ -0,0 +1,55 @@ +#ifndef BOOST_REF_HPP_INCLUDED +#define BOOST_REF_HPP_INCLUDED + +#if _MSC_VER >= 1020 +#pragma once +#endif + +// +// ref.hpp - ref/cref, useful helper functions +// +// Version 1.00.0003 (2001-08-22) +// +// Copyright (C) 1999, 2000 Jaakko Järvi (jaakko.jarvi@cs.utu.fi) +// +// Permission to copy, use, modify, sell and distribute this software +// is granted provided this copyright notice appears in all copies. +// This software is provided "as is" without express or implied +// warranty, and with no claim as to its suitability for any purpose. +// +// See http://www.boost.org/libs/bind/ref.html for documentation. +// + +namespace boost +{ + +template class reference_wrapper +{ +public: + + explicit reference_wrapper(T & t): t_(t) {} + + operator T & () const { return t_; } + + T & get() const { return t_; } + +private: + + T & t_; + + reference_wrapper & operator= (reference_wrapper const &); +}; + +template inline reference_wrapper ref(T & t) +{ + return reference_wrapper(t); +} + +template inline reference_wrapper cref(T const & t) +{ + return reference_wrapper(t); +} + +} // namespace boost + +#endif // #ifndef BOOST_REF_HPP_INCLUDED From 145ba3ab104366769b45610e331b5ff49a35c6eb Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Thu, 23 Aug 2001 19:05:21 +0000 Subject: [PATCH 003/144] Tabs converted to spaces. [SVN r10916] --- include/boost/ref.hpp | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/include/boost/ref.hpp b/include/boost/ref.hpp index f8ab454..39ce4e3 100644 --- a/include/boost/ref.hpp +++ b/include/boost/ref.hpp @@ -6,18 +6,18 @@ #endif // -// ref.hpp - ref/cref, useful helper functions +// ref.hpp - ref/cref, useful helper functions // -// Version 1.00.0003 (2001-08-22) +// Version 1.00.0003 (2001-08-22) // -// Copyright (C) 1999, 2000 Jaakko Järvi (jaakko.jarvi@cs.utu.fi) +// Copyright (C) 1999, 2000 Jaakko Järvi (jaakko.jarvi@cs.utu.fi) // -// Permission to copy, use, modify, sell and distribute this software -// is granted provided this copyright notice appears in all copies. -// This software is provided "as is" without express or implied -// warranty, and with no claim as to its suitability for any purpose. +// Permission to copy, use, modify, sell and distribute this software +// is granted provided this copyright notice appears in all copies. +// This software is provided "as is" without express or implied +// warranty, and with no claim as to its suitability for any purpose. // -// See http://www.boost.org/libs/bind/ref.html for documentation. +// See http://www.boost.org/libs/bind/ref.html for documentation. // namespace boost @@ -27,27 +27,27 @@ template class reference_wrapper { public: - explicit reference_wrapper(T & t): t_(t) {} + explicit reference_wrapper(T & t): t_(t) {} - operator T & () const { return t_; } + operator T & () const { return t_; } - T & get() const { return t_; } + T & get() const { return t_; } private: - T & t_; + T & t_; - reference_wrapper & operator= (reference_wrapper const &); + reference_wrapper & operator= (reference_wrapper const &); }; template inline reference_wrapper ref(T & t) { - return reference_wrapper(t); + return reference_wrapper(t); } template inline reference_wrapper cref(T const & t) { - return reference_wrapper(t); + return reference_wrapper(t); } } // namespace boost From 5ba2af4fe2a68fc2fba152ea697dbdb314fdc58e Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Sat, 10 Nov 2001 19:18:58 +0000 Subject: [PATCH 004/144] __stdcall support added. [SVN r11649] --- include/boost/ref.hpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/include/boost/ref.hpp b/include/boost/ref.hpp index 39ce4e3..b35fb0f 100644 --- a/include/boost/ref.hpp +++ b/include/boost/ref.hpp @@ -1,16 +1,15 @@ #ifndef BOOST_REF_HPP_INCLUDED #define BOOST_REF_HPP_INCLUDED -#if _MSC_VER >= 1020 +#if _MSC_VER+0 >= 1020 #pragma once #endif // // ref.hpp - ref/cref, useful helper functions // -// Version 1.00.0003 (2001-08-22) -// // Copyright (C) 1999, 2000 Jaakko Järvi (jaakko.jarvi@cs.utu.fi) +// Copyright (C) 2001 Peter Dimov // // Permission to copy, use, modify, sell and distribute this software // is granted provided this copyright notice appears in all copies. From e40de0d57743f0d33a8a543fefd6b27726d3e503 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Tue, 13 Nov 2001 13:56:05 +0000 Subject: [PATCH 005/144] Fixed a bug w/ adaptable function objects + nested binds, made ref<> return const [SVN r11670] --- include/boost/ref.hpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/include/boost/ref.hpp b/include/boost/ref.hpp index b35fb0f..29f8930 100644 --- a/include/boost/ref.hpp +++ b/include/boost/ref.hpp @@ -39,12 +39,18 @@ private: reference_wrapper & operator= (reference_wrapper const &); }; -template inline reference_wrapper ref(T & t) +#if defined(__BORLANDC__) && (__BORLANDC__ <= 0x551) +#define BOOST_REF_CONST +#else +#define BOOST_REF_CONST const +#endif + +template inline reference_wrapper BOOST_REF_CONST ref(T & t) { return reference_wrapper(t); } -template inline reference_wrapper cref(T const & t) +template inline reference_wrapper BOOST_REF_CONST cref(T const & t) { return reference_wrapper(t); } From b5723e23871aaabe21a44cb2cb2dca14a330c4ed Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Wed, 14 Nov 2001 14:40:29 +0000 Subject: [PATCH 006/144] #undef BOOST_REF_CONST added [SVN r11674] --- include/boost/ref.hpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/boost/ref.hpp b/include/boost/ref.hpp index 29f8930..8ba1cfe 100644 --- a/include/boost/ref.hpp +++ b/include/boost/ref.hpp @@ -55,6 +55,8 @@ template inline reference_wrapper BOOST_REF_CONST cref(T const return reference_wrapper(t); } +#undef BOOST_REF_CONST + } // namespace boost #endif // #ifndef BOOST_REF_HPP_INCLUDED From 36df1db1bbb78d7cbf8ea1ed0b499862fc59c89a Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Tue, 22 Jan 2002 13:38:52 +0000 Subject: [PATCH 007/144] Smart pointer enhancements, initial commit [SVN r12439] --- include/boost/checked_delete.hpp | 73 ++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 include/boost/checked_delete.hpp diff --git a/include/boost/checked_delete.hpp b/include/boost/checked_delete.hpp new file mode 100644 index 0000000..ad11d58 --- /dev/null +++ b/include/boost/checked_delete.hpp @@ -0,0 +1,73 @@ +#ifndef BOOST_CHECKED_DELETE_HPP_INCLUDED +#define BOOST_CHECKED_DELETE_HPP_INCLUDED + +#if _MSC_VER >= 1020 +#pragma once +#endif + +// +// boost/checked_delete.hpp +// +// Copyright (c) 1999, 2000, 2001, 2002 boost.org +// +// Permission to copy, use, modify, sell and distribute this software +// is granted provided this copyright notice appears in all copies. +// This software is provided "as is" without express or implied +// warranty, and with no claim as to its suitability for any purpose. +// + +namespace boost +{ + +// verify that types are complete for increased safety + +template< typename T > inline void checked_delete(T * x) +{ + typedef char type_must_be_complete[sizeof(T)]; + delete x; +} + +template< typename T > inline void checked_array_delete(T * x) +{ + typedef char type_must_be_complete[sizeof(T)]; + delete [] x; +} + +template struct checked_deleter +{ + typedef void result_type; + typedef T * argument_type; + + void operator()(T * x) + { + checked_delete(x); + } +}; + +// checked_deleter is needed by shared_ptr::reset(0) + +template<> struct checked_deleter +{ + typedef void result_type; + typedef void * argument_type; + + void operator()(void * x) + { + ::operator delete(x); // avoid g++ warning + } +}; + +template struct checked_array_deleter +{ + typedef void result_type; + typedef T * argument_type; + + void operator()(T * x) + { + checked_array_delete(x); + } +}; + +} // namespace boost + +#endif // #ifndef BOOST_CHECKED_DELETE_HPP_INCLUDED From 9885682c0743ba502d38e3d861b780863fef65be Mon Sep 17 00:00:00 2001 From: Dave Abrahams Date: Wed, 23 Jan 2002 21:19:14 +0000 Subject: [PATCH 008/144] added is_reference_wrapper<>, unwrap_reference<> [SVN r12470] --- include/boost/ref.hpp | 101 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 91 insertions(+), 10 deletions(-) diff --git a/include/boost/ref.hpp b/include/boost/ref.hpp index 8ba1cfe..b6b4704 100644 --- a/include/boost/ref.hpp +++ b/include/boost/ref.hpp @@ -1,9 +1,9 @@ #ifndef BOOST_REF_HPP_INCLUDED -#define BOOST_REF_HPP_INCLUDED +# define BOOST_REF_HPP_INCLUDED -#if _MSC_VER+0 >= 1020 -#pragma once -#endif +# if _MSC_VER+0 >= 1020 +# pragma once +# endif // // ref.hpp - ref/cref, useful helper functions @@ -25,6 +25,7 @@ namespace boost template class reference_wrapper { public: + typedef T type; explicit reference_wrapper(T & t): t_(t) {} @@ -39,11 +40,11 @@ private: reference_wrapper & operator= (reference_wrapper const &); }; -#if defined(__BORLANDC__) && (__BORLANDC__ <= 0x551) -#define BOOST_REF_CONST -#else -#define BOOST_REF_CONST const -#endif +# if defined(__BORLANDC__) && (__BORLANDC__ <= 0x551) +# define BOOST_REF_CONST +# else +# define BOOST_REF_CONST const +# endif template inline reference_wrapper BOOST_REF_CONST ref(T & t) { @@ -55,7 +56,87 @@ template inline reference_wrapper BOOST_REF_CONST cref(T const return reference_wrapper(t); } -#undef BOOST_REF_CONST +# undef BOOST_REF_CONST + +# ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION +template +class is_reference_wrapper +{ + public: + BOOST_STATIC_CONSTANT(bool, value = false); +}; + +template +class is_reference_wrapper > +{ + public: + BOOST_STATIC_CONSTANT(bool, value = true); +}; + +template +class unwrap_reference +{ + public: + typedef T type; +}; + +template +class unwrap_reference > +{ + public: + typedef T type; +}; +# else // no partial specialization +namespace detail +{ + typedef char (&yes_reference_wrapper_t)[1]; + typedef char (&no_reference_wrapper_t)[2]; + + no_reference_wrapper_t is_reference_wrapper_test(...); + + template + yes_reference_wrapper_t is_reference_wrapper_test(reference_wrapper*); + + template + struct reference_unwrapper + { + template + struct apply + { + typedef T type; + }; + }; + + template<> + struct reference_unwrapper + { + template + struct apply + { + typedef typename T::type type; + }; + }; +} + +template +class is_reference_wrapper +{ + public: + static T* t; + BOOST_STATIC_CONSTANT( + bool, value = ( + sizeof(detail::is_reference_wrapper_test(t)) + == sizeof(detail::yes_reference_wrapper_t))); +}; + +template +class unwrap_reference + : public detail::reference_unwrapper< + is_reference_wrapper::value + >::template apply +{}; + +# endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION } // namespace boost From 9d15e6ae468ebd016f9412b3449dd0951f43a0f8 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Thu, 24 Jan 2002 13:28:08 +0000 Subject: [PATCH 009/144] Modified is_reference_wrapper<> to work for reference types. [SVN r12475] --- include/boost/ref.hpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/include/boost/ref.hpp b/include/boost/ref.hpp index b6b4704..a13558b 100644 --- a/include/boost/ref.hpp +++ b/include/boost/ref.hpp @@ -87,6 +87,14 @@ class unwrap_reference > typedef T type; }; # else // no partial specialization + +} // namespace boost + +#include + +namespace boost +{ + namespace detail { typedef char (&yes_reference_wrapper_t)[1]; @@ -95,7 +103,7 @@ namespace detail no_reference_wrapper_t is_reference_wrapper_test(...); template - yes_reference_wrapper_t is_reference_wrapper_test(reference_wrapper*); + yes_reference_wrapper_t is_reference_wrapper_test(type< reference_wrapper >); template struct reference_unwrapper @@ -122,10 +130,9 @@ template class is_reference_wrapper { public: - static T* t; BOOST_STATIC_CONSTANT( bool, value = ( - sizeof(detail::is_reference_wrapper_test(t)) + sizeof(detail::is_reference_wrapper_test(type())) == sizeof(detail::yes_reference_wrapper_t))); }; From 4c161bfe04352dbfa19951f2087f6a1c13941d20 Mon Sep 17 00:00:00 2001 From: Dave Abrahams Date: Thu, 24 Jan 2002 16:52:06 +0000 Subject: [PATCH 010/144] initial checkin [SVN r12481] --- ref_test.cpp | 124 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 124 insertions(+) create mode 100644 ref_test.cpp diff --git a/ref_test.cpp b/ref_test.cpp new file mode 100644 index 0000000..24f9e98 --- /dev/null +++ b/ref_test.cpp @@ -0,0 +1,124 @@ +#if defined(_MSC_VER) && !defined(__ICL) +# pragma warning(disable: 4786) // identifier truncated in debug info +# pragma warning(disable: 4710) // function not inlined +# pragma warning(disable: 4711) // function selected for automatic inline expansion +# pragma warning(disable: 4514) // unreferenced inline removed +#endif + +#include +#include +#include + +#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300) +# pragma warning(push, 3) +#endif + +#include + +#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300) +# pragma warning(pop) +#endif + + +#define BOOST_INCLUDE_MAIN +#include + +namespace { +using namespace boost; + +template +struct wrapper +{ + // Used to verify implicit conversion + static T* get_pointer(T& x) + { + return &x; + } + + static T const* get_const_pointer(T const& x) + { + return &x; + } + + static void check_type_typedef(...) + { + BOOST_ERROR("expected a reference_wrapper argument"); + } + + template + static void check_type_typedef(boost::reference_wrapper) + { + typedef typename boost::reference_wrapper::type type_typedef; + BOOST_TEST((boost::is_same::value)); + } + + template + static T* passthru(Arg x) + { + check_type_typedef(x); + return get_pointer(x); + } + + template + static T const* cref_passthru(Arg x) + { + check_type_typedef(x); + return get_const_pointer(x); + } + + template + static void test_unwrapped(Arg x) + { + typedef typename unwrap_reference::type unwrapped; + BOOST_TEST((is_same::value)); + } + + template struct select {}; + typedef select constant; + typedef select non_constant; + + static void cref_test(T x, constant) {} + + static void cref_test(T x, non_constant) + { + BOOST_TEST(is_reference_wrapper >::value); + BOOST_TEST(cref_passthru(cref(x)) == &x); + BOOST_TEST(&cref(x).get() == &x); + } + + BOOST_STATIC_CONSTANT( + bool, t_is_constant = boost::is_const::value); + + static void test(T x) + { + BOOST_TEST(passthru(ref(x)) == &x); + + BOOST_TEST((is_same::type,T>::value)); + + BOOST_TEST(&ref(x).get() == &x); + + typedef reference_wrapper wrapped; + BOOST_TEST(is_reference_wrapper::value); + + typedef typename unwrap_reference::type unwrapped_wrapper; + BOOST_TEST((is_same::value)); + + typedef typename unwrap_reference::type unwrapped_self; + BOOST_TEST((is_same::value)); + + cref_test(x, select()); + } +}; + +} // namespace unnamed + +int test_main(int, char * []) +{ + wrapper::test(1); + wrapper::test(1); + BOOST_TEST(!is_reference_wrapper::value); + BOOST_TEST(!is_reference_wrapper::value); + BOOST_TEST(!is_reference_wrapper::value); + BOOST_TEST(!is_reference_wrapper::value); + return 0; +} From 924c81eedd07c5dc65f755c119dabca0c6f749ab Mon Sep 17 00:00:00 2001 From: Dave Abrahams Date: Thu, 24 Jan 2002 16:55:41 +0000 Subject: [PATCH 011/144] added missing #include of boost/config.hpp [SVN r12483] --- include/boost/ref.hpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/boost/ref.hpp b/include/boost/ref.hpp index a13558b..ff5394c 100644 --- a/include/boost/ref.hpp +++ b/include/boost/ref.hpp @@ -5,6 +5,8 @@ # pragma once # endif +# include + // // ref.hpp - ref/cref, useful helper functions // From e5dd8109bfe8b57983a862309a8dddbb0b38a8a6 Mon Sep 17 00:00:00 2001 From: Aleksey Gurtovoy Date: Sun, 27 Jan 2002 13:02:27 +0000 Subject: [PATCH 012/144] made 'reference_wrapper' Assignable [SVN r12520] --- include/boost/ref.hpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/include/boost/ref.hpp b/include/boost/ref.hpp index ff5394c..cf85e64 100644 --- a/include/boost/ref.hpp +++ b/include/boost/ref.hpp @@ -29,17 +29,15 @@ template class reference_wrapper public: typedef T type; - explicit reference_wrapper(T & t): t_(t) {} + explicit reference_wrapper(T& t): t_(&t) {} - operator T & () const { return t_; } + operator T& () const { return *t_; } - T & get() const { return t_; } + T& get() const { return *t_; } private: - T & t_; - - reference_wrapper & operator= (reference_wrapper const &); + T* t_; }; # if defined(__BORLANDC__) && (__BORLANDC__ <= 0x551) From 21ab86e031dee10a26b9c0d4247835c1d7b53ac2 Mon Sep 17 00:00:00 2001 From: Aleksey Gurtovoy Date: Sun, 27 Jan 2002 13:07:20 +0000 Subject: [PATCH 013/144] compile-time ref.hpp header test, initial checkin [SVN r12522] --- ref_ct_test.cpp | 128 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 128 insertions(+) create mode 100644 ref_ct_test.cpp diff --git a/ref_ct_test.cpp b/ref_ct_test.cpp new file mode 100644 index 0000000..97fecc3 --- /dev/null +++ b/ref_ct_test.cpp @@ -0,0 +1,128 @@ +//----------------------------------------------------------------------------- +// ref_ct_test.cpp - compile-time test for "boost/ref.hpp" header content +// See http://www.boost.org for updates, documentation, and revision history. +//----------------------------------------------------------------------------- +// +// Copyright (c) 2002 +// Aleksey Gurtovoy +// +// Permission to use, copy, modify, distribute and sell this software +// and its documentation for any purpose is hereby granted without fee, +// provided that the above copyright notice appears in all copies and +// that both the copyright notice and this permission notice appear in +// supporting documentation. No representations are made about the +// suitability of this software for any purpose. It is provided "as is" +// without express or implied warranty. + +#include +#include +#include + +namespace { + +template< typename T, typename U > +void ref_test(boost::reference_wrapper) +{ + typedef typename boost::reference_wrapper::type type; + BOOST_STATIC_ASSERT((boost::is_same::value)); + BOOST_STATIC_ASSERT((boost::is_same::value)); +} + +template< typename T > +void assignable_test(T x) +{ + x = x; +} + +template< bool R, typename T > +void is_reference_wrapper_test(T) +{ + BOOST_STATIC_ASSERT(boost::is_reference_wrapper::value == R); +} + +template< typename R, typename Ref > +void cxx_reference_test(Ref) +{ + BOOST_STATIC_ASSERT((boost::is_same::value)); +} + +template< typename R, typename Ref > +void unwrap_reference_test(Ref) +{ + typedef typename boost::unwrap_reference::type type; + BOOST_STATIC_ASSERT((boost::is_same::value)); +} + +} // namespace + +int main() +{ + int i = 0; + int& ri = i; + + int const ci = 0; + int const& rci = ci; + + // 'ref/cref' functions test + ref_test(boost::ref(i)); + ref_test(boost::ref(ri)); + ref_test(boost::ref(ci)); + ref_test(boost::ref(rci)); + + ref_test(boost::cref(i)); + ref_test(boost::cref(ri)); + ref_test(boost::cref(ci)); + ref_test(boost::cref(rci)); + + // test 'assignable' requirement + assignable_test(boost::ref(i)); + assignable_test(boost::ref(ri)); + assignable_test(boost::cref(i)); + assignable_test(boost::cref(ci)); + assignable_test(boost::cref(rci)); + + // 'is_reference_wrapper' test + is_reference_wrapper_test(boost::ref(i)); + is_reference_wrapper_test(boost::ref(ri)); + is_reference_wrapper_test(boost::cref(i)); + is_reference_wrapper_test(boost::cref(ci)); + is_reference_wrapper_test(boost::cref(rci)); + + is_reference_wrapper_test(i); + is_reference_wrapper_test(ri); + is_reference_wrapper_test(ci); + is_reference_wrapper_test(rci); + + // ordinary references/function template arguments deduction test + cxx_reference_test(i); + cxx_reference_test(ri); + cxx_reference_test(ci); + cxx_reference_test(rci); + + cxx_reference_test(i); + cxx_reference_test(ri); + cxx_reference_test(i); + cxx_reference_test(ri); + cxx_reference_test(ci); + cxx_reference_test(rci); + + // 'unwrap_reference' test + unwrap_reference_test(boost::ref(i)); + unwrap_reference_test(boost::ref(ri)); + unwrap_reference_test(boost::cref(i)); + unwrap_reference_test(boost::cref(ci)); + unwrap_reference_test(boost::cref(rci)); + + unwrap_reference_test(i); + unwrap_reference_test(ri); + unwrap_reference_test(ci); + unwrap_reference_test(rci); + unwrap_reference_test(i); + unwrap_reference_test(ri); + unwrap_reference_test(i); + unwrap_reference_test(ri); + unwrap_reference_test(ci); + unwrap_reference_test(rci); + + return 0; +} From 0b4618d2a6ca5148bae8aaf698a6df7a5afadc0f Mon Sep 17 00:00:00 2001 From: Aleksey Gurtovoy Date: Sun, 27 Jan 2002 13:32:37 +0000 Subject: [PATCH 014/144] ref_ct_test.cpp [SVN r12524] --- ref_ct_test.cpp | 128 ------------------------------------------------ ref_test.cpp | 68 ++++--------------------- 2 files changed, 9 insertions(+), 187 deletions(-) delete mode 100644 ref_ct_test.cpp diff --git a/ref_ct_test.cpp b/ref_ct_test.cpp deleted file mode 100644 index 97fecc3..0000000 --- a/ref_ct_test.cpp +++ /dev/null @@ -1,128 +0,0 @@ -//----------------------------------------------------------------------------- -// ref_ct_test.cpp - compile-time test for "boost/ref.hpp" header content -// See http://www.boost.org for updates, documentation, and revision history. -//----------------------------------------------------------------------------- -// -// Copyright (c) 2002 -// Aleksey Gurtovoy -// -// Permission to use, copy, modify, distribute and sell this software -// and its documentation for any purpose is hereby granted without fee, -// provided that the above copyright notice appears in all copies and -// that both the copyright notice and this permission notice appear in -// supporting documentation. No representations are made about the -// suitability of this software for any purpose. It is provided "as is" -// without express or implied warranty. - -#include -#include -#include - -namespace { - -template< typename T, typename U > -void ref_test(boost::reference_wrapper) -{ - typedef typename boost::reference_wrapper::type type; - BOOST_STATIC_ASSERT((boost::is_same::value)); - BOOST_STATIC_ASSERT((boost::is_same::value)); -} - -template< typename T > -void assignable_test(T x) -{ - x = x; -} - -template< bool R, typename T > -void is_reference_wrapper_test(T) -{ - BOOST_STATIC_ASSERT(boost::is_reference_wrapper::value == R); -} - -template< typename R, typename Ref > -void cxx_reference_test(Ref) -{ - BOOST_STATIC_ASSERT((boost::is_same::value)); -} - -template< typename R, typename Ref > -void unwrap_reference_test(Ref) -{ - typedef typename boost::unwrap_reference::type type; - BOOST_STATIC_ASSERT((boost::is_same::value)); -} - -} // namespace - -int main() -{ - int i = 0; - int& ri = i; - - int const ci = 0; - int const& rci = ci; - - // 'ref/cref' functions test - ref_test(boost::ref(i)); - ref_test(boost::ref(ri)); - ref_test(boost::ref(ci)); - ref_test(boost::ref(rci)); - - ref_test(boost::cref(i)); - ref_test(boost::cref(ri)); - ref_test(boost::cref(ci)); - ref_test(boost::cref(rci)); - - // test 'assignable' requirement - assignable_test(boost::ref(i)); - assignable_test(boost::ref(ri)); - assignable_test(boost::cref(i)); - assignable_test(boost::cref(ci)); - assignable_test(boost::cref(rci)); - - // 'is_reference_wrapper' test - is_reference_wrapper_test(boost::ref(i)); - is_reference_wrapper_test(boost::ref(ri)); - is_reference_wrapper_test(boost::cref(i)); - is_reference_wrapper_test(boost::cref(ci)); - is_reference_wrapper_test(boost::cref(rci)); - - is_reference_wrapper_test(i); - is_reference_wrapper_test(ri); - is_reference_wrapper_test(ci); - is_reference_wrapper_test(rci); - - // ordinary references/function template arguments deduction test - cxx_reference_test(i); - cxx_reference_test(ri); - cxx_reference_test(ci); - cxx_reference_test(rci); - - cxx_reference_test(i); - cxx_reference_test(ri); - cxx_reference_test(i); - cxx_reference_test(ri); - cxx_reference_test(ci); - cxx_reference_test(rci); - - // 'unwrap_reference' test - unwrap_reference_test(boost::ref(i)); - unwrap_reference_test(boost::ref(ri)); - unwrap_reference_test(boost::cref(i)); - unwrap_reference_test(boost::cref(ci)); - unwrap_reference_test(boost::cref(rci)); - - unwrap_reference_test(i); - unwrap_reference_test(ri); - unwrap_reference_test(ci); - unwrap_reference_test(rci); - unwrap_reference_test(i); - unwrap_reference_test(ri); - unwrap_reference_test(i); - unwrap_reference_test(ri); - unwrap_reference_test(ci); - unwrap_reference_test(rci); - - return 0; -} diff --git a/ref_test.cpp b/ref_test.cpp index 24f9e98..1cfb5dd 100644 --- a/ref_test.cpp +++ b/ref_test.cpp @@ -1,3 +1,7 @@ + +// run-time test for "boost/ref.hpp" header content +// see 'ref_ct_test.cpp' for compile-time part + #if defined(_MSC_VER) && !defined(__ICL) # pragma warning(disable: 4786) // identifier truncated in debug info # pragma warning(disable: 4710) // function not inlined @@ -6,8 +10,6 @@ #endif #include -#include -#include #if defined(BOOST_MSVC) && (BOOST_MSVC < 1300) # pragma warning(push, 3) @@ -27,7 +29,7 @@ namespace { using namespace boost; template -struct wrapper +struct ref_wrapper { // Used to verify implicit conversion static T* get_pointer(T& x) @@ -40,73 +42,25 @@ struct wrapper return &x; } - static void check_type_typedef(...) - { - BOOST_ERROR("expected a reference_wrapper argument"); - } - - template - static void check_type_typedef(boost::reference_wrapper) - { - typedef typename boost::reference_wrapper::type type_typedef; - BOOST_TEST((boost::is_same::value)); - } - template static T* passthru(Arg x) { - check_type_typedef(x); return get_pointer(x); } template static T const* cref_passthru(Arg x) { - check_type_typedef(x); return get_const_pointer(x); } - template - static void test_unwrapped(Arg x) - { - typedef typename unwrap_reference::type unwrapped; - BOOST_TEST((is_same::value)); - } - - template struct select {}; - typedef select constant; - typedef select non_constant; - - static void cref_test(T x, constant) {} - - static void cref_test(T x, non_constant) - { - BOOST_TEST(is_reference_wrapper >::value); - BOOST_TEST(cref_passthru(cref(x)) == &x); - BOOST_TEST(&cref(x).get() == &x); - } - - BOOST_STATIC_CONSTANT( - bool, t_is_constant = boost::is_const::value); - static void test(T x) { BOOST_TEST(passthru(ref(x)) == &x); - - BOOST_TEST((is_same::type,T>::value)); - BOOST_TEST(&ref(x).get() == &x); - typedef reference_wrapper wrapped; - BOOST_TEST(is_reference_wrapper::value); - - typedef typename unwrap_reference::type unwrapped_wrapper; - BOOST_TEST((is_same::value)); - - typedef typename unwrap_reference::type unwrapped_self; - BOOST_TEST((is_same::value)); - - cref_test(x, select()); + BOOST_TEST(cref_passthru(cref(x)) == &x); + BOOST_TEST(&cref(x).get() == &x); } }; @@ -114,11 +68,7 @@ struct wrapper int test_main(int, char * []) { - wrapper::test(1); - wrapper::test(1); - BOOST_TEST(!is_reference_wrapper::value); - BOOST_TEST(!is_reference_wrapper::value); - BOOST_TEST(!is_reference_wrapper::value); - BOOST_TEST(!is_reference_wrapper::value); + ref_wrapper::test(1); + ref_wrapper::test(1); return 0; } From 705d141ce4053de34bab56656ad0643d596e16b4 Mon Sep 17 00:00:00 2001 From: Aleksey Gurtovoy Date: Sun, 27 Jan 2002 13:39:06 +0000 Subject: [PATCH 015/144] compile-time ref.hpp header test, initial checkin [SVN r12525] --- ref_ct_test.cpp | 115 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 ref_ct_test.cpp diff --git a/ref_ct_test.cpp b/ref_ct_test.cpp new file mode 100644 index 0000000..d9af429 --- /dev/null +++ b/ref_ct_test.cpp @@ -0,0 +1,115 @@ +// compile-time test for "boost/ref.hpp" header content +// see 'ref_test.cpp' for run-time part + +#include +#include +#include + +namespace { + +template< typename T, typename U > +void ref_test(boost::reference_wrapper) +{ + typedef typename boost::reference_wrapper::type type; + BOOST_STATIC_ASSERT((boost::is_same::value)); + BOOST_STATIC_ASSERT((boost::is_same::value)); +} + +template< typename T > +void assignable_test(T x) +{ + x = x; +} + +template< bool R, typename T > +void is_reference_wrapper_test(T) +{ + BOOST_STATIC_ASSERT(boost::is_reference_wrapper::value == R); +} + +template< typename R, typename Ref > +void cxx_reference_test(Ref) +{ + BOOST_STATIC_ASSERT((boost::is_same::value)); +} + +template< typename R, typename Ref > +void unwrap_reference_test(Ref) +{ + typedef typename boost::unwrap_reference::type type; + BOOST_STATIC_ASSERT((boost::is_same::value)); +} + +} // namespace + +int main() +{ + int i = 0; + int& ri = i; + + int const ci = 0; + int const& rci = ci; + + // 'ref/cref' functions test + ref_test(boost::ref(i)); + ref_test(boost::ref(ri)); + ref_test(boost::ref(ci)); + ref_test(boost::ref(rci)); + + ref_test(boost::cref(i)); + ref_test(boost::cref(ri)); + ref_test(boost::cref(ci)); + ref_test(boost::cref(rci)); + + // test 'assignable' requirement + assignable_test(boost::ref(i)); + assignable_test(boost::ref(ri)); + assignable_test(boost::cref(i)); + assignable_test(boost::cref(ci)); + assignable_test(boost::cref(rci)); + + // 'is_reference_wrapper' test + is_reference_wrapper_test(boost::ref(i)); + is_reference_wrapper_test(boost::ref(ri)); + is_reference_wrapper_test(boost::cref(i)); + is_reference_wrapper_test(boost::cref(ci)); + is_reference_wrapper_test(boost::cref(rci)); + + is_reference_wrapper_test(i); + is_reference_wrapper_test(ri); + is_reference_wrapper_test(ci); + is_reference_wrapper_test(rci); + + // ordinary references/function template arguments deduction test + cxx_reference_test(i); + cxx_reference_test(ri); + cxx_reference_test(ci); + cxx_reference_test(rci); + + cxx_reference_test(i); + cxx_reference_test(ri); + cxx_reference_test(i); + cxx_reference_test(ri); + cxx_reference_test(ci); + cxx_reference_test(rci); + + // 'unwrap_reference' test + unwrap_reference_test(boost::ref(i)); + unwrap_reference_test(boost::ref(ri)); + unwrap_reference_test(boost::cref(i)); + unwrap_reference_test(boost::cref(ci)); + unwrap_reference_test(boost::cref(rci)); + + unwrap_reference_test(i); + unwrap_reference_test(ri); + unwrap_reference_test(ci); + unwrap_reference_test(rci); + unwrap_reference_test(i); + unwrap_reference_test(ri); + unwrap_reference_test(i); + unwrap_reference_test(ri); + unwrap_reference_test(ci); + unwrap_reference_test(rci); + + return 0; +} From 0e59ec327d17c8b46b2a4543ce13a0b28c77f7ec Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Fri, 15 Feb 2002 13:31:58 +0000 Subject: [PATCH 016/144] Added a default constructor to shared_count and shared_ptr for incomplete types (void). [SVN r12815] --- include/boost/checked_delete.hpp | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/include/boost/checked_delete.hpp b/include/boost/checked_delete.hpp index ad11d58..abb2ce0 100644 --- a/include/boost/checked_delete.hpp +++ b/include/boost/checked_delete.hpp @@ -44,19 +44,6 @@ template struct checked_deleter } }; -// checked_deleter is needed by shared_ptr::reset(0) - -template<> struct checked_deleter -{ - typedef void result_type; - typedef void * argument_type; - - void operator()(void * x) - { - ::operator delete(x); // avoid g++ warning - } -}; - template struct checked_array_deleter { typedef void result_type; From 0c5f2755698da471531defe7fa26195497c7e9ab Mon Sep 17 00:00:00 2001 From: Dave Abrahams Date: Sat, 9 Mar 2002 20:34:06 +0000 Subject: [PATCH 017/144] Added Copyright [SVN r13145] --- include/boost/ref.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/include/boost/ref.hpp b/include/boost/ref.hpp index cf85e64..9a93fb2 100644 --- a/include/boost/ref.hpp +++ b/include/boost/ref.hpp @@ -12,6 +12,7 @@ // // Copyright (C) 1999, 2000 Jaakko Järvi (jaakko.jarvi@cs.utu.fi) // Copyright (C) 2001 Peter Dimov +// Copyright (C) 2002 David Abrahams // // Permission to copy, use, modify, sell and distribute this software // is granted provided this copyright notice appears in all copies. From cf80afce24d4377ce0a5854e6ade26a9d7d0b609 Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Sun, 31 Mar 2002 00:24:00 +0000 Subject: [PATCH 018/144] boost/ref.hpp: - Added get_pointer method to return a pointer (instead of a reference) libs/bind/ref.html: - Document get_pointer [SVN r13322] --- include/boost/ref.hpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/boost/ref.hpp b/include/boost/ref.hpp index 9a93fb2..c7e23ca 100644 --- a/include/boost/ref.hpp +++ b/include/boost/ref.hpp @@ -36,6 +36,8 @@ public: T& get() const { return *t_; } + T* get_pointer() const { return t_; } + private: T* t_; From 795ae317eb0f61adf2348d33fb00ad6175e68dfe Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Wed, 10 Apr 2002 03:31:18 +0000 Subject: [PATCH 019/144] boost/utility.hpp: - Include boost/utility/addressof.hpp boost/utility/addressof.hpp: - addressof() implementation libs/utility/utility.htm: - Document addressof libs/utility/addressof_test.cpp: - Test addressof() [SVN r13414] --- addressof_test.cpp | 46 +++++++++++++++++++++++++ include/boost/utility/addressof.hpp | 53 +++++++++++++++++++++++++++++ 2 files changed, 99 insertions(+) create mode 100644 addressof_test.cpp create mode 100644 include/boost/utility/addressof.hpp diff --git a/addressof_test.cpp b/addressof_test.cpp new file mode 100644 index 0000000..62d988c --- /dev/null +++ b/addressof_test.cpp @@ -0,0 +1,46 @@ +// Copyright (C) 2002 Brad King (brad.king@kitware.com) +// Doug Gregor (gregod@cs.rpi.edu) +// +// 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 + +#define BOOST_INCLUDE_MAIN +#include +#include + +struct useless_type {}; + +class nonaddressable { +public: + void dummy(); // Silence GCC warning: all member of class are private + +private: + useless_type operator&() const; +}; + +int test_main(int, char*[]) +{ + nonaddressable* px = new nonaddressable(); + + nonaddressable& x = *px; + BOOST_TEST(boost::addressof(x) == px); + + const nonaddressable& cx = *px; + BOOST_TEST(boost::addressof(cx) == static_cast(px)); + + volatile nonaddressable& vx = *px; + BOOST_TEST(boost::addressof(vx) == static_cast(px)); + + const volatile nonaddressable& cvx = *px; + BOOST_TEST(boost::addressof(cvx) == static_cast(px)); + + return 0; +} diff --git a/include/boost/utility/addressof.hpp b/include/boost/utility/addressof.hpp new file mode 100644 index 0000000..ee997ff --- /dev/null +++ b/include/boost/utility/addressof.hpp @@ -0,0 +1,53 @@ +// Copyright (C) 2002 Brad King (brad.king@kitware.com) +// Doug Gregor (gregod@cs.rpi.edu) +// +// 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 + +#ifndef BOOST_UTILITY_ADDRESSOF_HPP +#define BOOST_UTILITY_ADDRESSOF_HPP + +namespace boost { + +template +inline T* addressof(T& v) +{ + struct addressof_helper {}; + return reinterpret_cast(&reinterpret_cast(v)); +} + +template +inline const T* addressof(const T& v) +{ + struct addressof_helper {}; + return reinterpret_cast( + &reinterpret_cast(v)); +} + +template +inline volatile T* addressof(volatile T& v) +{ + struct addressof_helper {}; + return reinterpret_cast( + &reinterpret_cast(v)); +} + +template +inline const volatile T* addressof(const volatile T& v) +{ + struct addressof_helper {}; + return reinterpret_cast( + &reinterpret_cast(v)); +} + +} + +#endif // BOOST_UTILITY_ADDRESSOF_HPP From 10d1e3b2738063ed203d89b64ae76787e8d90741 Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Wed, 10 Apr 2002 03:36:17 +0000 Subject: [PATCH 020/144] ref.hpp: - Use addressof() instead of & operator [SVN r13416] --- include/boost/ref.hpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/boost/ref.hpp b/include/boost/ref.hpp index c7e23ca..e45dd17 100644 --- a/include/boost/ref.hpp +++ b/include/boost/ref.hpp @@ -6,6 +6,7 @@ # endif # include +# include // // ref.hpp - ref/cref, useful helper functions @@ -30,7 +31,7 @@ template class reference_wrapper public: typedef T type; - explicit reference_wrapper(T& t): t_(&t) {} + explicit reference_wrapper(T& t): t_(addressof(t)) {} operator T& () const { return *t_; } From 3e0cbb0faa79e88bae4027f4e88fce9f80b4e4e0 Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Wed, 10 Apr 2002 04:00:22 +0000 Subject: [PATCH 021/144] Make local classes nonlocal to silence annoying warnings from Borland C++ [SVN r13418] --- include/boost/utility/addressof.hpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/include/boost/utility/addressof.hpp b/include/boost/utility/addressof.hpp index ee997ff..11a9fd3 100644 --- a/include/boost/utility/addressof.hpp +++ b/include/boost/utility/addressof.hpp @@ -17,35 +17,36 @@ namespace boost { +namespace detail { + struct addressof_helper {}; +} + template inline T* addressof(T& v) { - struct addressof_helper {}; - return reinterpret_cast(&reinterpret_cast(v)); + return reinterpret_cast( + &reinterpret_cast(v)); } template inline const T* addressof(const T& v) { - struct addressof_helper {}; return reinterpret_cast( - &reinterpret_cast(v)); + &reinterpret_cast(v)); } template inline volatile T* addressof(volatile T& v) { - struct addressof_helper {}; return reinterpret_cast( - &reinterpret_cast(v)); + &reinterpret_cast(v)); } template inline const volatile T* addressof(const volatile T& v) { - struct addressof_helper {}; return reinterpret_cast( - &reinterpret_cast(v)); + &reinterpret_cast(v)); } } From 258340c3cbe664ce6baf9aae90e00db1e82688df Mon Sep 17 00:00:00 2001 From: Dave Abrahams Date: Wed, 10 Apr 2002 09:48:30 +0000 Subject: [PATCH 022/144] Roll back addressof() patch temporarily [SVN r13428] --- include/boost/ref.hpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/include/boost/ref.hpp b/include/boost/ref.hpp index e45dd17..c7e23ca 100644 --- a/include/boost/ref.hpp +++ b/include/boost/ref.hpp @@ -6,7 +6,6 @@ # endif # include -# include // // ref.hpp - ref/cref, useful helper functions @@ -31,7 +30,7 @@ template class reference_wrapper public: typedef T type; - explicit reference_wrapper(T& t): t_(addressof(t)) {} + explicit reference_wrapper(T& t): t_(&t) {} operator T& () const { return *t_; } From fd437c96046f0632710fb2d4e48bbfac0affac10 Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Wed, 10 Apr 2002 14:47:32 +0000 Subject: [PATCH 023/144] addressof.hpp: - Peter Dimov suggested a fix to deal with those evil cv-qualifiers [SVN r13431] --- include/boost/utility/addressof.hpp | 27 +-------------------------- 1 file changed, 1 insertion(+), 26 deletions(-) diff --git a/include/boost/utility/addressof.hpp b/include/boost/utility/addressof.hpp index 11a9fd3..22da536 100644 --- a/include/boost/utility/addressof.hpp +++ b/include/boost/utility/addressof.hpp @@ -17,36 +17,11 @@ namespace boost { -namespace detail { - struct addressof_helper {}; -} - template inline T* addressof(T& v) { return reinterpret_cast( - &reinterpret_cast(v)); -} - -template -inline const T* addressof(const T& v) -{ - return reinterpret_cast( - &reinterpret_cast(v)); -} - -template -inline volatile T* addressof(volatile T& v) -{ - return reinterpret_cast( - &reinterpret_cast(v)); -} - -template -inline const volatile T* addressof(const volatile T& v) -{ - return reinterpret_cast( - &reinterpret_cast(v)); + &const_cast(reinterpret_cast(v))); } } From 077b632187013d867705376f75839ab5c2159169 Mon Sep 17 00:00:00 2001 From: Dave Abrahams Date: Wed, 10 Apr 2002 17:01:35 +0000 Subject: [PATCH 024/144] Roll addressof() patch back in! [SVN r13433] --- include/boost/ref.hpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/boost/ref.hpp b/include/boost/ref.hpp index c7e23ca..e45dd17 100644 --- a/include/boost/ref.hpp +++ b/include/boost/ref.hpp @@ -6,6 +6,7 @@ # endif # include +# include // // ref.hpp - ref/cref, useful helper functions @@ -30,7 +31,7 @@ template class reference_wrapper public: typedef T type; - explicit reference_wrapper(T& t): t_(&t) {} + explicit reference_wrapper(T& t): t_(addressof(t)) {} operator T& () const { return *t_; } From 84fbe634b1d23e9dda20e9cfdd1e364e255571e0 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Sat, 13 Apr 2002 13:19:57 +0000 Subject: [PATCH 025/144] MSVC fixes. [SVN r13476] --- include/boost/ref.hpp | 10 +++++++++- include/boost/utility/addressof.hpp | 8 +++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/include/boost/ref.hpp b/include/boost/ref.hpp index e45dd17..9a6fbc5 100644 --- a/include/boost/ref.hpp +++ b/include/boost/ref.hpp @@ -12,7 +12,7 @@ // ref.hpp - ref/cref, useful helper functions // // Copyright (C) 1999, 2000 Jaakko Järvi (jaakko.jarvi@cs.utu.fi) -// Copyright (C) 2001 Peter Dimov +// Copyright (C) 2001, 2002 Peter Dimov // Copyright (C) 2002 David Abrahams // // Permission to copy, use, modify, sell and distribute this software @@ -31,8 +31,16 @@ template class reference_wrapper public: typedef T type; +#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300) + + explicit reference_wrapper(T& t): t_(&t) {} + +#else + explicit reference_wrapper(T& t): t_(addressof(t)) {} +#endif + operator T& () const { return *t_; } T& get() const { return *t_; } diff --git a/include/boost/utility/addressof.hpp b/include/boost/utility/addressof.hpp index 22da536..a434b8e 100644 --- a/include/boost/utility/addressof.hpp +++ b/include/boost/utility/addressof.hpp @@ -1,5 +1,6 @@ // Copyright (C) 2002 Brad King (brad.king@kitware.com) // Doug Gregor (gregod@cs.rpi.edu) +// Peter Dimov // // Permission to copy, use, sell and distribute this software is granted // provided this copyright notice appears in all copies. @@ -17,11 +18,12 @@ namespace boost { -template -inline T* addressof(T& v) +// Do not make addressof() inline. Breaks MSVC 7. (Peter Dimov) + +template T* addressof(T& v) { return reinterpret_cast( - &const_cast(reinterpret_cast(v))); + &const_cast(reinterpret_cast(v))); } } From d7f719ed96f2648cab72934461ae31406b469d16 Mon Sep 17 00:00:00 2001 From: John Maddock Date: Sat, 4 May 2002 10:55:15 +0000 Subject: [PATCH 026/144] Borland C++ Builder 6 fixes [SVN r13659] --- include/boost/ref.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/boost/ref.hpp b/include/boost/ref.hpp index 9a6fbc5..60a834b 100644 --- a/include/boost/ref.hpp +++ b/include/boost/ref.hpp @@ -52,7 +52,7 @@ private: T* t_; }; -# if defined(__BORLANDC__) && (__BORLANDC__ <= 0x551) +# if defined(__BORLANDC__) && (__BORLANDC__ <= 0x560) # define BOOST_REF_CONST # else # define BOOST_REF_CONST const From 175b88649b3e7d6a99250348ef76d0ba74d1f9ea Mon Sep 17 00:00:00 2001 From: John Maddock Date: Sun, 25 Aug 2002 11:57:37 +0000 Subject: [PATCH 027/144] Misc Kylix fixes [SVN r15086] --- include/boost/ref.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/boost/ref.hpp b/include/boost/ref.hpp index 60a834b..a8d996c 100644 --- a/include/boost/ref.hpp +++ b/include/boost/ref.hpp @@ -52,7 +52,7 @@ private: T* t_; }; -# if defined(__BORLANDC__) && (__BORLANDC__ <= 0x560) +# if defined(__BORLANDC__) && (__BORLANDC__ <= 0x570) # define BOOST_REF_CONST # else # define BOOST_REF_CONST const From bdc34b65206e1af3fd5cd495aa65e637457307c6 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Wed, 23 Oct 2002 13:55:18 +0000 Subject: [PATCH 028/144] Changed typename to class; some libraries helpfully #define typename [SVN r15970] --- include/boost/checked_delete.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/boost/checked_delete.hpp b/include/boost/checked_delete.hpp index abb2ce0..9e42d9c 100644 --- a/include/boost/checked_delete.hpp +++ b/include/boost/checked_delete.hpp @@ -21,13 +21,13 @@ namespace boost // verify that types are complete for increased safety -template< typename T > inline void checked_delete(T * x) +template inline void checked_delete(T * x) { typedef char type_must_be_complete[sizeof(T)]; delete x; } -template< typename T > inline void checked_array_delete(T * x) +template inline void checked_array_delete(T * x) { typedef char type_must_be_complete[sizeof(T)]; delete [] x; From c1d7226a4a3bd198625202e1678b93c40f614f73 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Thu, 14 Nov 2002 14:53:32 +0000 Subject: [PATCH 029/144] checked_delete.hpp documentation added. [SVN r16238] --- checked_delete.html | 124 +++++++++++++++++++++++++++++++ include/boost/checked_delete.hpp | 3 + 2 files changed, 127 insertions(+) create mode 100644 checked_delete.html diff --git a/checked_delete.html b/checked_delete.html new file mode 100644 index 0000000..bd7753e --- /dev/null +++ b/checked_delete.html @@ -0,0 +1,124 @@ + + + + Boost: checked_delete.hpp documentation + + + + + + + + + + + +
+ c++boost.gif (8819 bytes) + +

checked_delete.hpp

+
 
+

+ The header <boost/checked_delete.hpp> defines two + function templates, checked_delete and checked_array_delete, + and two class templates, checked_deleter and checked_array_deleter. +

+

The C++ Standard allows, in 5.3.5/5, pointers to incomplete class types to + be deleted with a delete-expression. When the class has a non-trivial + destructor, or a class-specific operator delete, the behavior is undefined. + Some compilers issue a warning when an incomplete type is deleted, but + unfortunately, not all do, and programmers sometimes ignore or disable + warnings.

+

A particularly troublesome case is when a smart pointer's destructor, such as + boost::scoped_ptr<T>::~scoped_ptr, is instantiated with an + incomplete type. This can often lead to silent, hard to track failures.

+

The supplied function and class templates can be used to prevent these problems, + as they require a complete type, and cause a compilation error otherwise.

+

Synopsis

+
+namespace boost
+{
+
+template<class T> void checked_delete(T * p);
+template<class T> void checked_array_delete(T * p);
+template<class T> struct checked_deleter;
+template<class T> struct checked_array_deleter;
+
+}
+
+

checked_delete

+

template<class T> void checked_delete(T * p);

+
+

+ Requires: T must be a complete type. The expression delete p + must be well-formed. +

+

+ Effects: delete p; +

+
+

checked_array_delete

+

template<class T> void checked_array_delete(T + * p);

+
+

+ Requires: T must be a complete type. The expression delete [] p + must be well-formed. +

+

+ Effects: delete [] p; +

+
+

checked_deleter

+
+template<class T> struct checked_deleter
+{
+    typedef void result_type;
+    typedef T * argument_type;
+    void operator()(T * p);
+};
+
+

void checked_deleter<T>::operator()(T * p);

+
+

+ Requires: T must be a complete type. The expression delete p + must be well-formed. +

+

+ Effects: delete p; +

+
+

checked_array_deleter

+
+template<class T> struct checked_array_deleter
+{
+    typedef void result_type;
+    typedef T * argument_type;
+    void operator()(T * p);
+};
+
+

void checked_array_deleter<T>::operator()(T * p);

+
+

+ Requires: T must be a complete type. The expression delete [] p + must be well-formed. +

+

+ Effects: delete [] p; +

+
+

Acknowledgements

+

+ The function templates checked_delete and checked_array_delete + were originally part of <boost/utility.hpp>, and the + documentation acknowledged Beman Dawes, Dave Abrahams, Vladimir Prus, + Rainer Deyke, John Maddock, and others as contributors. +

+

+
+ Copyright © 2002 by Peter Dimov. Permission to copy, use, modify, sell + and distribute this document is granted provided this copyright notice appears + in all copies. This document is provided "as is" without express or implied + warranty, and with no claim as to its suitability for any purpose.

+ + diff --git a/include/boost/checked_delete.hpp b/include/boost/checked_delete.hpp index 9e42d9c..bf689c9 100644 --- a/include/boost/checked_delete.hpp +++ b/include/boost/checked_delete.hpp @@ -9,12 +9,15 @@ // boost/checked_delete.hpp // // Copyright (c) 1999, 2000, 2001, 2002 boost.org +// Copyright (c) 2002 Peter Dimov // // Permission to copy, use, modify, sell and distribute this software // is granted provided this copyright notice appears in all copies. // This software is provided "as is" without express or implied // warranty, and with no claim as to its suitability for any purpose. // +// http://www.boost.org/libs/utility/checked_delete.html +// namespace boost { From 7e079dd8b1fa8507eb6301f672e803ace7328e9e Mon Sep 17 00:00:00 2001 From: Beman Dawes Date: Mon, 23 Dec 2002 02:43:12 +0000 Subject: [PATCH 030/144] Add /libs/lib-name to comment [SVN r16685] --- include/boost/checked_delete.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/boost/checked_delete.hpp b/include/boost/checked_delete.hpp index bf689c9..223b4b5 100644 --- a/include/boost/checked_delete.hpp +++ b/include/boost/checked_delete.hpp @@ -16,7 +16,7 @@ // This software is provided "as is" without express or implied // warranty, and with no claim as to its suitability for any purpose. // -// http://www.boost.org/libs/utility/checked_delete.html +// See http://www.boost.org/libs/utility/checked_delete.html for documentation. // namespace boost From 33190d43c2f6378ebcc8cd673b14045a8ba1dc9e Mon Sep 17 00:00:00 2001 From: Dave Abrahams Date: Wed, 8 Jan 2003 17:21:10 +0000 Subject: [PATCH 031/144] Workaround VC7 bug which strips const from nested classes [SVN r16797] --- include/boost/utility/addressof.hpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/include/boost/utility/addressof.hpp b/include/boost/utility/addressof.hpp index a434b8e..de8dfe5 100644 --- a/include/boost/utility/addressof.hpp +++ b/include/boost/utility/addressof.hpp @@ -14,13 +14,25 @@ // For more information, see http://www.boost.org #ifndef BOOST_UTILITY_ADDRESSOF_HPP -#define BOOST_UTILITY_ADDRESSOF_HPP +# define BOOST_UTILITY_ADDRESSOF_HPP + +# include +# include +# if BOOST_WORKAROUND(BOOST_MSVC, == 1300) +# include +# endif namespace boost { // Do not make addressof() inline. Breaks MSVC 7. (Peter Dimov) -template T* addressof(T& v) +// VC7 strips const from nested classes unless we add indirection here +# if BOOST_WORKAROUND(BOOST_MSVC, == 1300) +template typename add_pointer::type +# else +template T* +# endif +addressof(T& v) { return reinterpret_cast( &const_cast(reinterpret_cast(v))); From 25a15916bcdf784428f911742b53974f9d6e70be Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Fri, 14 Feb 2003 16:20:01 +0000 Subject: [PATCH 032/144] Made operator()s const. [SVN r17411] --- checked_delete.html | 22 +++++++++++----------- include/boost/checked_delete.hpp | 6 +++--- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/checked_delete.html b/checked_delete.html index bd7753e..4af2ae7 100644 --- a/checked_delete.html +++ b/checked_delete.html @@ -23,8 +23,8 @@ function templates, checked_delete and checked_array_delete, and two class templates, checked_deleter and checked_array_deleter.

-

The C++ Standard allows, in 5.3.5/5, pointers to incomplete class types to - be deleted with a delete-expression. When the class has a non-trivial +

The C++ Standard allows, in 5.3.5/5, pointers to incomplete class types to be + deleted with a delete-expression. When the class has a non-trivial destructor, or a class-specific operator delete, the behavior is undefined. Some compilers issue a warning when an incomplete type is deleted, but unfortunately, not all do, and programmers sometimes ignore or disable @@ -75,10 +75,10 @@ template<class T> struct checked_deleter { typedef void result_type; typedef T * argument_type; - void operator()(T * p); + void operator()(T * p) const; }; -

void checked_deleter<T>::operator()(T * p);

+

void checked_deleter<T>::operator()(T * p) const;

Requires: T must be a complete type. The expression delete p @@ -94,10 +94,10 @@ template<class T> struct checked_array_deleter { typedef void result_type; typedef T * argument_type; - void operator()(T * p); + void operator()(T * p) const; }; -

void checked_array_deleter<T>::operator()(T * p);

+

void checked_array_deleter<T>::operator()(T * p) const;

Requires: T must be a complete type. The expression delete [] p @@ -111,14 +111,14 @@ template<class T> struct checked_array_deleter

The function templates checked_delete and checked_array_delete were originally part of <boost/utility.hpp>, and the - documentation acknowledged Beman Dawes, Dave Abrahams, Vladimir Prus, - Rainer Deyke, John Maddock, and others as contributors. + documentation acknowledged Beman Dawes, Dave Abrahams, Vladimir Prus, Rainer + Deyke, John Maddock, and others as contributors.


- Copyright © 2002 by Peter Dimov. 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 + Copyright © 2002 by Peter Dimov. Permission to copy, use, modify, sell and + distribute this document is granted provided this copyright notice appears in + all copies. This document is provided "as is" without express or implied warranty, and with no claim as to its suitability for any purpose.

diff --git a/include/boost/checked_delete.hpp b/include/boost/checked_delete.hpp index 223b4b5..aa8a7a5 100644 --- a/include/boost/checked_delete.hpp +++ b/include/boost/checked_delete.hpp @@ -9,7 +9,7 @@ // boost/checked_delete.hpp // // Copyright (c) 1999, 2000, 2001, 2002 boost.org -// Copyright (c) 2002 Peter Dimov +// Copyright (c) 2002, 2003 Peter Dimov // // Permission to copy, use, modify, sell and distribute this software // is granted provided this copyright notice appears in all copies. @@ -41,7 +41,7 @@ template struct checked_deleter typedef void result_type; typedef T * argument_type; - void operator()(T * x) + void operator()(T * x) const { checked_delete(x); } @@ -52,7 +52,7 @@ template struct checked_array_deleter typedef void result_type; typedef T * argument_type; - void operator()(T * x) + void operator()(T * x) const { checked_array_delete(x); } From a1dc228726959e2d1cbca940c6f2a203861eb1a1 Mon Sep 17 00:00:00 2001 From: Aleksey Gurtovoy Date: Mon, 17 Feb 2003 06:20:57 +0000 Subject: [PATCH 033/144] split utility.hpp header [SVN r17472] --- checked_delete_test.cpp | 2 +- include/boost/noncopyable.hpp | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 include/boost/noncopyable.hpp diff --git a/checked_delete_test.cpp b/checked_delete_test.cpp index f9107c8..161b49f 100644 --- a/checked_delete_test.cpp +++ b/checked_delete_test.cpp @@ -11,7 +11,7 @@ // Revision History // 21 May 01 Initial version (Beman Dawes) -#include // for checked_delete +#include // for checked_delete // This program demonstrates compiler errors when trying to delete an // incomplete type. diff --git a/include/boost/noncopyable.hpp b/include/boost/noncopyable.hpp new file mode 100644 index 0000000..e2c8399 --- /dev/null +++ b/include/boost/noncopyable.hpp @@ -0,0 +1,33 @@ +// Boost noncopyable.hpp header file --------------------------------------// + +// (C) Copyright Boost.org 1999-2003. Permission to copy, use, modify, sell +// and distribute this software is granted provided this copyright +// notice appears in all copies. This software is provided "as is" without +// express or implied warranty, and with no claim as to its suitability for +// any purpose. + +// See http://www.boost.org/libs/utility for documentation. + +#ifndef BOOST_NONCOPYABLE_HPP_INCLUDED +#define BOOST_NONCOPYABLE_HPP_INCLUDED + +namespace boost { + +// Private copy constructor and copy assignment ensure classes derived from +// class noncopyable cannot be copied. + +// Contributed by Dave Abrahams + +class noncopyable +{ + protected: + noncopyable() {} + ~noncopyable() {} + private: // emphasize the following members are private + noncopyable( const noncopyable& ); + const noncopyable& operator=( const noncopyable& ); +}; + +} // namespace boost + +#endif // BOOST_NONCOPYABLE_HPP_INCLUDED From a61832c9955d86cfe698466d02fc78588d5dd799 Mon Sep 17 00:00:00 2001 From: Dave Abrahams Date: Tue, 25 Feb 2003 00:57:33 +0000 Subject: [PATCH 034/144] fix metafunctions for MPL [SVN r17621] --- include/boost/ref.hpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/include/boost/ref.hpp b/include/boost/ref.hpp index a8d996c..c8a46c3 100644 --- a/include/boost/ref.hpp +++ b/include/boost/ref.hpp @@ -7,6 +7,7 @@ # include # include +# include // // ref.hpp - ref/cref, useful helper functions @@ -73,16 +74,14 @@ template inline reference_wrapper BOOST_REF_CONST cref(T const # ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION template class is_reference_wrapper + : public mpl::false_c { - public: - BOOST_STATIC_CONSTANT(bool, value = false); }; template class is_reference_wrapper > + : public mpl::true_c { - public: - BOOST_STATIC_CONSTANT(bool, value = true); }; template @@ -144,8 +143,10 @@ class is_reference_wrapper public: BOOST_STATIC_CONSTANT( bool, value = ( - sizeof(detail::is_reference_wrapper_test(type())) + sizeof(detail::is_reference_wrapper_test(type())) == sizeof(detail::yes_reference_wrapper_t))); + + typedef ::boost::mpl::bool_c type; }; template From 4db279cd810b2a1f8e03d0a513486eb3a4189f48 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Tue, 25 Feb 2003 13:00:22 +0000 Subject: [PATCH 035/144] Qualified checked_delete calls to prevent ADL (reported by Daniel Frey) [SVN r17636] --- include/boost/checked_delete.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/boost/checked_delete.hpp b/include/boost/checked_delete.hpp index aa8a7a5..92a3d0a 100644 --- a/include/boost/checked_delete.hpp +++ b/include/boost/checked_delete.hpp @@ -43,7 +43,7 @@ template struct checked_deleter void operator()(T * x) const { - checked_delete(x); + boost::checked_delete(x); } }; @@ -54,7 +54,7 @@ template struct checked_array_deleter void operator()(T * x) const { - checked_array_delete(x); + boost::checked_array_delete(x); } }; From ef31702ea4103c0a5804a16e6aa6120d708b2166 Mon Sep 17 00:00:00 2001 From: Aleksey Gurtovoy Date: Tue, 25 Feb 2003 23:11:41 +0000 Subject: [PATCH 036/144] MPL names/directory structure refactoring [SVN r17651] --- include/boost/ref.hpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/include/boost/ref.hpp b/include/boost/ref.hpp index c8a46c3..52f01cd 100644 --- a/include/boost/ref.hpp +++ b/include/boost/ref.hpp @@ -7,7 +7,7 @@ # include # include -# include +# include // // ref.hpp - ref/cref, useful helper functions @@ -74,13 +74,13 @@ template inline reference_wrapper BOOST_REF_CONST cref(T const # ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION template class is_reference_wrapper - : public mpl::false_c + : public mpl::false_ { }; template class is_reference_wrapper > - : public mpl::true_c + : public mpl::true_ { }; @@ -146,7 +146,7 @@ class is_reference_wrapper sizeof(detail::is_reference_wrapper_test(type())) == sizeof(detail::yes_reference_wrapper_t))); - typedef ::boost::mpl::bool_c type; + typedef ::boost::mpl::bool_ type; }; template From d5331fc7ca83d1fae528e6048cdfe897cfc841dc Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Thu, 12 Jun 2003 17:09:24 +0000 Subject: [PATCH 037/144] -Wundef fixes. [SVN r18788] --- include/boost/checked_delete.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/boost/checked_delete.hpp b/include/boost/checked_delete.hpp index 92a3d0a..f2300dd 100644 --- a/include/boost/checked_delete.hpp +++ b/include/boost/checked_delete.hpp @@ -1,8 +1,8 @@ #ifndef BOOST_CHECKED_DELETE_HPP_INCLUDED #define BOOST_CHECKED_DELETE_HPP_INCLUDED -#if _MSC_VER >= 1020 -#pragma once +#if defined(_MSC_VER) && (_MSC_VER >= 1020) +# pragma once #endif // From 37e3679e674d893e85d508f1a1fde93428e165ef Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Wed, 16 Jul 2003 10:53:06 +0000 Subject: [PATCH 038/144] Fixed Intel 7 issue (reported by Daniel Frey) [SVN r19145] --- checked_delete_test.cpp | 5 ++--- include/boost/checked_delete.hpp | 6 ++++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/checked_delete_test.cpp b/checked_delete_test.cpp index 161b49f..f5c799e 100644 --- a/checked_delete_test.cpp +++ b/checked_delete_test.cpp @@ -23,9 +23,8 @@ namespace int main() { - Incomplete * p; + Incomplete * p = 0; boost::checked_delete(p); // should cause compile time error - Incomplete ** pa; - boost::checked_array_delete(pa); // should cause compile time error + boost::checked_array_delete(p); // should cause compile time error return 0; } // main diff --git a/include/boost/checked_delete.hpp b/include/boost/checked_delete.hpp index f2300dd..3f7ca47 100644 --- a/include/boost/checked_delete.hpp +++ b/include/boost/checked_delete.hpp @@ -26,13 +26,14 @@ namespace boost template inline void checked_delete(T * x) { - typedef char type_must_be_complete[sizeof(T)]; + // Intel 7 accepts sizeof(incomplete) as 0 in system headers + typedef char type_must_be_complete[ sizeof(T)? 1: -1 ]; delete x; } template inline void checked_array_delete(T * x) { - typedef char type_must_be_complete[sizeof(T)]; + typedef char type_must_be_complete[ sizeof(T)? 1: -1 ]; delete [] x; } @@ -43,6 +44,7 @@ template struct checked_deleter void operator()(T * x) const { + // boost:: disables ADL boost::checked_delete(x); } }; From 9085a27d5f77cb1636a5ab2bff25cb0605b135a9 Mon Sep 17 00:00:00 2001 From: Daniel Frey Date: Sat, 16 Aug 2003 01:05:43 +0000 Subject: [PATCH 039/144] Fix for Metrowerks CW [SVN r19626] --- include/boost/checked_delete.hpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/include/boost/checked_delete.hpp b/include/boost/checked_delete.hpp index 3f7ca47..480c041 100644 --- a/include/boost/checked_delete.hpp +++ b/include/boost/checked_delete.hpp @@ -10,6 +10,8 @@ // // Copyright (c) 1999, 2000, 2001, 2002 boost.org // Copyright (c) 2002, 2003 Peter Dimov +// Copyright (c) 2003 Daniel Frey +// Copyright (c) 2003 Howard Hinnant // // Permission to copy, use, modify, sell and distribute this software // is granted provided this copyright notice appears in all copies. @@ -26,14 +28,16 @@ namespace boost template inline void checked_delete(T * x) { - // Intel 7 accepts sizeof(incomplete) as 0 in system headers + // intentionally complex - simplification causes regressions typedef char type_must_be_complete[ sizeof(T)? 1: -1 ]; + (void) sizeof(type_must_be_complete); delete x; } template inline void checked_array_delete(T * x) { typedef char type_must_be_complete[ sizeof(T)? 1: -1 ]; + (void) sizeof(type_must_be_complete); delete [] x; } From d6aafe7e1a6715e0f2a6758a0cbcbd95612ba94f Mon Sep 17 00:00:00 2001 From: Beman Dawes Date: Fri, 12 Sep 2003 17:09:29 +0000 Subject: [PATCH 040/144] Change license message to reference Boost Software License [SVN r20038] --- checked_delete_test.cpp | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/checked_delete_test.cpp b/checked_delete_test.cpp index f5c799e..1ffc1fd 100644 --- a/checked_delete_test.cpp +++ b/checked_delete_test.cpp @@ -1,12 +1,9 @@ // Boost checked_delete test program ---------------------------------------// -// (C) Copyright Beman Dawes 2001. Permission to copy, use, modify, sell -// and distribute this software is granted provided this copyright -// notice appears in all copies. This software is provided "as is" without -// express or implied warranty, and with no claim as to its suitability for -// any purpose. +// Copyright Beman Dawes 2001. +// See accompanying license for terms and conditions of use. -// See http://www.boost.org for most recent version including documentation. +// See http://www.boost.org/libs/utility for documentation. // Revision History // 21 May 01 Initial version (Beman Dawes) From be15129f9cf12a7289d34083bd9165b06721b8ae Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Fri, 28 Nov 2003 15:35:21 +0000 Subject: [PATCH 041/144] _MSC_VER use clarified. [SVN r20992] --- include/boost/checked_delete.hpp | 2 ++ include/boost/ref.hpp | 16 +++++++++------- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/include/boost/checked_delete.hpp b/include/boost/checked_delete.hpp index 480c041..d7f5212 100644 --- a/include/boost/checked_delete.hpp +++ b/include/boost/checked_delete.hpp @@ -1,6 +1,8 @@ #ifndef BOOST_CHECKED_DELETE_HPP_INCLUDED #define BOOST_CHECKED_DELETE_HPP_INCLUDED +// MS compatible compilers support #pragma once + #if defined(_MSC_VER) && (_MSC_VER >= 1020) # pragma once #endif diff --git a/include/boost/ref.hpp b/include/boost/ref.hpp index 52f01cd..8ff5725 100644 --- a/include/boost/ref.hpp +++ b/include/boost/ref.hpp @@ -1,13 +1,15 @@ #ifndef BOOST_REF_HPP_INCLUDED -# define BOOST_REF_HPP_INCLUDED +#define BOOST_REF_HPP_INCLUDED -# if _MSC_VER+0 >= 1020 -# pragma once -# endif +// MS compatible compilers support #pragma once -# include -# include -# include +#if defined(_MSC_VER) && (_MSC_VER >= 1020) +# pragma once +#endif + +#include +#include +#include // // ref.hpp - ref/cref, useful helper functions From 82195e9e6bdb6edb53bd05d9172d9cf8f75cf55e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaakko=20J=C3=A4rvi?= Date: Tue, 2 Dec 2003 21:41:15 +0000 Subject: [PATCH 042/144] Added enable_if library [SVN r21090] --- enable_if.html | 417 ++++++++++++++++++++++++++++ include/boost/utility/enable_if.hpp | 69 +++++ 2 files changed, 486 insertions(+) create mode 100644 enable_if.html create mode 100644 include/boost/utility/enable_if.hpp diff --git a/enable_if.html b/enable_if.html new file mode 100644 index 0000000..349189e --- /dev/null +++ b/enable_if.html @@ -0,0 +1,417 @@ + + +enable_if + + + + + + + + + + +
+
+ + +

+enable_if

+
+
+Copyright 2003 Jaakko Järvi, Jeremiah Willcock, Andrew Lumsdaine.
+
+ + +

1  Introduction

+ + +The enable_if family of templates is a set of tools to allow a function template or a class template specialization +to include or exclude itself from a set of matching functions or specializations +based on properties of its template arguments. +For example, one can define function templates that +are only enabled for, and thus only match, an arbitrary set of types +defined by a traits class. The enable_if templates can also be +applied to enable class template specializations. Applications of +enable_if are discussed in length +in [1] and [2].
+
+ + +

1.1  Synopsis

+ + +
+namespace boost {
+  template <class Cond, class T = void> struct enable_if;
+  template <class Cond, class T = void> struct disable_if;
+  template <class Cond, class T> struct lazy_enable_if;
+  template <class Cond, class T> struct lazy_disable_if;
+
+  template <bool B, class T = void> struct enable_if_c;
+  template <bool B, class T = void> struct disable_if_c;
+  template <bool B, class T> struct lazy_enable_if_c;
+  template <bool B, class T> struct lazy_disable_if_c;
+}
+
+ + +

1.2  Background

+ + +Sensible operation of template function overloading in C++ relies +on the SFINAE (substitution-failure-is-not-an-error) +principle [3]: if an invalid argument +or return type is formed during the instantiation of a function +template, the instantiation is removed from the overload resolution +set instead of causing a compilation error. The following example, +taken from [1], +demonstrates why this is important: +
+
+int negate(int i) { return -i; }
+
+template <class F>
+typename F::result_type negate(const F& f) { return -f(); }
+
+
+Suppose the compiler encounters the call negate(1). The first +definition is obviously a better match, but the compiler must +nevertheless consider (and instantiate the prototypes) of both +definitions to find this out. Instantiating the latter definition with +F as int would result in: +
+
+int::result_type negate(const int&);
+
+
+where the return type is invalid. If this was an error, adding an unrelated function template +(that was never called) could break otherwise valid code. +Due to the SFINAE principle the above example is not, however, erroneous. +The latter definition of negate is simply removed from the overload resolution set.
+
+The enable_if templates are tools for controlled creation of the SFINAE +conditions.
+
+ + +

2  The enable_if templates

+ + +The names of the enable_if templates have three parts: an optional lazy_ tag, +either enable_if or disable_if, and an optional _c tag. +All eight combinations of these parts are supported. +The meaning of the lazy_ tag is described in Section 3.3. +The second part of the name indicates whether a true condition argument should +enable or disable the current overload. +The third part of the name indicates whether the condition argument is a bool value +(_c suffix), or a type containing a static bool constant named value (no suffix). +The latter version interoperates with Boost.MPL.
+
+The definitions of enable_if_c and enable_if are as follows (we use enable_if templates +unqualified but they are in the boost namespace). +
+
+template <bool B, class T = void>
+struct enable_if_c {
+  typedef T type;
+};
+
+template <class T>
+struct enable_if_c<false, T> {};
+
+template <class Cond, class T = void>
+struct enable_if : public enable_if_c<Cond::value, T> {};
+
+
+An instantiation of the enable_if_c template with the parameter +B as true contains a member type type, defined +to be T. If B is +false, no such member is defined. Thus +enable_if_c<B, T>::type is either a valid or an invalid type +expression, depending on the value of B. +When valid, enable_if_c<B, T>::type equals T. +The enable_if_c template can thus be used for controlling when functions are considered for +overload resolution and when they are not. +For example, the following function is defined for all arithmetic types (according to the +classification of the Boost type_traits library): +
+
+template <class T>
+typename enable_if_c<boost::is_arithmetic<T>::value, T>::type 
+foo(T t) { return t; }
+
+
+The disable_if_c template is provided as well, and has the +same functionality as enable_if_c except for the negated condition. The following +function is enabled for all non-arithmetic types. +
+
+template <class T>
+typename disable_if_c<boost::is_arithmetic<T>::value, T>::type 
+bar(T t) { return t; }
+
+
+For easier syntax in some cases and interoperation with Boost.MPL we provide versions of +the enable_if templates taking any type with a bool member constant named +value as the condition argument. +The MPL bool_, and_, or_, and not_ templates are likely to be +useful for creating such types. Also, the traits classes in the Boost.Type_traits library +follow this convention. +For example, the above example function foo can be alternatively written as: +
+
+template <class T>
+typename enable_if<boost::is_arithmetic<T>, T>::type 
+foo(T t) { return t; }
+
+
+ + +

3  Using enable_if

+ + +The enable_if templates are defined in +boost/utility/enable_if.hpp, which is included by boost/utility.hpp.
+
+The enable_if template can be used either as the return type, or as an +extra argument. For example, the foo function in the previous section could also be written +as: +
+
+template <class T>
+T foo(T t, typename enable_if<boost::is_arithmetic<T> >::type* dummy = 0); 
+
+
Hence, an extra parameter of type void* is added, but it is given +a default value to keep the parameter hidden from client code. +Note that the second template argument was not given to enable_if, as the default +void gives the desired behavior.
+
+Whether to write the enabler as an argument or within the return type is +largely a matter of taste, but for certain functions, only one +alternative is possible: +
  • +Operators have a fixed number of arguments, thus enable_if must be used in the return type. +
  • Constructors and destructors do not have a return type; an extra argument is the only option. +
  • There does not seem to be a way to specify an enabler for a conversion operator. Converting constructors, +however, can have enablers as extra default arguments. +
+ + +

3.1  Enabling template class specializations

+ + +Class template specializations can be enabled or disabled with enable_if. +One extra template parameter needs to be added for the enabler expressions. +This parameter has the default value void. +For example: +
+
+template <class T, class Enable = void> 
+class A { ... };
+
+template <class T>
+class A<T, typename enable_if<is_integral<T> >::type> { ... };
+
+template <class T>
+class A<T, typename enable_if<is_float<T> >::type> { ... };
+
+
Instantiating A with any integral type matches the first specialization, +whereas any floating point type matches the second one. All other types +match the primary template. +The condition can be any compile-time boolean expression that depends on the +template arguments of the class. +Note that again, the second argument to enable_if is not needed; the default (void) +is the correct value.
+
+ + +

3.2  Overlapping enabler conditions

+ + +Once the compiler has examined the enabling conditions and included the +function into the overload resolution set, normal C++ overload resolution +rules are used to select the best matching function. +In particular, there is no ordering between enabling conditions. +Function templates with enabling conditions that are not mutually exclusive can +lead to ambiguities. For example: +
+
+template <class T>
+typename enable_if<boost::is_integral<T>, void>::type 
+foo(T t) {}
+
+template <class T>
+typename enable_if<boost::is_arithmetic<T>, void>::type 
+foo(T t) {}
+
+
+All integral types are also arithmetic. Therefore, say, for the call foo(1), +both conditions are true and both functions are thus in the overload resolution set. +They are both equally good matches and thus ambiguous. +Of course, more than one enabling condition can be simultaneously true as long as +other arguments disambiguate the functions.
+
+The above discussion applies to using enable_if in class template +partial specializations as well.
+
+ + +

3.3  Lazy enable_if

+ + +In some cases it is necessary to avoid instantiating part of a +function signature unless an enabling condition is true. For example: +
+
+template <class T, class U> class mult_traits;
+
+template <class T, class U>
+typename enable_if<is_multipliable<T, U>, typename mult_traits<T, U>::type>::type
+operator*(const T& t, const U& u) { ... }
+
+
Assume the class template mult_traits is a traits class defining +the resulting type of a multiplication operator. The is_multipliable traits +class specifies for which types to enable the operator. Whenever +is_multipliable<A, B>::value is true for some types A and B, +then mult_traits<A, B>::type is defined.
+
+Now, trying to invoke (some other overload) of operator* with, say, operand types C and D +for which is_multipliable<C, D>::value is false +and mult_traits<C, D>::type is not defined is an error on some compilers. +The SFINAE principle is not applied because +the invalid type occurs as an argument to another template. The lazy_enable_if +and lazy_disable_if templates (and their _c versions) can be used in such +situations: +
+
+template<class T, class U>
+typename lazy_enable_if<is_multipliable<T, U>, mult_traits<T, U> >::type
+operator*(const T& t, const U& u) { ... }
+
+
The second argument of lazy_enable_if must be a class type +that defines a nested type named type whenever the first +parameter (the condition) is true.
+
+ + +
Note
+ +Referring to one member type or static constant in a traits class +causes all of the members (type and static constant) of that +specialization to be instantiated. Therefore, if your traits classes +can sometimes contain invalid types, you should use two distinct +templates for describing the conditions and the type mappings. In the +above example, is_multipliable<T, U>::value defines when +mult_traits<T, U>::type is valid.
+
+ + +

3.4  Compiler workarounds

+ + +Some compilers flag functions as ambiguous if the only distinguishing factor is a different +condition in an enabler (even though the functions could never be ambiguous). For example, +some compilers (e.g. GCC 3.2) diagnose the following two functions as ambiguous: +
+
+template <class T>
+typename enable_if<boost::is_arithmetic<T>, T>::type 
+foo(T t);
+
+template <class T>
+typename disable_if<boost::is_arithmetic<T>, T>::type 
+foo(T t);
+
+
Two workarounds can be applied: +
  • +Use an extra dummy parameter which disambiguates the functions. Use a default value for +it to hide the parameter from the caller. For example: +
    +
    +template <class T> struct dummy { dummy(int) {} };
    +
    +template <class T>
    +typename enable_if<boost::is_arithmetic<T>, T>::type 
    +foo(T t, dummy<0> = 0);
    +
    +template <class T>
    +typename disable_if<boost::is_arithmetic<T>, T>::type 
    +foo(T t, dummy<1> = 0);
    +

    +
    +
  • Define the functions in different namespaces and bring them into a common +namespace with using declarations: +
    +
    +namespace A {
    +  template <class T>
    +  typename enable_if<boost::is_arithmetic<T>, T>::type 
    +  foo(T t);
    +}
    +
    +namespace B {
    +  template <class T>
    +  typename disable_if<boost::is_arithmetic<T>, T>::type 
    +  foo(T t);
    +}
    +
    +using A::foo;
    +using B::foo;
    +
    +
    +Note that the second workaround above cannot be used for member +templates. On the other hand, operators do not accept extra arguments, +which makes the first workaround unusable. As the net effect, +neither of the workarounds are of assistance for templated operators that +need to be defined as member functions (assignment and +subscript operators). +
+ + +

4  Acknowledgements

+ +We are grateful to Howard Hinnant, Jason Shirk, Paul Mensonides, and Richard +Smith whose findings have influenced the library.
+
+ + +

References

+
[1]
+Jaakko Järvi, Jeremiah Willcock, Howard Hinnant, and Andrew Lumsdaine. +Function overloading based on arbitrary properties of types. +C/C++ Users Journal, 21(6):25--32, June 2003.
+
+
[2]
+Jaakko Järvi, Jeremiah Willcock, and Andrew Lumsdaine. +Concept-controlled polymorphism. +In Frank Pfennig and Yannis Smaragdakis, editors, Generative + Programming and Component Engineering, volume 2830 of LNCS, pages + 228--244. Springer Verlag, September 2003.
+
+
[3]
+David Vandevoorde and Nicolai M. Josuttis. +C++ Templates: The Complete Guide. +Addison-Wesley, 2002.
+ + + + + +
+ +Contributed by:
+Jaakko Järvi, Jeremiah Willcock and Andrew Lumsdaine
+{jajarvi|jewillco|lums}@osl.iu.edu
+Indiana University
+Open Systems Lab + + + +
+
This document was translated from LATEX by +HEVEA. +
+ + diff --git a/include/boost/utility/enable_if.hpp b/include/boost/utility/enable_if.hpp new file mode 100644 index 0000000..c1f217d --- /dev/null +++ b/include/boost/utility/enable_if.hpp @@ -0,0 +1,69 @@ +// Boost enable_if library + +// Copyright 2003 © The Trustees of Indiana University. + +// Use, modification, and distribution is subject to 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) + +// Authors: Jaakko Järvi (jajarvi at osl.iu.edu) +// Jeremiah Willcock (jewillco at osl.iu.edu) +// Andrew Lumsdaine (lums at osl.iu.edu) + + +#ifndef BOOST_UTILITY_ENABLE_IF_HPP +#define BOOST_UTILITY_ENABLE_IF_HPP + +namespace boost +{ + + template + struct enable_if_c { + typedef T type; + }; + + template + struct enable_if_c {}; + + template + struct enable_if : public enable_if_c {}; + + template + struct lazy_enable_if_c { + typedef typename T::type type; + }; + + template + struct lazy_enable_if_c {}; + + template + struct lazy_enable_if : public lazy_enable_if_c {}; + + + template + struct disable_if_c { + typedef T type; + }; + + template + struct disable_if_c {}; + + template + struct disable_if : public disable_if_c {}; + + template + struct lazy_disable_if_c { + typedef typename T::type type; + }; + + template + struct lazy_disable_if_c {}; + + template + struct lazy_disable_if : public lazy_disable_if_c {}; + + + +} // namespace boost + +#endif From 11d0c114fd6f89cfa678114ab67ad0050883a6c0 Mon Sep 17 00:00:00 2001 From: Beman Dawes Date: Wed, 3 Dec 2003 14:36:38 +0000 Subject: [PATCH 043/144] fix broken link to logo [SVN r21122] --- enable_if.html | 65 ++++++++++++++------------------------------------ 1 file changed, 18 insertions(+), 47 deletions(-) diff --git a/enable_if.html b/enable_if.html index 349189e..eb485c5 100644 --- a/enable_if.html +++ b/enable_if.html @@ -4,7 +4,7 @@ enable_if - + @@ -17,7 +17,7 @@

-enable_if

+enable_if

Copyright 2003 Jaakko Järvi, Jeremiah Willcock, Andrew Lumsdaine.
@@ -42,8 +42,7 @@ in [1] and&n

1.1  Synopsis

-
-namespace boost {
+
namespace boost {
   template <class Cond, class T = void> struct enable_if;
   template <class Cond, class T = void> struct disable_if;
   template <class Cond, class T> struct lazy_enable_if;
@@ -68,9 +67,7 @@ template, the instantiation is removed from the overload resolution
 set instead of causing a compilation error. The following example, 
 taken from [1],
 demonstrates why this is important:
-
-
-int negate(int i) { return -i; }
+
int negate(int i) { return -i; }
 
 template <class F>
 typename F::result_type negate(const F& f) { return -f(); }
@@ -81,9 +78,7 @@ definition is obviously a better match, but the compiler must
 nevertheless consider (and instantiate the prototypes) of both
 definitions to find this out. Instantiating the latter definition with
 F as int would result in:
-
-
-int::result_type negate(const int&);
+
int::result_type negate(const int&);
 
 
where the return type is invalid. If this was an error, adding an unrelated function template @@ -111,9 +106,7 @@ The latter version interoperates with Boost.MPL.

The definitions of enable_if_c and enable_if are as follows (we use enable_if templates unqualified but they are in the boost namespace). -
-
-template <bool B, class T = void>
+
template <bool B, class T = void>
 struct enable_if_c {
   typedef T type;
 };
@@ -136,9 +129,7 @@ The enable_if_c template can thus be used for controlling when function
 overload resolution and when they are not. 
 For example, the following function is defined for all arithmetic types (according to the
 classification of the Boost type_traits library):
-
-
-template <class T>
+
template <class T>
 typename enable_if_c<boost::is_arithmetic<T>::value, T>::type 
 foo(T t) { return t; }
 
@@ -146,9 +137,7 @@ foo(T t) { return t; }
 The disable_if_c template is provided as well, and has the
 same functionality as enable_if_c except for the negated condition. The following
 function is enabled for all non-arithmetic types.
-
-
-template <class T>
+
template <class T>
 typename disable_if_c<boost::is_arithmetic<T>::value, T>::type 
 bar(T t) { return t; }
 
@@ -160,9 +149,7 @@ The MPL bool_, and_, or_, and not_ templates
 useful for creating such types. Also, the traits classes in the Boost.Type_traits library 
 follow this convention. 
 For example, the above example function foo can be alternatively written as:
-
-
-template <class T>
+
template <class T>
 typename enable_if<boost::is_arithmetic<T>, T>::type 
 foo(T t) { return t; }
 
@@ -178,9 +165,7 @@ The enable_if templates are defined in
 The enable_if template can be used either as the return type, or as an 
 extra argument. For example, the foo function in the previous section could also be written
 as:
-
-
-template <class T>
+
template <class T>
 T foo(T t, typename enable_if<boost::is_arithmetic<T> >::type* dummy = 0); 
 
 
Hence, an extra parameter of type void* is added, but it is given @@ -206,9 +191,7 @@ Class template specializations can be enabled or disabled with enable_ifvoid. For example: -
-
-template <class T, class Enable = void> 
+
template <class T, class Enable = void> 
 class A { ... };
 
 template <class T>
@@ -236,9 +219,7 @@ rules are used to select the best matching function.
 In particular, there is no ordering between enabling conditions.
 Function templates with enabling conditions that are not mutually exclusive can 
 lead to ambiguities. For example:
-
-
-template <class T>
+
template <class T>
 typename enable_if<boost::is_integral<T>, void>::type 
 foo(T t) {}
 
@@ -263,9 +244,7 @@ partial specializations as well.
In some cases it is necessary to avoid instantiating part of a function signature unless an enabling condition is true. For example: -
-
-template <class T, class U> class mult_traits;
+
template <class T, class U> class mult_traits;
 
 template <class T, class U>
 typename enable_if<is_multipliable<T, U>, typename mult_traits<T, U>::type>::type
@@ -284,9 +263,7 @@ The SFINAE principle is not applied because
 the invalid type occurs as an argument to another template. The lazy_enable_if 
 and lazy_disable_if templates (and their _c versions) can be used in such
 situations:
-
-
-template<class T, class U>
+
template<class T, class U>
 typename lazy_enable_if<is_multipliable<T, U>, mult_traits<T, U> >::type
 operator*(const T& t, const U& u) { ... }
 
@@ -314,9 +291,7 @@ above example, is_multipliable<T, U>::value defines when
 Some compilers flag functions as ambiguous if the only distinguishing factor is a different 
 condition in an enabler (even though the functions could never be ambiguous). For example,
 some compilers (e.g. GCC 3.2) diagnose the following two functions as ambiguous:
-
-
-template <class T>
+
template <class T>
 typename enable_if<boost::is_arithmetic<T>, T>::type 
 foo(T t);
 
@@ -328,9 +303,7 @@ foo(T t);
 
  • Use an extra dummy parameter which disambiguates the functions. Use a default value for it to hide the parameter from the caller. For example: -
    -
    -template <class T> struct dummy { dummy(int) {} };
    +
    template <class T> struct dummy { dummy(int) {} };
     
     template <class T>
     typename enable_if<boost::is_arithmetic<T>, T>::type 
    @@ -343,9 +316,7 @@ foo(T t, dummy<1> = 0);
     
  • Define the functions in different namespaces and bring them into a common namespace with using declarations: -
    -
    -namespace A {
    +
    namespace A {
       template <class T>
       typename enable_if<boost::is_arithmetic<T>, T>::type 
       foo(T t);
    @@ -414,4 +385,4 @@ Open Systems Lab
     HEVEA.
     
- + \ No newline at end of file From d0eec67a496d07b2a722bd02d2464c0fbcf40444 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaakko=20J=C3=A4rvi?= Date: Fri, 5 Dec 2003 16:31:38 +0000 Subject: [PATCH 044/144] guarded enable_if definitions with BOOST_NO_SFINAE [SVN r21149] --- include/boost/utility/enable_if.hpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/include/boost/utility/enable_if.hpp b/include/boost/utility/enable_if.hpp index c1f217d..0498d36 100644 --- a/include/boost/utility/enable_if.hpp +++ b/include/boost/utility/enable_if.hpp @@ -14,6 +14,13 @@ #ifndef BOOST_UTILITY_ENABLE_IF_HPP #define BOOST_UTILITY_ENABLE_IF_HPP +#include + +// Even the definition of enable_if causes problems on some compilers, +// so it's macroed out for all compilers that do not support SFINAE + +#ifndef BOOST_NO_SFINAE + namespace boost { @@ -62,8 +69,8 @@ namespace boost template struct lazy_disable_if : public lazy_disable_if_c {}; - - } // namespace boost +#endif // BOOST_NO_SFINAE + #endif From bb9a59cab02f0805a9ac064e8582080fa1490ff0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaakko=20J=C3=A4rvi?= Date: Fri, 5 Dec 2003 21:38:43 +0000 Subject: [PATCH 045/144] added dummy versions of enable_if templates for platforms that have BOOST_NO_SFINAE defined [SVN r21154] --- include/boost/utility/enable_if.hpp | 41 +++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/include/boost/utility/enable_if.hpp b/include/boost/utility/enable_if.hpp index 0498d36..df126c1 100644 --- a/include/boost/utility/enable_if.hpp +++ b/include/boost/utility/enable_if.hpp @@ -15,6 +15,7 @@ #define BOOST_UTILITY_ENABLE_IF_HPP #include +#include // Even the definition of enable_if causes problems on some compilers, // so it's macroed out for all compilers that do not support SFINAE @@ -71,6 +72,46 @@ namespace boost } // namespace boost +#else + +namespace boost { + + BOOST_STATIC_CONSTANT(bool, enable_if_does_not_work_on_this_compiler = false); + + template + struct enable_if_c + { BOOST_STATIC_ASSERT(enable_if_does_not_work_on_this_compiler); }; + + template + struct disable_if_c + { BOOST_STATIC_ASSERT(enable_if_does_not_work_on_this_compiler); }; + + template + struct lazy_enable_if_c + { BOOST_STATIC_ASSERT(enable_if_does_not_work_on_this_compiler); }; + + template + struct lazy_disable_if_c + { BOOST_STATIC_ASSERT(enable_if_does_not_work_on_this_compiler); }; + + template + struct enable_if + { BOOST_STATIC_ASSERT(enable_if_does_not_work_on_this_compiler); }; + + template + struct disable_if + { BOOST_STATIC_ASSERT(enable_if_does_not_work_on_this_compiler); }; + + template + struct lazy_enable_if + { BOOST_STATIC_ASSERT(enable_if_does_not_work_on_this_compiler); }; + + template + struct lazy_disable_if + { BOOST_STATIC_ASSERT(enable_if_does_not_work_on_this_compiler); }; + +} // namespace boost + #endif // BOOST_NO_SFINAE #endif From 439c636485208fd9061fb853f00564201b5263de Mon Sep 17 00:00:00 2001 From: Eric Friedman Date: Sat, 6 Dec 2003 03:57:54 +0000 Subject: [PATCH 046/144] Improved workarounds. [SVN r21157] --- include/boost/utility/enable_if.hpp | 56 +++++++++++++++-------------- 1 file changed, 29 insertions(+), 27 deletions(-) diff --git a/include/boost/utility/enable_if.hpp b/include/boost/utility/enable_if.hpp index df126c1..c8b54c4 100644 --- a/include/boost/utility/enable_if.hpp +++ b/include/boost/utility/enable_if.hpp @@ -14,8 +14,7 @@ #ifndef BOOST_UTILITY_ENABLE_IF_HPP #define BOOST_UTILITY_ENABLE_IF_HPP -#include -#include +#include "boost/config.hpp" // Even the definition of enable_if causes problems on some compilers, // so it's macroed out for all compilers that do not support SFINAE @@ -76,39 +75,42 @@ namespace boost namespace boost { - BOOST_STATIC_CONSTANT(bool, enable_if_does_not_work_on_this_compiler = false); + namespace detail { typedef void enable_if_default_T; } - template - struct enable_if_c - { BOOST_STATIC_ASSERT(enable_if_does_not_work_on_this_compiler); }; + template + struct enable_if_does_not_work_on_this_compiler; - template - struct disable_if_c - { BOOST_STATIC_ASSERT(enable_if_does_not_work_on_this_compiler); }; + template + struct enable_if_c : enable_if_does_not_work_on_this_compiler + { }; - template - struct lazy_enable_if_c - { BOOST_STATIC_ASSERT(enable_if_does_not_work_on_this_compiler); }; + template + struct disable_if_c : enable_if_does_not_work_on_this_compiler + { }; - template - struct lazy_disable_if_c - { BOOST_STATIC_ASSERT(enable_if_does_not_work_on_this_compiler); }; + template + struct lazy_enable_if_c : enable_if_does_not_work_on_this_compiler + { }; - template - struct enable_if - { BOOST_STATIC_ASSERT(enable_if_does_not_work_on_this_compiler); }; + template + struct lazy_disable_if_c : enable_if_does_not_work_on_this_compiler + { }; - template - struct disable_if - { BOOST_STATIC_ASSERT(enable_if_does_not_work_on_this_compiler); }; + template + struct enable_if : enable_if_does_not_work_on_this_compiler + { }; - template - struct lazy_enable_if - { BOOST_STATIC_ASSERT(enable_if_does_not_work_on_this_compiler); }; + template + struct disable_if : enable_if_does_not_work_on_this_compiler + { }; - template - struct lazy_disable_if - { BOOST_STATIC_ASSERT(enable_if_does_not_work_on_this_compiler); }; + template + struct lazy_enable_if : enable_if_does_not_work_on_this_compiler + { }; + + template + struct lazy_disable_if : enable_if_does_not_work_on_this_compiler + { }; } // namespace boost From ddfdf8f857cdfaeab858331d887be0c130cec0a8 Mon Sep 17 00:00:00 2001 From: Dave Abrahams Date: Wed, 7 Jan 2004 14:07:21 +0000 Subject: [PATCH 047/144] pro9 workarounds; some ADL protection for is_xxx [SVN r21529] --- include/boost/ref.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/boost/ref.hpp b/include/boost/ref.hpp index 8ff5725..fb7497b 100644 --- a/include/boost/ref.hpp +++ b/include/boost/ref.hpp @@ -40,7 +40,7 @@ public: #else - explicit reference_wrapper(T& t): t_(addressof(t)) {} + explicit reference_wrapper(T& t): t_(boost::addressof(t)) {} #endif From 9630659544a94a9bab01761bc62d11220db96d3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaakko=20J=C3=A4rvi?= Date: Thu, 6 May 2004 22:38:34 +0000 Subject: [PATCH 048/144] fixed a typo [SVN r22754] --- enable_if.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/enable_if.html b/enable_if.html index eb485c5..085fcd9 100644 --- a/enable_if.html +++ b/enable_if.html @@ -303,7 +303,7 @@ foo(T t);
  • Use an extra dummy parameter which disambiguates the functions. Use a default value for it to hide the parameter from the caller. For example: -
    template <class T> struct dummy { dummy(int) {} };
    +
    template <int> struct dummy { dummy(int) {} };
     
     template <class T>
     typename enable_if<boost::is_arithmetic<T>, T>::type 
    
    From b201c6aaf76df67382d86f270db29f0c75a13904 Mon Sep 17 00:00:00 2001
    From: Douglas Gregor 
    Date: Sun, 25 Jul 2004 02:29:29 +0000
    Subject: [PATCH 049/144] Doug Gregor -> Douglas Gregor
    
    [SVN r24016]
    ---
     include/boost/utility/addressof.hpp | 2 +-
     1 file changed, 1 insertion(+), 1 deletion(-)
    
    diff --git a/include/boost/utility/addressof.hpp b/include/boost/utility/addressof.hpp
    index de8dfe5..a5a1425 100644
    --- a/include/boost/utility/addressof.hpp
    +++ b/include/boost/utility/addressof.hpp
    @@ -1,5 +1,5 @@
     // Copyright (C) 2002 Brad King (brad.king@kitware.com) 
    -//                    Doug Gregor (gregod@cs.rpi.edu)
    +//                    Douglas Gregor (gregod@cs.rpi.edu)
     //                    Peter Dimov
     //
     // Permission to copy, use, sell and distribute this software is granted
    
    From ea633e9f6787818f29ed749c209a7519fbb31035 Mon Sep 17 00:00:00 2001
    From: Douglas Gregor 
    Date: Sun, 25 Jul 2004 19:13:06 +0000
    Subject: [PATCH 050/144] License update
    
    [SVN r24048]
    ---
     addressof_test.cpp | 2 +-
     1 file changed, 1 insertion(+), 1 deletion(-)
    
    diff --git a/addressof_test.cpp b/addressof_test.cpp
    index 62d988c..eacb985 100644
    --- a/addressof_test.cpp
    +++ b/addressof_test.cpp
    @@ -1,5 +1,5 @@
     // Copyright (C) 2002 Brad King (brad.king@kitware.com) 
    -//                    Doug Gregor (gregod@cs.rpi.edu)
    +//                    Douglas Gregor (gregod@cs.rpi.edu)
     //
     // Permission to copy, use, sell and distribute this software is granted
     // provided this copyright notice appears in all copies.
    
    From 00ea4449dce473c359ca0171fcb40d2b05c46a15 Mon Sep 17 00:00:00 2001
    From: Douglas Gregor 
    Date: Mon, 26 Jul 2004 00:32:12 +0000
    Subject: [PATCH 051/144] Converted to Boost Software License, Version 1.0
    
    [SVN r24055]
    ---
     include/boost/ref.hpp | 7 +++----
     1 file changed, 3 insertions(+), 4 deletions(-)
    
    diff --git a/include/boost/ref.hpp b/include/boost/ref.hpp
    index fb7497b..65d5d10 100644
    --- a/include/boost/ref.hpp
    +++ b/include/boost/ref.hpp
    @@ -18,10 +18,9 @@
     //  Copyright (C) 2001, 2002 Peter Dimov
     //  Copyright (C) 2002 David Abrahams
     //
    -//  Permission to copy, use, modify, sell and distribute this software
    -//  is granted provided this copyright notice appears in all copies.
    -//  This software is provided "as is" without express or implied
    -//  warranty, and with no claim as to its suitability for any purpose.
    +// 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/bind/ref.html for documentation.
     //
    
    From 8b0e43c411b977fa240533a30b9bbdd9c859dc46 Mon Sep 17 00:00:00 2001
    From: Douglas Gregor 
    Date: Tue, 27 Jul 2004 03:43:34 +0000
    Subject: [PATCH 052/144] Converted to Boost Software License, Version 1.0
    
    [SVN r24096]
    ---
     include/boost/utility/addressof.hpp | 11 +++--------
     1 file changed, 3 insertions(+), 8 deletions(-)
    
    diff --git a/include/boost/utility/addressof.hpp b/include/boost/utility/addressof.hpp
    index a5a1425..603ea60 100644
    --- a/include/boost/utility/addressof.hpp
    +++ b/include/boost/utility/addressof.hpp
    @@ -2,14 +2,9 @@
     //                    Douglas Gregor (gregod@cs.rpi.edu)
     //                    Peter Dimov
     //
    -// 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.
    +// 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
     
    
    From 0b281fd8152f8c60a3a5c2e78730cf2092de7f3e Mon Sep 17 00:00:00 2001
    From: Douglas Gregor 
    Date: Fri, 30 Jul 2004 01:47:08 +0000
    Subject: [PATCH 053/144] License update
    
    [SVN r24175]
    ---
     addressof_test.cpp | 11 +++--------
     1 file changed, 3 insertions(+), 8 deletions(-)
    
    diff --git a/addressof_test.cpp b/addressof_test.cpp
    index eacb985..60f2e23 100644
    --- a/addressof_test.cpp
    +++ b/addressof_test.cpp
    @@ -1,14 +1,9 @@
     // Copyright (C) 2002 Brad King (brad.king@kitware.com) 
     //                    Douglas Gregor (gregod@cs.rpi.edu)
     //
    -// 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.
    +// 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
     
    
    From fe3db5b2d6ca4757704880c41b45526845de6786 Mon Sep 17 00:00:00 2001
    From: John Maddock 
    Date: Tue, 10 Aug 2004 10:34:20 +0000
    Subject: [PATCH 054/144] Updated Beman Dawes' licence statement to use the new
     prefered form of words.
    
    [SVN r24370]
    ---
     checked_delete_test.cpp | 5 +++--
     1 file changed, 3 insertions(+), 2 deletions(-)
    
    diff --git a/checked_delete_test.cpp b/checked_delete_test.cpp
    index 1ffc1fd..41fdc9a 100644
    --- a/checked_delete_test.cpp
    +++ b/checked_delete_test.cpp
    @@ -1,7 +1,8 @@
     //  Boost checked_delete test program  ---------------------------------------//
     
    -//  Copyright Beman Dawes 2001.
    -//  See accompanying license for terms and conditions of use.
    +//  Copyright Beman Dawes 2001.  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/utility for documentation.
     
    
    From 0c1eb3aed1f727850462c7db326da97d0c81dbc0 Mon Sep 17 00:00:00 2001
    From: John Maddock 
    Date: Tue, 10 Aug 2004 12:53:34 +0000
    Subject: [PATCH 055/144] Removed Boost.org copyrights and replaced with
     originating authors copyright instead.
    
    [SVN r24372]
    ---
     include/boost/noncopyable.hpp | 8 +++-----
     1 file changed, 3 insertions(+), 5 deletions(-)
    
    diff --git a/include/boost/noncopyable.hpp b/include/boost/noncopyable.hpp
    index e2c8399..ce05cfa 100644
    --- a/include/boost/noncopyable.hpp
    +++ b/include/boost/noncopyable.hpp
    @@ -1,10 +1,8 @@
     //  Boost noncopyable.hpp header file  --------------------------------------//
     
    -//  (C) Copyright Boost.org 1999-2003. Permission to copy, use, modify, sell
    -//  and distribute this software is granted provided this copyright
    -//  notice appears in all copies. This software is provided "as is" without
    -//  express or implied warranty, and with no claim as to its suitability for
    -//  any purpose.
    +//  (C) Copyright Beman Dawes 1999-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)
     
     //  See http://www.boost.org/libs/utility for documentation.
     
    
    From d0a10f8305f2cdda327b496b1eacb1913664e780 Mon Sep 17 00:00:00 2001
    From: John Maddock 
    Date: Wed, 11 Aug 2004 10:59:33 +0000
    Subject: [PATCH 056/144] Removed boost.org copyright assignments, and reverted
     to orginal author (as based on cvs history).
    
    [SVN r24402]
    ---
     include/boost/checked_delete.hpp | 1 -
     1 file changed, 1 deletion(-)
    
    diff --git a/include/boost/checked_delete.hpp b/include/boost/checked_delete.hpp
    index d7f5212..8d39d5c 100644
    --- a/include/boost/checked_delete.hpp
    +++ b/include/boost/checked_delete.hpp
    @@ -10,7 +10,6 @@
     //
     //  boost/checked_delete.hpp
     //
    -//  Copyright (c) 1999, 2000, 2001, 2002 boost.org
     //  Copyright (c) 2002, 2003 Peter Dimov
     //  Copyright (c) 2003 Daniel Frey
     //  Copyright (c) 2003 Howard Hinnant
    
    From 15284db3f5000afde87d08d8e73da6610f21f785 Mon Sep 17 00:00:00 2001
    From: Douglas Gregor 
    Date: Thu, 12 Aug 2004 17:13:07 +0000
    Subject: [PATCH 057/144] Moved to BSL
    
    [SVN r24446]
    ---
     include/boost/checked_delete.hpp | 7 +++----
     1 file changed, 3 insertions(+), 4 deletions(-)
    
    diff --git a/include/boost/checked_delete.hpp b/include/boost/checked_delete.hpp
    index 8d39d5c..9bb84e8 100644
    --- a/include/boost/checked_delete.hpp
    +++ b/include/boost/checked_delete.hpp
    @@ -14,10 +14,9 @@
     //  Copyright (c) 2003 Daniel Frey
     //  Copyright (c) 2003 Howard Hinnant
     //
    -//  Permission to copy, use, modify, sell and distribute this software
    -//  is granted provided this copyright notice appears in all copies.
    -//  This software is provided "as is" without express or implied
    -//  warranty, and with no claim as to its suitability for any purpose.
    +//  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/utility/checked_delete.html for documentation.
     //
    
    From e347e49955339da5f8a73d851a6042164cc6b363 Mon Sep 17 00:00:00 2001
    From: Dave Abrahams 
    Date: Wed, 18 Aug 2004 17:01:11 +0000
    Subject: [PATCH 058/144] ADL protection
    
    [SVN r24564]
    ---
     include/boost/noncopyable.hpp | 21 +++++++++++++--------
     1 file changed, 13 insertions(+), 8 deletions(-)
    
    diff --git a/include/boost/noncopyable.hpp b/include/boost/noncopyable.hpp
    index ce05cfa..7770bdb 100644
    --- a/include/boost/noncopyable.hpp
    +++ b/include/boost/noncopyable.hpp
    @@ -16,15 +16,20 @@ namespace boost {
     
     //  Contributed by Dave Abrahams
     
    -class noncopyable
    +namespace noncopyable_  // protection from unintended ADL
     {
    - protected:
    -    noncopyable() {}
    -    ~noncopyable() {}
    - private:  // emphasize the following members are private
    -    noncopyable( const noncopyable& );
    -    const noncopyable& operator=( const noncopyable& );
    -};
    +  class noncopyable
    +  {
    +   protected:
    +      noncopyable() {}
    +      ~noncopyable() {}
    +   private:  // emphasize the following members are private
    +      noncopyable( const noncopyable& );
    +      const noncopyable& operator=( const noncopyable& );
    +  };
    +}
    +
    +typedef noncopyable_::noncopyable noncopyable;
     
     } // namespace boost
     
    
    From dded3779aec82caaeb08f112caa6afeb1799feff Mon Sep 17 00:00:00 2001
    From: Dave Abrahams 
    Date: Thu, 19 Aug 2004 13:12:35 +0000
    Subject: [PATCH 059/144] ADL protection
    
    [SVN r24595]
    ---
     include/boost/noncopyable.hpp | 2 --
     1 file changed, 2 deletions(-)
    
    diff --git a/include/boost/noncopyable.hpp b/include/boost/noncopyable.hpp
    index 7770bdb..019413e 100644
    --- a/include/boost/noncopyable.hpp
    +++ b/include/boost/noncopyable.hpp
    @@ -29,8 +29,6 @@ namespace noncopyable_  // protection from unintended ADL
       };
     }
     
    -typedef noncopyable_::noncopyable noncopyable;
    -
     } // namespace boost
     
     #endif  // BOOST_NONCOPYABLE_HPP_INCLUDED
    
    From 3887539e0a39e9aa84f864628b9c7af78cb96672 Mon Sep 17 00:00:00 2001
    From: Dave Abrahams 
    Date: Fri, 20 Aug 2004 17:17:06 +0000
    Subject: [PATCH 060/144] fix noncopyable, finally
    
    [SVN r24618]
    ---
     include/boost/noncopyable.hpp | 2 ++
     1 file changed, 2 insertions(+)
    
    diff --git a/include/boost/noncopyable.hpp b/include/boost/noncopyable.hpp
    index 019413e..7770bdb 100644
    --- a/include/boost/noncopyable.hpp
    +++ b/include/boost/noncopyable.hpp
    @@ -29,6 +29,8 @@ namespace noncopyable_  // protection from unintended ADL
       };
     }
     
    +typedef noncopyable_::noncopyable noncopyable;
    +
     } // namespace boost
     
     #endif  // BOOST_NONCOPYABLE_HPP_INCLUDED
    
    From 3c15c38268cad6705b7fe010eb46d41fb578b77f Mon Sep 17 00:00:00 2001
    From: Dave Abrahams 
    Date: Mon, 30 Aug 2004 01:31:40 +0000
    Subject: [PATCH 061/144] added copyright/license
    
    [SVN r24814]
    ---
     ref_ct_test.cpp | 5 +++++
     ref_test.cpp    | 4 ++++
     2 files changed, 9 insertions(+)
    
    diff --git a/ref_ct_test.cpp b/ref_ct_test.cpp
    index d9af429..f072537 100644
    --- a/ref_ct_test.cpp
    +++ b/ref_ct_test.cpp
    @@ -1,3 +1,8 @@
    +// Copyright David Abrahams and Aleksey Gurtovoy
    +// 2002-2004. 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)
    +
     // compile-time test for "boost/ref.hpp" header content
     // see 'ref_test.cpp' for run-time part
     
    diff --git a/ref_test.cpp b/ref_test.cpp
    index 1cfb5dd..ef4775f 100644
    --- a/ref_test.cpp
    +++ b/ref_test.cpp
    @@ -1,3 +1,7 @@
    +// Copyright David Abrahams and Aleksey Gurtovoy
    +// 2002-2004. 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)
     
     // run-time test for "boost/ref.hpp" header content
     // see 'ref_ct_test.cpp' for compile-time part
    
    From c9b9b074386d59eacb75247221cd7ecdc945f019 Mon Sep 17 00:00:00 2001
    From: Aleksey Gurtovoy 
    Date: Tue, 5 Oct 2004 15:45:52 +0000
    Subject: [PATCH 062/144] c++boost.gif -> boost.png replacement
    
    [SVN r25573]
    ---
     checked_delete.html | 2 +-
     enable_if.html      | 2 +-
     2 files changed, 2 insertions(+), 2 deletions(-)
    
    diff --git a/checked_delete.html b/checked_delete.html
    index 4af2ae7..20ffef0 100644
    --- a/checked_delete.html
    +++ b/checked_delete.html
    @@ -8,7 +8,7 @@
     		
    - c++boost.gif (8819 bytes) + boost.png (6897 bytes)

    checked_delete.hpp

    diff --git a/enable_if.html b/enable_if.html index 085fcd9..7a00225 100644 --- a/enable_if.html +++ b/enable_if.html @@ -17,7 +17,7 @@

    -enable_if

    +enable_if

    Copyright 2003 Jaakko Järvi, Jeremiah Willcock, Andrew Lumsdaine.
    From a8c403d864a41684baa95d2f9636ca5fe3a162be Mon Sep 17 00:00:00 2001 From: Aleksey Gurtovoy Date: Sun, 28 Nov 2004 03:35:12 +0000 Subject: [PATCH 063/144] merge RC_1_32_0 fixes [SVN r26328] --- include/boost/ref.hpp | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/include/boost/ref.hpp b/include/boost/ref.hpp index 65d5d10..3745e7c 100644 --- a/include/boost/ref.hpp +++ b/include/boost/ref.hpp @@ -73,18 +73,13 @@ template inline reference_wrapper BOOST_REF_CONST cref(T const # undef BOOST_REF_CONST # ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION + template class is_reference_wrapper : public mpl::false_ { }; -template -class is_reference_wrapper > - : public mpl::true_ -{ -}; - template class unwrap_reference { @@ -92,12 +87,30 @@ class unwrap_reference typedef T type; }; -template -class unwrap_reference > -{ - public: - typedef T type; -}; +# define AUX_REFERENCE_WRAPPER_METAFUNCTIONS_DEF(X) \ +template \ +class is_reference_wrapper< X > \ + : public mpl::true_ \ +{ \ +}; \ +\ +template \ +class unwrap_reference< X > \ +{ \ + public: \ + typedef T type; \ +}; \ +/**/ + +AUX_REFERENCE_WRAPPER_METAFUNCTIONS_DEF(reference_wrapper) +#if !defined(BOOST_NO_CV_SPECIALIZATIONS) +AUX_REFERENCE_WRAPPER_METAFUNCTIONS_DEF(reference_wrapper const) +AUX_REFERENCE_WRAPPER_METAFUNCTIONS_DEF(reference_wrapper volatile) +AUX_REFERENCE_WRAPPER_METAFUNCTIONS_DEF(reference_wrapper const volatile) +#endif + +# undef AUX_REFERENCE_WRAPPER_METAFUNCTIONS_DEF + # else // no partial specialization } // namespace boost From 65f05c3d4188458deb7b9fe6063534bfbc393e3b Mon Sep 17 00:00:00 2001 From: Aleksey Gurtovoy Date: Sun, 28 Nov 2004 04:44:21 +0000 Subject: [PATCH 064/144] merge RC_1_32_0 fixes [SVN r26333] --- enable_if.html | 2 +- ref_ct_test.cpp | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/enable_if.html b/enable_if.html index 7a00225..2b6ac0a 100644 --- a/enable_if.html +++ b/enable_if.html @@ -128,7 +128,7 @@ When valid, enable_if_c<B, T>::type equals T. The enable_if_c template can thus be used for controlling when functions are considered for overload resolution and when they are not. For example, the following function is defined for all arithmetic types (according to the -classification of the Boost type_traits library): +classification of the Boost type_traits library):
    template <class T>
     typename enable_if_c<boost::is_arithmetic<T>::value, T>::type 
     foo(T t) { return t; }
    diff --git a/ref_ct_test.cpp b/ref_ct_test.cpp
    index f072537..a3b5eea 100644
    --- a/ref_ct_test.cpp
    +++ b/ref_ct_test.cpp
    @@ -7,8 +7,12 @@
     // see 'ref_test.cpp' for run-time part
     
     #include 
    -#include 
    +#include 
    +#include 
     #include 
    +#include 
    +
    +#include 
     
     namespace {
     
    @@ -35,13 +39,23 @@ void is_reference_wrapper_test(T)
     template< typename R, typename Ref >
     void cxx_reference_test(Ref)
     {
    +#if BOOST_WORKAROUND(__BORLANDC__, < 0x600)
    +    typedef typename boost::remove_const::type ref;
    +    BOOST_STATIC_ASSERT((boost::is_same::value));
    +#else
         BOOST_STATIC_ASSERT((boost::is_same::value));
    +#endif
     }
     
     template< typename R, typename Ref >
     void unwrap_reference_test(Ref)
     {
    +#if BOOST_WORKAROUND(__BORLANDC__, < 0x600)
    +    typedef typename boost::remove_const::type ref;
    +    typedef typename boost::unwrap_reference::type type;
    +#else
         typedef typename boost::unwrap_reference::type type;
    +#endif
         BOOST_STATIC_ASSERT((boost::is_same::value));
     }
     
    
    From f9eab708f1fcc5fdc0227561359477bae81a042a Mon Sep 17 00:00:00 2001
    From: Stefan Slapeta 
    Date: Thu, 3 Feb 2005 13:48:49 +0000
    Subject: [PATCH 065/144] replaced BOOST_TEST
    
    [SVN r27054]
    ---
     addressof_test.cpp | 8 ++++----
     ref_test.cpp       | 8 ++++----
     2 files changed, 8 insertions(+), 8 deletions(-)
    
    diff --git a/addressof_test.cpp b/addressof_test.cpp
    index 60f2e23..2630f27 100644
    --- a/addressof_test.cpp
    +++ b/addressof_test.cpp
    @@ -26,16 +26,16 @@ int test_main(int, char*[])
       nonaddressable* px = new nonaddressable();
     
       nonaddressable& x = *px;
    -  BOOST_TEST(boost::addressof(x) == px);
    +  BOOST_CHECK(boost::addressof(x) == px);
     
       const nonaddressable& cx = *px;
    -  BOOST_TEST(boost::addressof(cx) == static_cast(px));
    +  BOOST_CHECK(boost::addressof(cx) == static_cast(px));
     
       volatile nonaddressable& vx = *px;
    -  BOOST_TEST(boost::addressof(vx) == static_cast(px));
    +  BOOST_CHECK(boost::addressof(vx) == static_cast(px));
     
       const volatile nonaddressable& cvx = *px;
    -  BOOST_TEST(boost::addressof(cvx) == static_cast(px));
    +  BOOST_CHECK(boost::addressof(cvx) == static_cast(px));
       
       return 0;
     }
    diff --git a/ref_test.cpp b/ref_test.cpp
    index ef4775f..63fc9e5 100644
    --- a/ref_test.cpp
    +++ b/ref_test.cpp
    @@ -60,11 +60,11 @@ struct ref_wrapper
     
         static void test(T x)
         {
    -        BOOST_TEST(passthru(ref(x)) == &x);
    -        BOOST_TEST(&ref(x).get() == &x);
    +        BOOST_CHECK(passthru(ref(x)) == &x);
    +        BOOST_CHECK(&ref(x).get() == &x);
     
    -        BOOST_TEST(cref_passthru(cref(x)) == &x);
    -        BOOST_TEST(&cref(x).get() == &x);
    +        BOOST_CHECK(cref_passthru(cref(x)) == &x);
    +        BOOST_CHECK(&cref(x).get() == &x);
         }
     };
     
    
    From 109d1d8c8d4a1682fb5fd3fdbb432a2d965459f8 Mon Sep 17 00:00:00 2001
    From: Eric Niebler 
    Date: Mon, 14 Mar 2005 23:03:42 +0000
    Subject: [PATCH 066/144] work-around for Borland addressof(array) bug and
     associated tests
    
    [SVN r27656]
    ---
     addressof_test.cpp                  | 10 +++++++++-
     include/boost/utility/addressof.hpp | 16 ++++++++++++++++
     2 files changed, 25 insertions(+), 1 deletion(-)
    
    diff --git a/addressof_test.cpp b/addressof_test.cpp
    index 2630f27..51294bd 100644
    --- a/addressof_test.cpp
    +++ b/addressof_test.cpp
    @@ -36,6 +36,14 @@ int test_main(int, char*[])
     
       const volatile nonaddressable& cvx = *px;
       BOOST_CHECK(boost::addressof(cvx) == static_cast(px));
    -  
    +
    +  int nrg[3] = {1,2,3};
    +  int (*pnrg)[3] = &nrg;
    +  BOOST_CHECK(boost::addressof(nrg) == pnrg);
    +
    +  int const cnrg[3] = {1,2,3};
    +  int const (*pcnrg)[3] = &cnrg;
    +  BOOST_CHECK(boost::addressof(cnrg) == pcnrg);
    +
       return 0;
     }
    diff --git a/include/boost/utility/addressof.hpp b/include/boost/utility/addressof.hpp
    index 603ea60..6d97fca 100644
    --- a/include/boost/utility/addressof.hpp
    +++ b/include/boost/utility/addressof.hpp
    @@ -33,6 +33,22 @@ addressof(T& v)
            &const_cast(reinterpret_cast(v)));
     }
     
    +// Borland doesn't like casting an array reference to a char reference
    +// but these overloads work around the problem.
    +# if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
    +template
    +T (*addressof(T (&t)[N]))[N]
    +{
    +   return reinterpret_cast(&t);
    +}
    +
    +template
    +const T (*addressof(const T (&t)[N]))[N]
    +{
    +   return reinterpret_cast(&t);
    +}
    +# endif
    +
     }
     
     #endif // BOOST_UTILITY_ADDRESSOF_HPP
    
    From a41e0d7955b3a76720a2e6fd6f46437989822e7b Mon Sep 17 00:00:00 2001
    From: Peter Dimov 
    Date: Wed, 16 Mar 2005 22:02:22 +0000
    Subject: [PATCH 067/144] Removed type_traits include, added more tests
    
    [SVN r27712]
    ---
     addressof_test.cpp                  | 99 +++++++++++++++++++++--------
     include/boost/utility/addressof.hpp | 12 ++--
     2 files changed, 80 insertions(+), 31 deletions(-)
    
    diff --git a/addressof_test.cpp b/addressof_test.cpp
    index 51294bd..9619cc3 100644
    --- a/addressof_test.cpp
    +++ b/addressof_test.cpp
    @@ -7,43 +7,88 @@
     
     // For more information, see http://www.boost.org
     
    -#define BOOST_INCLUDE_MAIN
    -#include 
    -#include 
    +
    +#include 
    +
    +#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
    +#pragma warning(push, 3)
    +#endif
    +
    +#include 
    +
    +#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
    +#pragma warning(pop)
    +#endif
    +
    +#include 
    +
    +template void scalar_test( T * = 0 )
    +{
    +    T* px = new T();
    +
    +    T& x = *px;
    +    BOOST_TEST( boost::addressof(x) == px );
    +
    +    const T& cx = *px;
    +    const T* pcx = boost::addressof(cx);
    +    BOOST_TEST( pcx == px );
    +
    +    volatile T& vx = *px;
    +    volatile T* pvx = boost::addressof(vx);
    +    BOOST_TEST( pvx == px );
    +
    +    const volatile T& cvx = *px;
    +    const volatile T* pcvx = boost::addressof(cvx);
    +    BOOST_TEST( pcvx == px );
    +
    +    delete px;
    +}
    +
    +template void array_test( T * = 0 )
    +{
    +    T nrg[3] = {1,2,3};
    +    T (*pnrg)[3] = &nrg;
    +    BOOST_TEST( boost::addressof(nrg) == pnrg );
    +
    +    T const cnrg[3] = {1,2,3};
    +    T const (*pcnrg)[3] = &cnrg;
    +    BOOST_TEST( boost::addressof(cnrg) == pcnrg );
    +}
    +
    +struct addressable
    +{
    +    addressable( int = 0 )
    +    {
    +    }
    +};
     
     struct useless_type {};
     
     class nonaddressable {
     public:
    -  void dummy(); // Silence GCC warning: all member of class are private
    +
    +    nonaddressable( int = 0 )
    +    {
    +    }
    +
    +    void dummy(); // Silence GCC warning: all member of class are private
     
     private:
    -  useless_type operator&() const;
    +
    +    useless_type operator&() const;
     };
     
    -int test_main(int, char*[])
    +int main()
     {
    -  nonaddressable* px = new nonaddressable();
    +    scalar_test();
    +    scalar_test();
    +    scalar_test();
    +    scalar_test();
     
    -  nonaddressable& x = *px;
    -  BOOST_CHECK(boost::addressof(x) == px);
    +    array_test();
    +    array_test();
    +    array_test();
    +    array_test();
     
    -  const nonaddressable& cx = *px;
    -  BOOST_CHECK(boost::addressof(cx) == static_cast(px));
    -
    -  volatile nonaddressable& vx = *px;
    -  BOOST_CHECK(boost::addressof(vx) == static_cast(px));
    -
    -  const volatile nonaddressable& cvx = *px;
    -  BOOST_CHECK(boost::addressof(cvx) == static_cast(px));
    -
    -  int nrg[3] = {1,2,3};
    -  int (*pnrg)[3] = &nrg;
    -  BOOST_CHECK(boost::addressof(nrg) == pnrg);
    -
    -  int const cnrg[3] = {1,2,3};
    -  int const (*pcnrg)[3] = &cnrg;
    -  BOOST_CHECK(boost::addressof(cnrg) == pcnrg);
    -
    -  return 0;
    +    return boost::report_errors();
     }
    diff --git a/include/boost/utility/addressof.hpp b/include/boost/utility/addressof.hpp
    index 6d97fca..7629488 100644
    --- a/include/boost/utility/addressof.hpp
    +++ b/include/boost/utility/addressof.hpp
    @@ -13,9 +13,6 @@
     
     # include 
     # include 
    -# if BOOST_WORKAROUND(BOOST_MSVC, == 1300)
    -#  include 
    -# endif
     
     namespace boost {
     
    @@ -23,7 +20,14 @@ namespace boost {
     
     // VC7 strips const from nested classes unless we add indirection here
     # if BOOST_WORKAROUND(BOOST_MSVC, == 1300)
    -template  typename add_pointer::type
    +
    +template struct _addp
    +{
    +    typedef T * type;
    +};
    +    
    +template  typename _addp::type
    +
     # else
     template  T*
     # endif
    
    From b93f58c58e043bd9c3e3c4ab50f050a230ad8748 Mon Sep 17 00:00:00 2001
    From: Peter Dimov 
    Date: Sun, 25 Sep 2005 21:54:19 +0000
    Subject: [PATCH 068/144] Made the Boost logo link to the home page
    
    [SVN r31112]
    ---
     checked_delete.html | 5 ++---
     1 file changed, 2 insertions(+), 3 deletions(-)
    
    diff --git a/checked_delete.html b/checked_delete.html
    index 20ffef0..c123fd5 100644
    --- a/checked_delete.html
    +++ b/checked_delete.html
    @@ -7,10 +7,9 @@
     	
     		
    -				
    -				
    
    From a3c8d13b70e477f6bfc65ad208d6248b7aec4aa9 Mon Sep 17 00:00:00 2001
    From: Peter Dimov 
    Date: Mon, 27 Feb 2006 21:57:38 +0000
    Subject: [PATCH 069/144] Borland 5.81 fix (Alisdair Meredith)
    
    [SVN r33161]
    ---
     include/boost/ref.hpp | 5 +++--
     1 file changed, 3 insertions(+), 2 deletions(-)
    
    diff --git a/include/boost/ref.hpp b/include/boost/ref.hpp
    index 3745e7c..ab09ae7 100644
    --- a/include/boost/ref.hpp
    +++ b/include/boost/ref.hpp
    @@ -10,6 +10,7 @@
     #include 
     #include 
     #include 
    +#include 
     
     //
     //  ref.hpp - ref/cref, useful helper functions
    @@ -33,7 +34,7 @@ template class reference_wrapper
     public:
         typedef T type;
     
    -#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
    +#if defined( BOOST_MSVC ) && BOOST_WORKAROUND( BOOST_MSVC, < 1300 )
     
         explicit reference_wrapper(T& t): t_(&t) {}
     
    @@ -54,7 +55,7 @@ private:
         T* t_;
     };
     
    -# if defined(__BORLANDC__) && (__BORLANDC__ <= 0x570)
    +# if defined( __BORLANDC__ ) && BOOST_WORKAROUND( __BORLANDC__, BOOST_TESTED_AT(0x581) )
     #  define BOOST_REF_CONST
     # else
     #  define BOOST_REF_CONST const
    
    From d64c92281ce0279be13d0fa29c70166109199881 Mon Sep 17 00:00:00 2001
    From: Peter Dimov 
    Date: Thu, 9 Nov 2006 20:34:33 +0000
    Subject: [PATCH 070/144] License/copyright edits
    
    [SVN r35958]
    ---
     checked_delete.html | 7 +++----
     1 file changed, 3 insertions(+), 4 deletions(-)
    
    diff --git a/checked_delete.html b/checked_delete.html
    index c123fd5..33b5bcb 100644
    --- a/checked_delete.html
    +++ b/checked_delete.html
    @@ -115,9 +115,8 @@ template<class T> struct checked_array_deleter
     		


    - Copyright © 2002 by Peter Dimov. 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.

    + Copyright © 2002 by Peter Dimov. 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.

    From e134f0de97d0fc6d8982d073044836f2f203747b Mon Sep 17 00:00:00 2001 From: John Maddock Date: Sat, 15 Mar 2008 18:41:51 +0000 Subject: [PATCH 071/144] Fix some inspection report issues. [SVN r43633] --- enable_if.html | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/enable_if.html b/enable_if.html index 2b6ac0a..a17a290 100644 --- a/enable_if.html +++ b/enable_if.html @@ -366,17 +366,18 @@ David Vandevoorde and Nicolai M. Josuttis. C++ Templates: The Complete Guide. Addison-Wesley, 2002. - - - - -
    - -Contributed by:
    -Jaakko Järvi, Jeremiah Willcock and Andrew Lumsdaine
    +
    +

    Copyright Jaakko Järvi, Jeremiah Willcock and Andrew Lumsdaine
    {jajarvi|jewillco|lums}@osl.iu.edu
    Indiana University
    -Open Systems Lab +Open Systems Lab
    +Use, modification and distribution are subject to 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 +). +

    From 4a07f2ed5395bc0acc9b25aea265edbc6c77efdc Mon Sep 17 00:00:00 2001 From: Marshall Clow Date: Wed, 2 Apr 2008 01:42:32 +0000 Subject: [PATCH 072/144] Replaced all occurrences of non-ASCII copyright symbol with '(c)' for people using non-ASCII code pages [SVN r43992] --- include/boost/utility/enable_if.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/boost/utility/enable_if.hpp b/include/boost/utility/enable_if.hpp index c8b54c4..d77d108 100644 --- a/include/boost/utility/enable_if.hpp +++ b/include/boost/utility/enable_if.hpp @@ -1,6 +1,6 @@ // Boost enable_if library -// Copyright 2003 © The Trustees of Indiana University. +// Copyright 2003 (c) The Trustees of Indiana University. // Use, modification, and distribution is subject to the Boost Software // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at From 286a7fa7678a3bd680e2fd5ddc3ac15b8ebc5148 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Mon, 21 Apr 2008 21:42:29 +0000 Subject: [PATCH 073/144] Fix #1846. [SVN r44705] --- include/boost/utility/addressof.hpp | 43 ++++++++++++++++------------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/include/boost/utility/addressof.hpp b/include/boost/utility/addressof.hpp index 7629488..8e0a586 100644 --- a/include/boost/utility/addressof.hpp +++ b/include/boost/utility/addressof.hpp @@ -1,6 +1,7 @@ // Copyright (C) 2002 Brad King (brad.king@kitware.com) // Douglas Gregor (gregod@cs.rpi.edu) -// Peter Dimov +// +// Copyright (C) 2002, 2008 Peter Dimov // // Distributed under the Boost Software License, Version 1.0. (See // accompanying file LICENSE_1_0.txt or copy at @@ -14,27 +15,31 @@ # include # include -namespace boost { - -// Do not make addressof() inline. Breaks MSVC 7. (Peter Dimov) - -// VC7 strips const from nested classes unless we add indirection here -# if BOOST_WORKAROUND(BOOST_MSVC, == 1300) - -template struct _addp +namespace boost { - typedef T * type; + +namespace detail +{ + +template struct addressof_impl +{ + static inline T * f( T & v, long ) + { + return reinterpret_cast( + &const_cast(reinterpret_cast(v))); + } + + static inline T * f( T * v, int ) + { + return v; + } }; - -template typename _addp::type -# else -template T* -# endif -addressof(T& v) +} // namespace detail + +template T * addressof( T & v ) { - return reinterpret_cast( - &const_cast(reinterpret_cast(v))); + return boost::detail::addressof_impl::f( v, 0 ); } // Borland doesn't like casting an array reference to a char reference @@ -53,6 +58,6 @@ const T (*addressof(const T (&t)[N]))[N] } # endif -} +} // namespace boost #endif // BOOST_UTILITY_ADDRESSOF_HPP From b6e7b0be846af659da38c993715c4fa347aff964 Mon Sep 17 00:00:00 2001 From: Beman Dawes Date: Sat, 28 Jun 2008 13:45:21 +0000 Subject: [PATCH 074/144] =?UTF-8?q?With=20his=20kind=20permission,=20chang?= =?UTF-8?q?e=20Jaakko=20"J=C3=A4rvi"=20to=20"Jarvi"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [SVN r46808] --- include/boost/ref.hpp | 2 +- include/boost/utility/enable_if.hpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/boost/ref.hpp b/include/boost/ref.hpp index ab09ae7..330ca65 100644 --- a/include/boost/ref.hpp +++ b/include/boost/ref.hpp @@ -15,7 +15,7 @@ // // ref.hpp - ref/cref, useful helper functions // -// Copyright (C) 1999, 2000 Jaakko Järvi (jaakko.jarvi@cs.utu.fi) +// Copyright (C) 1999, 2000 Jaakko Jarvi (jaakko.jarvi@cs.utu.fi) // Copyright (C) 2001, 2002 Peter Dimov // Copyright (C) 2002 David Abrahams // diff --git a/include/boost/utility/enable_if.hpp b/include/boost/utility/enable_if.hpp index d77d108..d292c6a 100644 --- a/include/boost/utility/enable_if.hpp +++ b/include/boost/utility/enable_if.hpp @@ -6,7 +6,7 @@ // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) -// Authors: Jaakko Järvi (jajarvi at osl.iu.edu) +// Authors: Jaakko Jarvi (jajarvi at osl.iu.edu) // Jeremiah Willcock (jewillco at osl.iu.edu) // Andrew Lumsdaine (lums at osl.iu.edu) From eaeb3ca8d2d02423944bc076e0d85385b4179143 Mon Sep 17 00:00:00 2001 From: Ronald Garcia Date: Thu, 10 Jul 2008 19:28:49 +0000 Subject: [PATCH 075/144] Added unwrap_ref. [SVN r47295] --- include/boost/ref.hpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/include/boost/ref.hpp b/include/boost/ref.hpp index 330ca65..9c996ab 100644 --- a/include/boost/ref.hpp +++ b/include/boost/ref.hpp @@ -173,6 +173,12 @@ class unwrap_reference # endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION +template inline typename unwrap_reference::type& +unwrap_ref(T& t) +{ + return t; +} + } // namespace boost #endif // #ifndef BOOST_REF_HPP_INCLUDED From 26b87da9ca097a4f535923e6a63837bea98b2cf2 Mon Sep 17 00:00:00 2001 From: Ronald Garcia Date: Thu, 10 Jul 2008 19:29:02 +0000 Subject: [PATCH 076/144] Added tests for unwrap_ref. [SVN r47296] --- ref_test.cpp | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/ref_test.cpp b/ref_test.cpp index 63fc9e5..93468ee 100644 --- a/ref_test.cpp +++ b/ref_test.cpp @@ -68,11 +68,53 @@ struct ref_wrapper } }; +struct copy_counter { + static int count_; + copy_counter(copy_counter const& other) { + ++count_; + } + copy_counter() {} + static void reset() { count_ = 0; } + static int count() { return copy_counter::count_; } +}; + +int copy_counter::count_ = 0; + } // namespace unnamed +template +void do_unwrap(T t) { + + /* typename unwrap_reference::type& lt = */ + unwrap_ref(t); + +} + +void unwrap_test() { + + int i = 3; + const int ci = 2; + + do_unwrap(i); + do_unwrap(ci); + do_unwrap(ref(i)); + do_unwrap(cref(ci)); + do_unwrap(ref(ci)); + + copy_counter cc; + BOOST_CHECK(cc.count() == 0); + + do_unwrap(cc); + do_unwrap(ref(cc)); + do_unwrap(cref(cc)); + + BOOST_CHECK(cc.count() == 1); +} + int test_main(int, char * []) { ref_wrapper::test(1); ref_wrapper::test(1); + unwrap_test(); return 0; } From e00f569741c0baf86216e43b56af9e00f5425a63 Mon Sep 17 00:00:00 2001 From: Ronald Garcia Date: Thu, 10 Jul 2008 23:01:26 +0000 Subject: [PATCH 077/144] Added an anonymous unwrapping test. [SVN r47297] --- ref_test.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/ref_test.cpp b/ref_test.cpp index 93468ee..d4237b4 100644 --- a/ref_test.cpp +++ b/ref_test.cpp @@ -109,6 +109,7 @@ void unwrap_test() { do_unwrap(cref(cc)); BOOST_CHECK(cc.count() == 1); + BOOST_CHECK(unwrap_ref(ref(cc)).count() == 1); } int test_main(int, char * []) From 239c2db98f977039729b20ee84f82fe34436bfe1 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Sun, 1 Mar 2009 17:04:14 +0000 Subject: [PATCH 078/144] Refs #2128 (fixed in trunk.) [SVN r51512] --- include/boost/ref.hpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/include/boost/ref.hpp b/include/boost/ref.hpp index 9c996ab..6058d69 100644 --- a/include/boost/ref.hpp +++ b/include/boost/ref.hpp @@ -179,6 +179,11 @@ unwrap_ref(T& t) return t; } +template inline T* get_pointer( reference_wrapper const & r ) +{ + return r.get_pointer(); +} + } // namespace boost #endif // #ifndef BOOST_REF_HPP_INCLUDED From 729842ac994171cb5757ed4ccb84f7f1938cbf97 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Fri, 20 Mar 2009 17:14:00 +0000 Subject: [PATCH 079/144] Attempt to fix addressof in trunk to handle classes with conversion operators. Refs #2878. [SVN r51872] --- addressof_fn_test.cpp | 76 +++++++++++++++++++++++ addressof_test2.cpp | 95 +++++++++++++++++++++++++++++ include/boost/utility/addressof.hpp | 16 +++++ 3 files changed, 187 insertions(+) create mode 100644 addressof_fn_test.cpp create mode 100644 addressof_test2.cpp diff --git a/addressof_fn_test.cpp b/addressof_fn_test.cpp new file mode 100644 index 0000000..0d043bf --- /dev/null +++ b/addressof_fn_test.cpp @@ -0,0 +1,76 @@ +#include + +#if defined(BOOST_MSVC) +#pragma warning(disable: 4786) // identifier truncated in debug info +#pragma warning(disable: 4710) // function not inlined +#pragma warning(disable: 4711) // function selected for automatic inline expansion +#pragma warning(disable: 4514) // unreferenced inline removed +#endif + +// addressof_fn_test.cpp: addressof( f ) +// +// Copyright (c) 2008, 2009 Peter Dimov +// +// 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 + + +void f0() +{ +} + +void f1(int) +{ +} + +void f2(int, int) +{ +} + +void f3(int, int, int) +{ +} + +void f4(int, int, int, int) +{ +} + +void f5(int, int, int, int, int) +{ +} + +void f6(int, int, int, int, int, int) +{ +} + +void f7(int, int, int, int, int, int, int) +{ +} + +void f8(int, int, int, int, int, int, int, int) +{ +} + +void f9(int, int, int, int, int, int, int, int, int) +{ +} + +int main() +{ + BOOST_TEST( boost::addressof( f0 ) == &f0 ); + BOOST_TEST( boost::addressof( f1 ) == &f1 ); + BOOST_TEST( boost::addressof( f2 ) == &f2 ); + BOOST_TEST( boost::addressof( f3 ) == &f3 ); + BOOST_TEST( boost::addressof( f4 ) == &f4 ); + BOOST_TEST( boost::addressof( f5 ) == &f5 ); + BOOST_TEST( boost::addressof( f6 ) == &f6 ); + BOOST_TEST( boost::addressof( f7 ) == &f7 ); + BOOST_TEST( boost::addressof( f8 ) == &f8 ); + BOOST_TEST( boost::addressof( f9 ) == &f9 ); + + return boost::report_errors(); +} diff --git a/addressof_test2.cpp b/addressof_test2.cpp new file mode 100644 index 0000000..b1c36f8 --- /dev/null +++ b/addressof_test2.cpp @@ -0,0 +1,95 @@ +// Copyright (C) 2002 Brad King (brad.king@kitware.com) +// Douglas Gregor (gregod@cs.rpi.edu) +// +// Copyright 2009 Peter Dimov +// +// 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 + + +#include + +#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300) +#pragma warning(push, 3) +#endif + +#include + +#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300) +#pragma warning(pop) +#endif + +#include + +template void scalar_test( T * = 0 ) +{ + T* px = new T(); + + T& x = *px; + BOOST_TEST( boost::addressof(x) == px ); + + const T& cx = *px; + const T* pcx = boost::addressof(cx); + BOOST_TEST( pcx == px ); + + volatile T& vx = *px; + volatile T* pvx = boost::addressof(vx); + BOOST_TEST( pvx == px ); + + const volatile T& cvx = *px; + const volatile T* pcvx = boost::addressof(cvx); + BOOST_TEST( pcvx == px ); + + delete px; +} + +template void array_test( T * = 0 ) +{ + T nrg[3] = {1,2,3}; + T (*pnrg)[3] = &nrg; + BOOST_TEST( boost::addressof(nrg) == pnrg ); + + T const cnrg[3] = {1,2,3}; + T const (*pcnrg)[3] = &cnrg; + BOOST_TEST( boost::addressof(cnrg) == pcnrg ); +} + +class convertible { +public: + + convertible( int = 0 ) + { + } + + template operator U () const + { + return U(); + } +}; + +class convertible2 { +public: + + convertible2( int = 0 ) + { + } + + operator convertible2* () const + { + return 0; + } +}; + +int main() +{ + scalar_test(); + scalar_test(); + + array_test(); + array_test(); + + return boost::report_errors(); +} diff --git a/include/boost/utility/addressof.hpp b/include/boost/utility/addressof.hpp index 8e0a586..f0da384 100644 --- a/include/boost/utility/addressof.hpp +++ b/include/boost/utility/addressof.hpp @@ -21,6 +21,14 @@ namespace boost namespace detail { +template struct addr_impl_ref +{ + T & v_; + + inline addr_impl_ref( T & v ): v_( v ) {} + inline operator T& () const { return v_; } +}; + template struct addressof_impl { static inline T * f( T & v, long ) @@ -39,7 +47,15 @@ template struct addressof_impl template T * addressof( T & v ) { +#if BOOST_WORKAROUND( __BORLANDC__, < 0x560 ) + return boost::detail::addressof_impl::f( v, 0 ); + +#else + + return boost::detail::addressof_impl::f( boost::detail::addr_impl_ref( v ), 0 ); + +#endif } // Borland doesn't like casting an array reference to a char reference From eacbce16fbaf7d99aba6d43dba1efb0e45c4d78f Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Sat, 21 Mar 2009 20:20:37 +0000 Subject: [PATCH 080/144] Disable new addressof code for all Borland versions. Refs #2878. [SVN r51891] --- include/boost/utility/addressof.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/boost/utility/addressof.hpp b/include/boost/utility/addressof.hpp index f0da384..48602be 100644 --- a/include/boost/utility/addressof.hpp +++ b/include/boost/utility/addressof.hpp @@ -47,7 +47,7 @@ template struct addressof_impl template T * addressof( T & v ) { -#if BOOST_WORKAROUND( __BORLANDC__, < 0x560 ) +#if BOOST_WORKAROUND( __BORLANDC__, BOOST_TESTED_AT( 0x610 ) ) return boost::detail::addressof_impl::f( v, 0 ); From 82d77c20eb843b70cba3ebee8f23457ff4b51a94 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Thu, 26 Mar 2009 00:06:47 +0000 Subject: [PATCH 081/144] Try to fix array addressof failures on Sun C++. [SVN r51977] --- include/boost/utility/addressof.hpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/include/boost/utility/addressof.hpp b/include/boost/utility/addressof.hpp index 48602be..2ebaefb 100644 --- a/include/boost/utility/addressof.hpp +++ b/include/boost/utility/addressof.hpp @@ -47,7 +47,7 @@ template struct addressof_impl template T * addressof( T & v ) { -#if BOOST_WORKAROUND( __BORLANDC__, BOOST_TESTED_AT( 0x610 ) ) +#if defined( __BORLANDC__ ) && BOOST_WORKAROUND( __BORLANDC__, BOOST_TESTED_AT( 0x610 ) ) return boost::detail::addressof_impl::f( v, 0 ); @@ -58,9 +58,18 @@ template T * addressof( T & v ) #endif } +#if defined( __SUNPRO_CC ) && BOOST_WORKAROUND( __SUNPRO_CC, BOOST_TESTED_AT( 0x590 ) ) + +template T (*addressof(T (&t)[N]))[N] +{ + return &t; +} + +#endif + // Borland doesn't like casting an array reference to a char reference // but these overloads work around the problem. -# if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) +#if defined( __BORLANDC__ ) && BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) template T (*addressof(T (&t)[N]))[N] { @@ -72,7 +81,7 @@ const T (*addressof(const T (&t)[N]))[N] { return reinterpret_cast(&t); } -# endif +#endif } // namespace boost From 5d3d9f60d817954220ceaedefafd031e736cc43c Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Thu, 26 Mar 2009 13:05:05 +0000 Subject: [PATCH 082/144] Try the Sun workaround with int instead of size_t. [SVN r51986] --- include/boost/utility/addressof.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/boost/utility/addressof.hpp b/include/boost/utility/addressof.hpp index 2ebaefb..bea9a01 100644 --- a/include/boost/utility/addressof.hpp +++ b/include/boost/utility/addressof.hpp @@ -60,7 +60,7 @@ template T * addressof( T & v ) #if defined( __SUNPRO_CC ) && BOOST_WORKAROUND( __SUNPRO_CC, BOOST_TESTED_AT( 0x590 ) ) -template T (*addressof(T (&t)[N]))[N] +template T (*addressof(T (&t)[N]))[N] { return &t; } From 09bb576ae802cad9ecfab12eb392c0bb5430acf0 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Fri, 27 Mar 2009 12:50:09 +0000 Subject: [PATCH 083/144] Another try at the Sun workaround. [SVN r52010] --- include/boost/utility/addressof.hpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/include/boost/utility/addressof.hpp b/include/boost/utility/addressof.hpp index bea9a01..ac42a51 100644 --- a/include/boost/utility/addressof.hpp +++ b/include/boost/utility/addressof.hpp @@ -60,7 +60,18 @@ template T * addressof( T & v ) #if defined( __SUNPRO_CC ) && BOOST_WORKAROUND( __SUNPRO_CC, BOOST_TESTED_AT( 0x590 ) ) -template T (*addressof(T (&t)[N]))[N] +namespace detail +{ + +template struct addressof_addp +{ + typedef T * type; +}; + +} // namespace detail + +template< class T, std::size_t N > +typename detail::addressof_addp< T[N] >::type addressof( T (&t)[N] ) { return &t; } From 4f645eb49c4254013c156e40bd8d25f08bacc330 Mon Sep 17 00:00:00 2001 From: Eric Niebler Date: Thu, 7 May 2009 17:47:08 +0000 Subject: [PATCH 084/144] eliminate noisy warning on msvc, fixes #2993 [SVN r52837] --- include/boost/utility/addressof.hpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/boost/utility/addressof.hpp b/include/boost/utility/addressof.hpp index ac42a51..95cd92f 100644 --- a/include/boost/utility/addressof.hpp +++ b/include/boost/utility/addressof.hpp @@ -27,6 +27,9 @@ template struct addr_impl_ref inline addr_impl_ref( T & v ): v_( v ) {} inline operator T& () const { return v_; } + +private: + addr_impl_ref & operator=(const addr_impl_ref &); }; template struct addressof_impl From e7988f3ae7a17437b87779b13874a34bb67bb32d Mon Sep 17 00:00:00 2001 From: John Maddock Date: Sun, 8 Nov 2009 18:53:59 +0000 Subject: [PATCH 085/144] Suppress/fix some msvc and gcc compiler warnings. [SVN r57494] --- ref_test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ref_test.cpp b/ref_test.cpp index d4237b4..71481fa 100644 --- a/ref_test.cpp +++ b/ref_test.cpp @@ -70,7 +70,7 @@ struct ref_wrapper struct copy_counter { static int count_; - copy_counter(copy_counter const& other) { + copy_counter(copy_counter const& /*other*/) { ++count_; } copy_counter() {} From 3133f1402e50d9adb8a947ce03d9e354fba17ab3 Mon Sep 17 00:00:00 2001 From: Jeremiah Willcock Date: Wed, 13 Apr 2011 02:30:39 +0000 Subject: [PATCH 086/144] Applied doc patches from Matt Calabrese [SVN r71221] --- enable_if.html | 111 +++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 93 insertions(+), 18 deletions(-) diff --git a/enable_if.html b/enable_if.html index a17a290..8ea33bb 100644 --- a/enable_if.html +++ b/enable_if.html @@ -21,6 +21,7 @@

    Copyright 2003 Jaakko Järvi, Jeremiah Willcock, Andrew Lumsdaine.
    +Copyright 2011 Matt Calabrese.

    @@ -81,7 +82,7 @@ definitions to find this out. Instantiating the latter definition with
    int::result_type negate(const int&);
     
     
    -where the return type is invalid. If this was an error, adding an unrelated function template +where the return type is invalid. If this were an error, adding an unrelated function template (that was never called) could break otherwise valid code. Due to the SFINAE principle the above example is not, however, erroneous. The latter definition of negate is simply removed from the overload resolution set.
    @@ -154,6 +155,7 @@ typename enable_if<boost::is_arithmetic<T>, T>::type foo(T t) { return t; } +

    3  Using enable_if

    @@ -162,8 +164,19 @@ foo(T t) { return t; } The enable_if templates are defined in boost/utility/enable_if.hpp, which is included by boost/utility.hpp.

    -The enable_if template can be used either as the return type, or as an -extra argument. For example, the foo function in the previous section could also be written +With respect to function templates, enable_if can be used in multiple different ways: + +
      +
    • As the return type of an instantiatied function +
    • As an extra parameter of an instantiated function +
    • As an extra template parameter (useful only in a compiler that supports C++0x default +arguments for function template parameters, see Enabling function +templates in C++0x for details) +
    + +In the previous section, the return type form of enable_if was shown. As an example +of using the form of enable_if that works via an extra function parameter, the +foo function in the previous section could also be written as:
    template <class T>
     T foo(T t, typename enable_if<boost::is_arithmetic<T> >::type* dummy = 0); 
    @@ -173,18 +186,80 @@ a default value to keep the parameter hidden from client code.
     Note that the second template argument was not given to enable_if, as the default 
     void gives the desired behavior.

    -Whether to write the enabler as an argument or within the return type is -largely a matter of taste, but for certain functions, only one -alternative is possible: +Which way to write the enabler is largely a matter of taste, but for certain functions, only a +subset of the options is possible:
    • -Operators have a fixed number of arguments, thus enable_if must be used in the return type. -
    • Constructors and destructors do not have a return type; an extra argument is the only option. -
    • There does not seem to be a way to specify an enabler for a conversion operator. Converting constructors, -however, can have enablers as extra default arguments. +Many operators have a fixed number of arguments, thus enable_if must be used either in the +return type or in an extra template parameter. +
    • Functions that have a variadic parameter list must use either the return type form or an extra +template parameter. +
    • Constructors do not have a return type so you must use either an extra function parameter or an +extra template parameter. +
    • Constructors that have a variadic parameter list must an extra template parameter. +
    • Conversion operators can only be written with an extra template parameter.
    + + + +

    3.1  Enabling function templates in C++0x

    + +In a compiler which supports C++0x default arguments for function template parameters, you can +enable and disable function templates by adding an additional template parameter. This approach +works in all situations where you would use either the return type form of enable_if or +the function parameter form, including operators, constructors, variadic function templates, and +even overloaded conversion operations. + +As an example: + +
    #include <boost/type_traits/is_arithmetic.hpp>
    +#include <boost/type_traits/is_pointer.hpp>
    +#include <boost/utility/enable_if.hpp>
    +
    +class test
    +{
    +public:
    +  // A constructor that works for any argument list of size 10
    +  template< class... T
    +          , typename boost::enable_if_c< sizeof...( T ) == 10, int >::type = 0
    +          >
    +  test( T&&... );
    +
    +  // A conversion operation that can convert to any arithmetic type
    +  template< class T
    +          , typename boost::enable_if< boost::is_arithmetic< T >, int >::type = 0
    +          >
    +  operator T() const;
    +
    +  // A conversion operation that can convert to any pointer type
    +  template< class T
    +          , typename boost::enable_if< boost::is_pointer< T >, int >::type = 0
    +          >
    +  operator T() const;
    +};
    +
    +int main()
    +{
    +  // Works
    +  test test_( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 );
    +
    +  // Fails as expected
    +  test fail_construction( 1, 2, 3, 4, 5 );
    +
    +  // Works by calling the conversion operator enabled for arithmetic types
    +  int arithmetic_object = test_;
    +
    +  // Works by calling the conversion operator enabled for pointer types
    +  int* pointer_object = test_;
    +
    +  // Fails as expected
    +  struct {} fail_conversion = test_;
    +}
    +
    +
    + -

    3.1  Enabling template class specializations

    +

    3.2  Enabling template class specializations

    Class template specializations can be enabled or disabled with enable_if. @@ -210,7 +285,7 @@ is the correct value.

    -

    3.2  Overlapping enabler conditions

    +

    3.3  Overlapping enabler conditions

    Once the compiler has examined the enabling conditions and included the @@ -239,7 +314,7 @@ partial specializations as well.

    -

    3.3  Lazy enable_if

    +

    3.4  Lazy enable_if

    In some cases it is necessary to avoid instantiating part of a @@ -285,7 +360,7 @@ above example, is_multipliable<T, U>::value defines when
    -

    3.4  Compiler workarounds

    +

    3.5  Compiler workarounds

    Some compilers flag functions as ambiguous if the only distinguishing factor is a different @@ -367,9 +442,9 @@ David Vandevoorde and Nicolai M. Josuttis. Addison-Wesley, 2002.
    -

    Copyright Jaakko Järvi, Jeremiah Willcock and Andrew Lumsdaine
    -{jajarvi|jewillco|lums}@osl.iu.edu
    -Indiana University
    +

    Copyright Jaakko Järvi*, Jeremiah Willcock*, Andrew Lumsdaine*, Matt Calabrese
    +{jajarvi|jewillco|lums}@osl.iu.edu, rivorus@gmail.com
    +*Indiana University
    Open Systems Lab
    Use, modification and distribution are subject to the Boost Software License, Version 1.0. @@ -386,4 +461,4 @@ or copy at HEVEA. - \ No newline at end of file + From 3803997b5b113fff01e2d126045456f367de629b Mon Sep 17 00:00:00 2001 From: "Vicente J. Botet Escriba" Date: Thu, 14 Mar 2013 17:48:06 +0000 Subject: [PATCH 087/144] Utility: address_of take care of #7079. [SVN r83429] --- include/boost/utility/addressof.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/boost/utility/addressof.hpp b/include/boost/utility/addressof.hpp index 95cd92f..ecb7776 100644 --- a/include/boost/utility/addressof.hpp +++ b/include/boost/utility/addressof.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2002 Brad King (brad.king@kitware.com) +// Copyright (C) 2002 Brad King (brad.king@kitware.com) // Douglas Gregor (gregod@cs.rpi.edu) // // Copyright (C) 2002, 2008 Peter Dimov @@ -50,7 +50,7 @@ template struct addressof_impl template T * addressof( T & v ) { -#if defined( __BORLANDC__ ) && BOOST_WORKAROUND( __BORLANDC__, BOOST_TESTED_AT( 0x610 ) ) +#if (defined( __BORLANDC__ ) && BOOST_WORKAROUND( __BORLANDC__, BOOST_TESTED_AT( 0x610 ) ) ) || defined( __SUNPRO_CC ) return boost::detail::addressof_impl::f( v, 0 ); From 83edb7e6de91f67a5b2fc00f3e114fc6a81d3c76 Mon Sep 17 00:00:00 2001 From: "Vicente J. Botet Escriba" Date: Wed, 10 Apr 2013 17:16:02 +0000 Subject: [PATCH 088/144] Utility/noncopyable: Make use of =delete #6578. [SVN r83833] --- include/boost/noncopyable.hpp | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/include/boost/noncopyable.hpp b/include/boost/noncopyable.hpp index 7770bdb..eb8e2e7 100644 --- a/include/boost/noncopyable.hpp +++ b/include/boost/noncopyable.hpp @@ -9,6 +9,8 @@ #ifndef BOOST_NONCOPYABLE_HPP_INCLUDED #define BOOST_NONCOPYABLE_HPP_INCLUDED +#include + namespace boost { // Private copy constructor and copy assignment ensure classes derived from @@ -21,11 +23,21 @@ namespace noncopyable_ // protection from unintended ADL class noncopyable { protected: - noncopyable() {} +#ifndef BOOST_NO_DEFAULTED_FUNCTIONS + BOOST_CONSTEXPR noncopyable() = default; + ~noncopyable() = default; +#else + noncopyable() {} ~noncopyable() {} - private: // emphasize the following members are private +#endif +#ifndef BOOST_NO_DELETED_FUNCTIONS + noncopyable( const noncopyable& ) = delete; + noncopyable& operator=( const noncopyable& ) = delete; +#else + private: // emphasize the following members are private noncopyable( const noncopyable& ); - const noncopyable& operator=( const noncopyable& ); + noncopyable& operator=( const noncopyable& ); +#endif }; } From af1562624b17ca6cfe5ceca53dd8c8025ff852af Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Thu, 26 Sep 2013 13:02:51 +0000 Subject: [PATCH 089/144] Remove obsolete MSVC check from pragma guard git grep -h -B1 "^#\s*pragma once" | grep -v pragma | sort | uniq is now clean. [SVN r85952] --- include/boost/checked_delete.hpp | 2 +- include/boost/ref.hpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/boost/checked_delete.hpp b/include/boost/checked_delete.hpp index 9bb84e8..80f936a 100644 --- a/include/boost/checked_delete.hpp +++ b/include/boost/checked_delete.hpp @@ -3,7 +3,7 @@ // MS compatible compilers support #pragma once -#if defined(_MSC_VER) && (_MSC_VER >= 1020) +#if defined(_MSC_VER) # pragma once #endif diff --git a/include/boost/ref.hpp b/include/boost/ref.hpp index 6058d69..90d033c 100644 --- a/include/boost/ref.hpp +++ b/include/boost/ref.hpp @@ -3,7 +3,7 @@ // MS compatible compilers support #pragma once -#if defined(_MSC_VER) && (_MSC_VER >= 1020) +#if defined(_MSC_VER) # pragma once #endif From 5ee57dd4693f9c9a9c530e76d24203c5b137daee Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Mon, 30 Sep 2013 00:19:48 +0000 Subject: [PATCH 090/144] Ref: Remove obsolete MSVC version check. [SVN r86031] --- include/boost/ref.hpp | 8 -------- 1 file changed, 8 deletions(-) diff --git a/include/boost/ref.hpp b/include/boost/ref.hpp index 90d033c..cf68764 100644 --- a/include/boost/ref.hpp +++ b/include/boost/ref.hpp @@ -34,16 +34,8 @@ template class reference_wrapper public: typedef T type; -#if defined( BOOST_MSVC ) && BOOST_WORKAROUND( BOOST_MSVC, < 1300 ) - - explicit reference_wrapper(T& t): t_(&t) {} - -#else - explicit reference_wrapper(T& t): t_(boost::addressof(t)) {} -#endif - operator T& () const { return *t_; } T& get() const { return *t_; } From 0f4204467c9d31c4e9fba38d761bcce87b42da85 Mon Sep 17 00:00:00 2001 From: Joel Falcou Date: Tue, 1 Oct 2013 15:02:28 +0000 Subject: [PATCH 091/144] Fix #9169 - Add BOOST_FORCEINLINE on boost::ref for performance issue [SVN r86124] --- include/boost/ref.hpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/include/boost/ref.hpp b/include/boost/ref.hpp index cf68764..cd186f9 100644 --- a/include/boost/ref.hpp +++ b/include/boost/ref.hpp @@ -30,17 +30,17 @@ namespace boost { template class reference_wrapper -{ +{ public: typedef T type; - explicit reference_wrapper(T& t): t_(boost::addressof(t)) {} + BOOST_FORCEINLINE explicit reference_wrapper(T& t): t_(boost::addressof(t)) {} - operator T& () const { return *t_; } + BOOST_FORCEINLINE operator T& () const { return *t_; } - T& get() const { return *t_; } + BOOST_FORCEINLINE T& get() const { return *t_; } - T* get_pointer() const { return t_; } + BOOST_FORCEINLINE T* get_pointer() const { return t_; } private: @@ -53,12 +53,12 @@ private: # define BOOST_REF_CONST const # endif -template inline reference_wrapper BOOST_REF_CONST ref(T & t) -{ +template BOOST_FORCEINLINE reference_wrapper BOOST_REF_CONST ref(T & t) +{ return reference_wrapper(t); } -template inline reference_wrapper BOOST_REF_CONST cref(T const & t) +template BOOST_FORCEINLINE reference_wrapper BOOST_REF_CONST cref(T const & t) { return reference_wrapper(t); } @@ -117,7 +117,7 @@ namespace detail { typedef char (&yes_reference_wrapper_t)[1]; typedef char (&no_reference_wrapper_t)[2]; - + no_reference_wrapper_t is_reference_wrapper_test(...); template @@ -152,7 +152,7 @@ class is_reference_wrapper bool, value = ( sizeof(detail::is_reference_wrapper_test(type())) == sizeof(detail::yes_reference_wrapper_t))); - + typedef ::boost::mpl::bool_ type; }; @@ -165,13 +165,13 @@ class unwrap_reference # endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION -template inline typename unwrap_reference::type& +template BOOST_FORCEINLINE typename unwrap_reference::type& unwrap_ref(T& t) { return t; } -template inline T* get_pointer( reference_wrapper const & r ) +template BOOST_FORCEINLINE T* get_pointer( reference_wrapper const & r ) { return r.get_pointer(); } From 01559a8b20f1d0ddc1dc9ff53021529127786b17 Mon Sep 17 00:00:00 2001 From: Joel Falcou Date: Tue, 1 Oct 2013 15:05:39 +0000 Subject: [PATCH 092/144] Fix #9170 - Add BOOST_FORCEINLINE in address_of for performance issues [SVN r86125] --- include/boost/utility/addressof.hpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/include/boost/utility/addressof.hpp b/include/boost/utility/addressof.hpp index ecb7776..2b637df 100644 --- a/include/boost/utility/addressof.hpp +++ b/include/boost/utility/addressof.hpp @@ -25,8 +25,8 @@ template struct addr_impl_ref { T & v_; - inline addr_impl_ref( T & v ): v_( v ) {} - inline operator T& () const { return v_; } + BOOST_FORCEINLINE addr_impl_ref( T & v ): v_( v ) {} + BOOST_FORCEINLINE operator T& () const { return v_; } private: addr_impl_ref & operator=(const addr_impl_ref &); @@ -34,13 +34,13 @@ private: template struct addressof_impl { - static inline T * f( T & v, long ) + static BOOST_FORCEINLINE T * f( T & v, long ) { return reinterpret_cast( &const_cast(reinterpret_cast(v))); } - static inline T * f( T * v, int ) + static BOOST_FORCEINLINE T * f( T * v, int ) { return v; } @@ -48,7 +48,9 @@ template struct addressof_impl } // namespace detail -template T * addressof( T & v ) +template +BOOST_FORCEINLINE +T * addressof( T & v ) { #if (defined( __BORLANDC__ ) && BOOST_WORKAROUND( __BORLANDC__, BOOST_TESTED_AT( 0x610 ) ) ) || defined( __SUNPRO_CC ) @@ -74,6 +76,7 @@ template struct addressof_addp } // namespace detail template< class T, std::size_t N > +BOOST_FORCEINLINE typename detail::addressof_addp< T[N] >::type addressof( T (&t)[N] ) { return &t; @@ -85,12 +88,14 @@ typename detail::addressof_addp< T[N] >::type addressof( T (&t)[N] ) // but these overloads work around the problem. #if defined( __BORLANDC__ ) && BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) template +BOOST_FORCEINLINE T (*addressof(T (&t)[N]))[N] { return reinterpret_cast(&t); } template +BOOST_FORCEINLINE const T (*addressof(const T (&t)[N]))[N] { return reinterpret_cast(&t); From 3ca731ba5c28228602035e4344046cf62c1bfefb Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Fri, 11 Oct 2013 23:17:48 +0000 Subject: [PATCH 093/144] Remove BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION Process #ifndef...#else...#endif blocks. [SVN r86245] --- include/boost/ref.hpp | 61 ------------------------------------------- 1 file changed, 61 deletions(-) diff --git a/include/boost/ref.hpp b/include/boost/ref.hpp index cd186f9..eae86f8 100644 --- a/include/boost/ref.hpp +++ b/include/boost/ref.hpp @@ -65,7 +65,6 @@ template BOOST_FORCEINLINE reference_wrapper BOOST_REF_CONST # undef BOOST_REF_CONST -# ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION template class is_reference_wrapper @@ -104,66 +103,6 @@ AUX_REFERENCE_WRAPPER_METAFUNCTIONS_DEF(reference_wrapper const volatile) # undef AUX_REFERENCE_WRAPPER_METAFUNCTIONS_DEF -# else // no partial specialization - -} // namespace boost - -#include - -namespace boost -{ - -namespace detail -{ - typedef char (&yes_reference_wrapper_t)[1]; - typedef char (&no_reference_wrapper_t)[2]; - - no_reference_wrapper_t is_reference_wrapper_test(...); - - template - yes_reference_wrapper_t is_reference_wrapper_test(type< reference_wrapper >); - - template - struct reference_unwrapper - { - template - struct apply - { - typedef T type; - }; - }; - - template<> - struct reference_unwrapper - { - template - struct apply - { - typedef typename T::type type; - }; - }; -} - -template -class is_reference_wrapper -{ - public: - BOOST_STATIC_CONSTANT( - bool, value = ( - sizeof(detail::is_reference_wrapper_test(type())) - == sizeof(detail::yes_reference_wrapper_t))); - - typedef ::boost::mpl::bool_ type; -}; - -template -class unwrap_reference - : public detail::reference_unwrapper< - is_reference_wrapper::value - >::template apply -{}; - -# endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION template BOOST_FORCEINLINE typename unwrap_reference::type& unwrap_ref(T& t) From b153bb98f38ee430359b52e9a26e4457436cad76 Mon Sep 17 00:00:00 2001 From: Jeremiah Willcock Date: Fri, 25 Oct 2013 02:46:04 +0000 Subject: [PATCH 094/144] Fixed duplicate anchors [SVN r86423] --- enable_if.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/enable_if.html b/enable_if.html index 8ea33bb..9988f3a 100644 --- a/enable_if.html +++ b/enable_if.html @@ -201,7 +201,7 @@ extra template parameter. -

    3.1  Enabling function templates in C++0x

    +

    3.1  Enabling function templates in C++0x

    In a compiler which supports C++0x default arguments for function template parameters, you can enable and disable function templates by adding an additional template parameter. This approach @@ -416,7 +416,7 @@ subscript operators). -

    4  Acknowledgements

    +

    4  Acknowledgements

    We are grateful to Howard Hinnant, Jason Shirk, Paul Mensonides, and Richard Smith whose findings have influenced the library.
    From d38344b9a4ca1bb97ab93eb411fc96e5b908afd4 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Wed, 11 Dec 2013 00:13:48 +0200 Subject: [PATCH 095/144] Revert "Remove obsolete MSVC check from pragma guard" This reverts commit 1fd5883b345a3c230daaad8ee93af5bc8f3209d5. --- include/boost/checked_delete.hpp | 2 +- include/boost/ref.hpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/boost/checked_delete.hpp b/include/boost/checked_delete.hpp index 80f936a..9bb84e8 100644 --- a/include/boost/checked_delete.hpp +++ b/include/boost/checked_delete.hpp @@ -3,7 +3,7 @@ // MS compatible compilers support #pragma once -#if defined(_MSC_VER) +#if defined(_MSC_VER) && (_MSC_VER >= 1020) # pragma once #endif diff --git a/include/boost/ref.hpp b/include/boost/ref.hpp index eae86f8..e31b167 100644 --- a/include/boost/ref.hpp +++ b/include/boost/ref.hpp @@ -3,7 +3,7 @@ // MS compatible compilers support #pragma once -#if defined(_MSC_VER) +#if defined(_MSC_VER) && (_MSC_VER >= 1020) # pragma once #endif From 8a1d121ef972f0a3394eeee428caf7ca6d848b5a Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Wed, 11 Dec 2013 00:46:10 +0200 Subject: [PATCH 096/144] Revert "Ref: Remove obsolete MSVC version check." This reverts commit adf57817ec09cb8edd6032a30da6daec3edbe23f. Conflicts: include/boost/ref.hpp --- include/boost/ref.hpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/include/boost/ref.hpp b/include/boost/ref.hpp index e31b167..8169149 100644 --- a/include/boost/ref.hpp +++ b/include/boost/ref.hpp @@ -34,8 +34,16 @@ template class reference_wrapper public: typedef T type; +#if defined( BOOST_MSVC ) && BOOST_WORKAROUND( BOOST_MSVC, < 1300 ) + + explicit reference_wrapper(T& t): t_(&t) {} + +#else + BOOST_FORCEINLINE explicit reference_wrapper(T& t): t_(boost::addressof(t)) {} +#endif + BOOST_FORCEINLINE operator T& () const { return *t_; } BOOST_FORCEINLINE T& get() const { return *t_; } From a25ab4d824347f5c621e4392beb5ff6bb85a3213 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Wed, 11 Dec 2013 01:57:20 +0200 Subject: [PATCH 097/144] Fix addressof for nullptr_t values. Fixes #5487. --- addressof_np_test.cpp | 50 +++++++++++++++++++++++++ include/boost/utility/addressof.hpp | 57 ++++++++++++++++++++++++++++- 2 files changed, 106 insertions(+), 1 deletion(-) create mode 100644 addressof_np_test.cpp diff --git a/addressof_np_test.cpp b/addressof_np_test.cpp new file mode 100644 index 0000000..9e155d4 --- /dev/null +++ b/addressof_np_test.cpp @@ -0,0 +1,50 @@ +// +// Copyright 2013 Peter Dimov +// +// 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 + +#if defined( BOOST_NO_CXX11_NULLPTR ) + +void nullptr_test() +{ +} + +#else + +void nullptr_test() +{ + { + auto x = nullptr; + BOOST_TEST( boost::addressof(x) == &x ); + } + + { + auto const x = nullptr; + BOOST_TEST( boost::addressof(x) == &x ); + } + + { + auto volatile x = nullptr; + BOOST_TEST( boost::addressof(x) == &x ); + } + + { + auto const volatile x = nullptr; + BOOST_TEST( boost::addressof(x) == &x ); + } +} + +#endif + +int main() +{ + nullptr_test(); + return boost::report_errors(); +} diff --git a/include/boost/utility/addressof.hpp b/include/boost/utility/addressof.hpp index 2b637df..ef5639f 100644 --- a/include/boost/utility/addressof.hpp +++ b/include/boost/utility/addressof.hpp @@ -1,7 +1,7 @@ // Copyright (C) 2002 Brad King (brad.king@kitware.com) // Douglas Gregor (gregod@cs.rpi.edu) // -// Copyright (C) 2002, 2008 Peter Dimov +// Copyright (C) 2002, 2008, 2013 Peter Dimov // // Distributed under the Boost Software License, Version 1.0. (See // accompanying file LICENSE_1_0.txt or copy at @@ -14,6 +14,7 @@ # include # include +# include namespace boost { @@ -46,6 +47,60 @@ template struct addressof_impl } }; +#if !defined( BOOST_NO_CXX11_NULLPTR ) + +#if defined( __clang__ ) && !defined( _LIBCPP_VERSION ) && !defined( BOOST_NO_CXX11_DECLTYPE ) + + typedef decltype(nullptr) addr_nullptr_t; + +#else + + typedef std::nullptr_t addr_nullptr_t; + +#endif + +template<> struct addressof_impl< addr_nullptr_t > +{ + typedef addr_nullptr_t T; + + static BOOST_FORCEINLINE T * f( T & v, int ) + { + return &v; + } +}; + +template<> struct addressof_impl< addr_nullptr_t const > +{ + typedef addr_nullptr_t const T; + + static BOOST_FORCEINLINE T * f( T & v, int ) + { + return &v; + } +}; + +template<> struct addressof_impl< addr_nullptr_t volatile > +{ + typedef addr_nullptr_t volatile T; + + static BOOST_FORCEINLINE T * f( T & v, int ) + { + return &v; + } +}; + +template<> struct addressof_impl< addr_nullptr_t const volatile > +{ + typedef addr_nullptr_t const volatile T; + + static BOOST_FORCEINLINE T * f( T & v, int ) + { + return &v; + } +}; + +#endif + } // namespace detail template From 5956c3b0f09ce136e6e18ea91d0c565c687e5701 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Wed, 11 Dec 2013 23:28:13 +0200 Subject: [PATCH 098/144] Revert incorrect reversion of adf57817ec09cb8edd6032a30da6daec3edbe23f --- include/boost/ref.hpp | 8 -------- 1 file changed, 8 deletions(-) diff --git a/include/boost/ref.hpp b/include/boost/ref.hpp index 8169149..e31b167 100644 --- a/include/boost/ref.hpp +++ b/include/boost/ref.hpp @@ -34,16 +34,8 @@ template class reference_wrapper public: typedef T type; -#if defined( BOOST_MSVC ) && BOOST_WORKAROUND( BOOST_MSVC, < 1300 ) - - explicit reference_wrapper(T& t): t_(&t) {} - -#else - BOOST_FORCEINLINE explicit reference_wrapper(T& t): t_(boost::addressof(t)) {} -#endif - BOOST_FORCEINLINE operator T& () const { return *t_; } BOOST_FORCEINLINE T& get() const { return *t_; } From 24bb363cf1b7a9815c41f51727244d18fca6a278 Mon Sep 17 00:00:00 2001 From: Andrey Semashev Date: Thu, 10 Apr 2014 00:27:41 +0400 Subject: [PATCH 099/144] Fix compilation with gcc 4.5 in C++11 mode Gcc 4.5 does not allow non-public defaulted functions, so fall back to the C++03 version. Also replaced the deprecated macros with the new ones and adjusted formatting. --- include/boost/noncopyable.hpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/include/boost/noncopyable.hpp b/include/boost/noncopyable.hpp index eb8e2e7..50eb966 100644 --- a/include/boost/noncopyable.hpp +++ b/include/boost/noncopyable.hpp @@ -22,19 +22,19 @@ namespace noncopyable_ // protection from unintended ADL { class noncopyable { - protected: -#ifndef BOOST_NO_DEFAULTED_FUNCTIONS - BOOST_CONSTEXPR noncopyable() = default; - ~noncopyable() = default; + protected: +#if !defined(BOOST_NO_CXX11_DEFAULTED_FUNCTIONS) && !defined(BOOST_NO_CXX11_NON_PUBLIC_DEFAULTED_FUNCTIONS) + BOOST_CONSTEXPR noncopyable() = default; + ~noncopyable() = default; #else - noncopyable() {} + noncopyable() {} ~noncopyable() {} #endif -#ifndef BOOST_NO_DELETED_FUNCTIONS - noncopyable( const noncopyable& ) = delete; - noncopyable& operator=( const noncopyable& ) = delete; +#if !defined(BOOST_NO_CXX11_DELETED_FUNCTIONS) + noncopyable( const noncopyable& ) = delete; + noncopyable& operator=( const noncopyable& ) = delete; #else - private: // emphasize the following members are private + private: // emphasize the following members are private noncopyable( const noncopyable& ); noncopyable& operator=( const noncopyable& ); #endif From 503cd251c28cdf97b8412edcd573fe08f988c3df Mon Sep 17 00:00:00 2001 From: Aleksey Gurtovoy Date: Sun, 10 Oct 2004 16:15:58 +0000 Subject: [PATCH 100/144] move enable_if tests into their own subdirectory [SVN r25649] --- enable_if/test/Jamfile | 33 +++++++ enable_if/test/constructors.cpp | 62 ++++++++++++ enable_if/test/dummy_arg_disambiguation.cpp | 46 +++++++++ enable_if/test/lazy.cpp | 82 ++++++++++++++++ enable_if/test/lazy_test.cpp | 100 ++++++++++++++++++++ enable_if/test/member_templates.cpp | 43 +++++++++ enable_if/test/namespace_disambiguation.cpp | 47 +++++++++ enable_if/test/no_disambiguation.cpp | 43 +++++++++ enable_if/test/partial_specializations.cpp | 67 +++++++++++++ 9 files changed, 523 insertions(+) create mode 100644 enable_if/test/Jamfile create mode 100644 enable_if/test/constructors.cpp create mode 100644 enable_if/test/dummy_arg_disambiguation.cpp create mode 100644 enable_if/test/lazy.cpp create mode 100644 enable_if/test/lazy_test.cpp create mode 100644 enable_if/test/member_templates.cpp create mode 100644 enable_if/test/namespace_disambiguation.cpp create mode 100644 enable_if/test/no_disambiguation.cpp create mode 100644 enable_if/test/partial_specializations.cpp diff --git a/enable_if/test/Jamfile b/enable_if/test/Jamfile new file mode 100644 index 0000000..f2e5ee3 --- /dev/null +++ b/enable_if/test/Jamfile @@ -0,0 +1,33 @@ +# 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) + +# For more information, see http://www.boost.org/ + +subproject libs/utility/enable_if/test ; + +# bring in rules for testing +import testing ; + +# Make tests run by default. +DEPENDS all : test ; + +{ + local test_monitor = @boost/libs/test/build/boost_test_exec_monitor ; + + # look in BOOST_ROOT for sources first, just in this Jamfile + local SEARCH_SOURCE = $(BOOST_ROOT) $(SEARCH_SOURCE) ; + + test-suite utility/enable_if + : + [ run libs/utility/enable_if/test/constructors.cpp $(test_monitor) ] + [ run libs/utility/enable_if/test/dummy_arg_disambiguation.cpp $(test_monitor) ] + [ run libs/utility/enable_if/test/lazy.cpp $(test_monitor) ] + [ run libs/utility/enable_if/test/lazy_test.cpp $(test_monitor) ] + [ run libs/utility/enable_if/test/member_templates.cpp $(test_monitor) ] + [ run libs/utility/enable_if/test/namespace_disambiguation.cpp $(test_monitor) ] + [ run libs/utility/enable_if/test/no_disambiguation.cpp $(test_monitor) ] + [ run libs/utility/enable_if/test/partial_specializations.cpp $(test_monitor) ] + ; +} diff --git a/enable_if/test/constructors.cpp b/enable_if/test/constructors.cpp new file mode 100644 index 0000000..557b2f0 --- /dev/null +++ b/enable_if/test/constructors.cpp @@ -0,0 +1,62 @@ +// Boost enable_if library + +// Copyright 2003 © The Trustees of Indiana University. + +// Use, modification, and distribution is subject to 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) + +// Authors: Jaakko Järvi (jajarvi at osl.iu.edu) +// Jeremiah Willcock (jewillco at osl.iu.edu) +// Andrew Lumsdaine (lums at osl.iu.edu) + +#include + +#include +#include + +using boost::enable_if; +using boost::disable_if; +using boost::is_arithmetic; + +struct container { + bool my_value; + + template + container(const T&, const typename enable_if, T>::type * = 0): + my_value(true) {} + + template + container(const T&, const typename disable_if, T>::type * = 0): + my_value(false) {} +}; + +// example from Howard Hinnant (tests enable_if template members of a templated class) +template +struct xstring +{ + template + xstring(It begin, It end, typename + disable_if >::type* = 0) + : data(end-begin) {} + + int data; +}; + + +int test_main(int, char*[]) +{ + + BOOST_CHECK(container(1).my_value); + BOOST_CHECK(container(1.0).my_value); + + BOOST_CHECK(!container("1").my_value); + BOOST_CHECK(!container(static_cast(0)).my_value); + + char sa[] = "123456"; + BOOST_CHECK(xstring(sa, sa+6).data == 6); + + + return 0; +} + diff --git a/enable_if/test/dummy_arg_disambiguation.cpp b/enable_if/test/dummy_arg_disambiguation.cpp new file mode 100644 index 0000000..bb9f733 --- /dev/null +++ b/enable_if/test/dummy_arg_disambiguation.cpp @@ -0,0 +1,46 @@ +// Boost enable_if library + +// Copyright 2003 © The Trustees of Indiana University. + +// Use, modification, and distribution is subject to 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) + +// Authors: Jaakko Järvi (jajarvi at osl.iu.edu) +// Jeremiah Willcock (jewillco at osl.iu.edu) +// Andrew Lumsdaine (lums at osl.iu.edu) + +#include + +#include +#include + +using boost::enable_if; +using boost::disable_if; +using boost::is_arithmetic; + +template struct dummy { + dummy(int) {}; +}; + +template +typename enable_if, bool>::type +arithmetic_object(T t, dummy<0> = 0) { return true; } + +template +typename disable_if, bool>::type +arithmetic_object(T t, dummy<1> = 0) { return false; } + + +int test_main(int, char*[]) +{ + + BOOST_CHECK(arithmetic_object(1)); + BOOST_CHECK(arithmetic_object(1.0)); + + BOOST_CHECK(!arithmetic_object("1")); + BOOST_CHECK(!arithmetic_object(static_cast(0))); + + return 0; +} + diff --git a/enable_if/test/lazy.cpp b/enable_if/test/lazy.cpp new file mode 100644 index 0000000..6e7d650 --- /dev/null +++ b/enable_if/test/lazy.cpp @@ -0,0 +1,82 @@ +// Boost enable_if library + +// Copyright 2003 © The Trustees of Indiana University. + +// Use, modification, and distribution is subject to 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) + +// Authors: Jaakko Järvi (jajarvi at osl.iu.edu) +// Jeremiah Willcock (jewillco at osl.iu.edu) +// Andrew Lumsdaine (lums at osl.iu.edu) + +#include + +#include +#include + +using boost::enable_if_c; +using boost::lazy_enable_if_c; + +// This class provides a reduced example of a traits class for +// computing the result of multiplying two types. The member typedef +// 'type' in this traits class defines the return type of this +// operator. The return type member is invalid unless both arguments +// for mult_traits are values that mult_traits expects (ints in this +// case). This kind of situation may arise if a traits class only +// makes sense for some set of types, not all C++ types. + +template struct is_int { + BOOST_STATIC_CONSTANT(bool, value = (boost::is_same::value)); +}; + +template +struct mult_traits { + typedef typename T::does_not_exist type; +}; + +template <> +struct mult_traits { + typedef int type; +}; + + +// Next, a forwarding function mult() is defined. It is enabled only +// when both arguments are of type int. The first version, using +// non-lazy enable_if_c does not work. + +#if 0 +template +typename enable_if_c< + is_int::value && is_int::value, + typename mult_traits::type +>::type +mult(const T& x, const U& y) {return x * y;} +#endif + +// A correct version uses lazy_enable_if_c. +// This template removes compiler errors from invalid code used as an +// argument to enable_if_c. + +#if 1 +template +typename lazy_enable_if_c< + is_int::value && is_int::value, + mult_traits +>::type +mult(const T& x, const U& y) {return x * y;} +#endif + +double mult(int i, double d) { return (double)i * d; } + +int test_main(int, char*[]) +{ + + + BOOST_CHECK(mult(1, 2) == 2); + + BOOST_CHECK(mult(1, 3.0) == 3.0); + + return 0; +} + diff --git a/enable_if/test/lazy_test.cpp b/enable_if/test/lazy_test.cpp new file mode 100644 index 0000000..d52d01e --- /dev/null +++ b/enable_if/test/lazy_test.cpp @@ -0,0 +1,100 @@ +// Boost enable_if library + +// Copyright 2003 © The Trustees of Indiana University. + +// Use, modification, and distribution is subject to 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) + +// Authors: Jaakko Järvi (jajarvi at osl.iu.edu) +// Jeremiah Willcock (jewillco at osl.iu.edu) +// Andrew Lumsdaine (lums at osl.iu.edu) + +// Testing all variations of lazy_enable_if. + +#include +#include + +#include +#include + +using boost::lazy_enable_if; +using boost::lazy_disable_if; + +using boost::lazy_enable_if_c; +using boost::lazy_disable_if_c; + + +template +struct is_int_or_double { + BOOST_STATIC_CONSTANT(bool, + value = (boost::is_same::value || + boost::is_same::value)); +}; + +template +struct some_traits { + typedef typename T::does_not_exist type; +}; + +template <> +struct some_traits { + typedef bool type; +}; + +template <> +struct some_traits { + typedef bool type; +}; + +template +struct make_bool { + typedef bool type; +}; + +template <> +struct make_bool {}; + +template <> +struct make_bool {}; + +namespace A { + + template + typename lazy_enable_if, some_traits >::type + foo(T t) { return true; } + + template + typename lazy_enable_if_c::value, some_traits >::type + foo2(T t) { return true; } +} + +namespace B { + template + typename lazy_disable_if, make_bool >::type + foo(T t) { return false; } + + template + typename lazy_disable_if_c::value, make_bool >::type + foo2(T t) { return false; } +} + +int test_main(int, char*[]) +{ + using namespace A; + using namespace B; + BOOST_CHECK(foo(1)); + BOOST_CHECK(foo(1.0)); + + BOOST_CHECK(!foo("1")); + BOOST_CHECK(!foo(static_cast(0))); + + BOOST_CHECK(foo2(1)); + BOOST_CHECK(foo2(1.0)); + + BOOST_CHECK(!foo2("1")); + BOOST_CHECK(!foo2(static_cast(0))); + + return 0; +} + diff --git a/enable_if/test/member_templates.cpp b/enable_if/test/member_templates.cpp new file mode 100644 index 0000000..23dd173 --- /dev/null +++ b/enable_if/test/member_templates.cpp @@ -0,0 +1,43 @@ +// Boost enable_if library + +// Copyright 2003 © The Trustees of Indiana University. + +// Use, modification, and distribution is subject to 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) + +// Authors: Jaakko Järvi (jajarvi at osl.iu.edu) +// Jeremiah Willcock (jewillco at osl.iu.edu) +// Andrew Lumsdaine (lums at osl.iu.edu) + +#include + +#include +#include + +using boost::enable_if; +using boost::disable_if; +using boost::is_arithmetic; + +struct container { + template + typename enable_if, bool>::type + arithmetic_object(const T&, const int* /* disambiguate */ = 0) {return true;} + + template + typename disable_if, bool>::type + arithmetic_object(const T&) {return false;} +}; + +int test_main(int, char*[]) +{ + + BOOST_CHECK(container().arithmetic_object(1)); + BOOST_CHECK(container().arithmetic_object(1.0)); + + BOOST_CHECK(!container().arithmetic_object("1")); + BOOST_CHECK(!container().arithmetic_object(static_cast(0))); + + return 0; +} + diff --git a/enable_if/test/namespace_disambiguation.cpp b/enable_if/test/namespace_disambiguation.cpp new file mode 100644 index 0000000..90a98a1 --- /dev/null +++ b/enable_if/test/namespace_disambiguation.cpp @@ -0,0 +1,47 @@ +// Boost enable_if library + +// Copyright 2003 © The Trustees of Indiana University. + +// Use, modification, and distribution is subject to 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) + +// Authors: Jaakko Järvi (jajarvi at osl.iu.edu) +// Jeremiah Willcock (jewillco at osl.iu.edu) +// Andrew Lumsdaine (lums at osl.iu.edu) + +#include +#include + +#include +#include + +using boost::enable_if; +using boost::mpl::not_; +using boost::is_arithmetic; + +namespace A { + template + typename enable_if, bool>::type + arithmetic_object(T t) { return true; } +} + +namespace B { + template + typename enable_if >, bool>::type + arithmetic_object(T t) { return false; } +} + +int test_main(int, char*[]) +{ + using namespace A; + using namespace B; + BOOST_CHECK(arithmetic_object(1)); + BOOST_CHECK(arithmetic_object(1.0)); + + BOOST_CHECK(!arithmetic_object("1")); + BOOST_CHECK(!arithmetic_object(static_cast(0))); + + return 0; +} + diff --git a/enable_if/test/no_disambiguation.cpp b/enable_if/test/no_disambiguation.cpp new file mode 100644 index 0000000..f4936e8 --- /dev/null +++ b/enable_if/test/no_disambiguation.cpp @@ -0,0 +1,43 @@ +// Boost enable_if library + +// Copyright 2003 © The Trustees of Indiana University. + +// Use, modification, and distribution is subject to 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) + +// Authors: Jaakko Järvi (jajarvi at osl.iu.edu) +// Jeremiah Willcock (jewillco at osl.iu.edu) +// Andrew Lumsdaine (lums at osl.iu.edu) + +#include +#include + +#include +#include + +using boost::mpl::not_; +using boost::enable_if; +using boost::is_arithmetic; + +template +typename enable_if, bool>::type +arithmetic_object(T t) { return true; } + +template +typename enable_if >, bool>::type +arithmetic_object(T t) { return false; } + + +int test_main(int, char*[]) +{ + + BOOST_CHECK(arithmetic_object(1)); + BOOST_CHECK(arithmetic_object(1.0)); + + BOOST_CHECK(!arithmetic_object("1")); + BOOST_CHECK(!arithmetic_object(static_cast(0))); + + return 0; +} + diff --git a/enable_if/test/partial_specializations.cpp b/enable_if/test/partial_specializations.cpp new file mode 100644 index 0000000..3dce799 --- /dev/null +++ b/enable_if/test/partial_specializations.cpp @@ -0,0 +1,67 @@ +// Boost enable_if library + +// Copyright 2003 © The Trustees of Indiana University. + +// Use, modification, and distribution is subject to 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) + +// Authors: Jaakko Järvi (jajarvi at osl.iu.edu) +// Jeremiah Willcock (jewillco at osl.iu.edu) +// Andrew Lumsdaine (lums at osl.iu.edu) + +#include + +#include +#include + +using boost::enable_if_c; +using boost::disable_if_c; +using boost::enable_if; +using boost::disable_if; +using boost::is_arithmetic; + +template +struct tester; + +template +struct tester::value>::type> { + BOOST_STATIC_CONSTANT(bool, value = true); +}; + +template +struct tester::value>::type> { + BOOST_STATIC_CONSTANT(bool, value = false); +}; + +template +struct tester2; + +template +struct tester2 >::type> { + BOOST_STATIC_CONSTANT(bool, value = true); +}; + +template +struct tester2 >::type> { + BOOST_STATIC_CONSTANT(bool, value = false); +}; + +int test_main(int, char*[]) +{ + + BOOST_CHECK(tester::value); + BOOST_CHECK(tester::value); + + BOOST_CHECK(!tester::value); + BOOST_CHECK(!tester::value); + + BOOST_CHECK(tester2::value); + BOOST_CHECK(tester2::value); + + BOOST_CHECK(!tester2::value); + BOOST_CHECK(!tester2::value); + + return 0; +} + From ca4fa81b07072191587f87a8e18b9fed1fe05d8e Mon Sep 17 00:00:00 2001 From: Vladimir Prus Date: Thu, 14 Apr 2005 13:15:46 +0000 Subject: [PATCH 101/144] Add V2 Jamfile [SVN r28246] --- enable_if/test/Jamfile.v2 | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 enable_if/test/Jamfile.v2 diff --git a/enable_if/test/Jamfile.v2 b/enable_if/test/Jamfile.v2 new file mode 100644 index 0000000..77a8798 --- /dev/null +++ b/enable_if/test/Jamfile.v2 @@ -0,0 +1,23 @@ +# 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) + +# For more information, see http://www.boost.org/ + +project + : requirements /boost/test//boost_test_exec_monitor + ; + +test-suite utility/enable_if + : + [ run constructors.cpp ] + [ run dummy_arg_disambiguation.cpp ] + [ run lazy.cpp ] + [ run lazy_test.cpp ] + [ run member_templates.cpp ] + [ run namespace_disambiguation.cpp ] + [ run no_disambiguation.cpp ] + [ run partial_specializations.cpp ] + ; + From 168d31dc520f886c95631e7618b955add0e9bd8b Mon Sep 17 00:00:00 2001 From: Jeremiah Willcock Date: Sun, 4 Dec 2005 18:47:02 +0000 Subject: [PATCH 102/144] Attempted portability fix for Sun compilers [SVN r31904] --- enable_if/test/lazy.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/enable_if/test/lazy.cpp b/enable_if/test/lazy.cpp index 6e7d650..d766fc9 100644 --- a/enable_if/test/lazy.cpp +++ b/enable_if/test/lazy.cpp @@ -61,7 +61,7 @@ mult(const T& x, const U& y) {return x * y;} #if 1 template typename lazy_enable_if_c< - is_int::value && is_int::value, + is_int::value & is_int::value, mult_traits >::type mult(const T& x, const U& y) {return x * y;} From 836c451d93b23fddade8aead7cc645820990bfd7 Mon Sep 17 00:00:00 2001 From: Vladimir Prus Date: Wed, 8 Aug 2007 19:02:26 +0000 Subject: [PATCH 103/144] Remove V1 Jamfiles [SVN r38516] --- enable_if/test/Jamfile | 33 --------------------------------- 1 file changed, 33 deletions(-) delete mode 100644 enable_if/test/Jamfile diff --git a/enable_if/test/Jamfile b/enable_if/test/Jamfile deleted file mode 100644 index f2e5ee3..0000000 --- a/enable_if/test/Jamfile +++ /dev/null @@ -1,33 +0,0 @@ -# Copyright David Abrahams 2003. -# Distributed under the Boost Software License, Version 1.0. -# (See accompanying file LICENSE_1_0.txt or copy at -# http://www.boost.org/LICENSE_1_0.txt) - -# For more information, see http://www.boost.org/ - -subproject libs/utility/enable_if/test ; - -# bring in rules for testing -import testing ; - -# Make tests run by default. -DEPENDS all : test ; - -{ - local test_monitor = @boost/libs/test/build/boost_test_exec_monitor ; - - # look in BOOST_ROOT for sources first, just in this Jamfile - local SEARCH_SOURCE = $(BOOST_ROOT) $(SEARCH_SOURCE) ; - - test-suite utility/enable_if - : - [ run libs/utility/enable_if/test/constructors.cpp $(test_monitor) ] - [ run libs/utility/enable_if/test/dummy_arg_disambiguation.cpp $(test_monitor) ] - [ run libs/utility/enable_if/test/lazy.cpp $(test_monitor) ] - [ run libs/utility/enable_if/test/lazy_test.cpp $(test_monitor) ] - [ run libs/utility/enable_if/test/member_templates.cpp $(test_monitor) ] - [ run libs/utility/enable_if/test/namespace_disambiguation.cpp $(test_monitor) ] - [ run libs/utility/enable_if/test/no_disambiguation.cpp $(test_monitor) ] - [ run libs/utility/enable_if/test/partial_specializations.cpp $(test_monitor) ] - ; -} From e8dc13f91592e3de5cbfb4be60acd142aed5261c Mon Sep 17 00:00:00 2001 From: Marshall Clow Date: Wed, 2 Apr 2008 01:42:32 +0000 Subject: [PATCH 104/144] Replaced all occurrences of non-ASCII copyright symbol with '(c)' for people using non-ASCII code pages [SVN r43992] --- enable_if/test/constructors.cpp | 2 +- enable_if/test/dummy_arg_disambiguation.cpp | 2 +- enable_if/test/lazy.cpp | 2 +- enable_if/test/lazy_test.cpp | 2 +- enable_if/test/member_templates.cpp | 2 +- enable_if/test/namespace_disambiguation.cpp | 2 +- enable_if/test/no_disambiguation.cpp | 2 +- enable_if/test/partial_specializations.cpp | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/enable_if/test/constructors.cpp b/enable_if/test/constructors.cpp index 557b2f0..889133d 100644 --- a/enable_if/test/constructors.cpp +++ b/enable_if/test/constructors.cpp @@ -1,6 +1,6 @@ // Boost enable_if library -// Copyright 2003 © The Trustees of Indiana University. +// Copyright 2003 (c) The Trustees of Indiana University. // Use, modification, and distribution is subject to the Boost Software // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at diff --git a/enable_if/test/dummy_arg_disambiguation.cpp b/enable_if/test/dummy_arg_disambiguation.cpp index bb9f733..90275e9 100644 --- a/enable_if/test/dummy_arg_disambiguation.cpp +++ b/enable_if/test/dummy_arg_disambiguation.cpp @@ -1,6 +1,6 @@ // Boost enable_if library -// Copyright 2003 © The Trustees of Indiana University. +// Copyright 2003 (c) The Trustees of Indiana University. // Use, modification, and distribution is subject to the Boost Software // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at diff --git a/enable_if/test/lazy.cpp b/enable_if/test/lazy.cpp index d766fc9..117ec41 100644 --- a/enable_if/test/lazy.cpp +++ b/enable_if/test/lazy.cpp @@ -1,6 +1,6 @@ // Boost enable_if library -// Copyright 2003 © The Trustees of Indiana University. +// Copyright 2003 (c) The Trustees of Indiana University. // Use, modification, and distribution is subject to the Boost Software // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at diff --git a/enable_if/test/lazy_test.cpp b/enable_if/test/lazy_test.cpp index d52d01e..10bb60c 100644 --- a/enable_if/test/lazy_test.cpp +++ b/enable_if/test/lazy_test.cpp @@ -1,6 +1,6 @@ // Boost enable_if library -// Copyright 2003 © The Trustees of Indiana University. +// Copyright 2003 (c) The Trustees of Indiana University. // Use, modification, and distribution is subject to the Boost Software // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at diff --git a/enable_if/test/member_templates.cpp b/enable_if/test/member_templates.cpp index 23dd173..f7c00a0 100644 --- a/enable_if/test/member_templates.cpp +++ b/enable_if/test/member_templates.cpp @@ -1,6 +1,6 @@ // Boost enable_if library -// Copyright 2003 © The Trustees of Indiana University. +// Copyright 2003 (c) The Trustees of Indiana University. // Use, modification, and distribution is subject to the Boost Software // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at diff --git a/enable_if/test/namespace_disambiguation.cpp b/enable_if/test/namespace_disambiguation.cpp index 90a98a1..a53d3a7 100644 --- a/enable_if/test/namespace_disambiguation.cpp +++ b/enable_if/test/namespace_disambiguation.cpp @@ -1,6 +1,6 @@ // Boost enable_if library -// Copyright 2003 © The Trustees of Indiana University. +// Copyright 2003 (c) The Trustees of Indiana University. // Use, modification, and distribution is subject to the Boost Software // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at diff --git a/enable_if/test/no_disambiguation.cpp b/enable_if/test/no_disambiguation.cpp index f4936e8..122d600 100644 --- a/enable_if/test/no_disambiguation.cpp +++ b/enable_if/test/no_disambiguation.cpp @@ -1,6 +1,6 @@ // Boost enable_if library -// Copyright 2003 © The Trustees of Indiana University. +// Copyright 2003 (c) The Trustees of Indiana University. // Use, modification, and distribution is subject to the Boost Software // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at diff --git a/enable_if/test/partial_specializations.cpp b/enable_if/test/partial_specializations.cpp index 3dce799..5c322ae 100644 --- a/enable_if/test/partial_specializations.cpp +++ b/enable_if/test/partial_specializations.cpp @@ -1,6 +1,6 @@ // Boost enable_if library -// Copyright 2003 © The Trustees of Indiana University. +// Copyright 2003 (c) The Trustees of Indiana University. // Use, modification, and distribution is subject to the Boost Software // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at From f258850888034f739d2c5efd2277e3d356ede33e Mon Sep 17 00:00:00 2001 From: Beman Dawes Date: Sat, 28 Jun 2008 13:45:21 +0000 Subject: [PATCH 105/144] =?UTF-8?q?With=20his=20kind=20permission,=20chang?= =?UTF-8?q?e=20Jaakko=20"J=C3=A4rvi"=20to=20"Jarvi"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [SVN r46808] --- enable_if/test/constructors.cpp | 2 +- enable_if/test/dummy_arg_disambiguation.cpp | 2 +- enable_if/test/lazy.cpp | 2 +- enable_if/test/lazy_test.cpp | 2 +- enable_if/test/member_templates.cpp | 2 +- enable_if/test/namespace_disambiguation.cpp | 2 +- enable_if/test/no_disambiguation.cpp | 2 +- enable_if/test/partial_specializations.cpp | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/enable_if/test/constructors.cpp b/enable_if/test/constructors.cpp index 889133d..0d465de 100644 --- a/enable_if/test/constructors.cpp +++ b/enable_if/test/constructors.cpp @@ -6,7 +6,7 @@ // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) -// Authors: Jaakko Järvi (jajarvi at osl.iu.edu) +// Authors: Jaakko Jarvi (jajarvi at osl.iu.edu) // Jeremiah Willcock (jewillco at osl.iu.edu) // Andrew Lumsdaine (lums at osl.iu.edu) diff --git a/enable_if/test/dummy_arg_disambiguation.cpp b/enable_if/test/dummy_arg_disambiguation.cpp index 90275e9..60dfdfd 100644 --- a/enable_if/test/dummy_arg_disambiguation.cpp +++ b/enable_if/test/dummy_arg_disambiguation.cpp @@ -6,7 +6,7 @@ // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) -// Authors: Jaakko Järvi (jajarvi at osl.iu.edu) +// Authors: Jaakko Jarvi (jajarvi at osl.iu.edu) // Jeremiah Willcock (jewillco at osl.iu.edu) // Andrew Lumsdaine (lums at osl.iu.edu) diff --git a/enable_if/test/lazy.cpp b/enable_if/test/lazy.cpp index 117ec41..f04111e 100644 --- a/enable_if/test/lazy.cpp +++ b/enable_if/test/lazy.cpp @@ -6,7 +6,7 @@ // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) -// Authors: Jaakko Järvi (jajarvi at osl.iu.edu) +// Authors: Jaakko Jarvi (jajarvi at osl.iu.edu) // Jeremiah Willcock (jewillco at osl.iu.edu) // Andrew Lumsdaine (lums at osl.iu.edu) diff --git a/enable_if/test/lazy_test.cpp b/enable_if/test/lazy_test.cpp index 10bb60c..9ec5324 100644 --- a/enable_if/test/lazy_test.cpp +++ b/enable_if/test/lazy_test.cpp @@ -6,7 +6,7 @@ // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) -// Authors: Jaakko Järvi (jajarvi at osl.iu.edu) +// Authors: Jaakko Jarvi (jajarvi at osl.iu.edu) // Jeremiah Willcock (jewillco at osl.iu.edu) // Andrew Lumsdaine (lums at osl.iu.edu) diff --git a/enable_if/test/member_templates.cpp b/enable_if/test/member_templates.cpp index f7c00a0..55e2d80 100644 --- a/enable_if/test/member_templates.cpp +++ b/enable_if/test/member_templates.cpp @@ -6,7 +6,7 @@ // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) -// Authors: Jaakko Järvi (jajarvi at osl.iu.edu) +// Authors: Jaakko Jarvi (jajarvi at osl.iu.edu) // Jeremiah Willcock (jewillco at osl.iu.edu) // Andrew Lumsdaine (lums at osl.iu.edu) diff --git a/enable_if/test/namespace_disambiguation.cpp b/enable_if/test/namespace_disambiguation.cpp index a53d3a7..45d4f0a 100644 --- a/enable_if/test/namespace_disambiguation.cpp +++ b/enable_if/test/namespace_disambiguation.cpp @@ -6,7 +6,7 @@ // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) -// Authors: Jaakko Järvi (jajarvi at osl.iu.edu) +// Authors: Jaakko Jarvi (jajarvi at osl.iu.edu) // Jeremiah Willcock (jewillco at osl.iu.edu) // Andrew Lumsdaine (lums at osl.iu.edu) diff --git a/enable_if/test/no_disambiguation.cpp b/enable_if/test/no_disambiguation.cpp index 122d600..e2416ed 100644 --- a/enable_if/test/no_disambiguation.cpp +++ b/enable_if/test/no_disambiguation.cpp @@ -6,7 +6,7 @@ // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) -// Authors: Jaakko Järvi (jajarvi at osl.iu.edu) +// Authors: Jaakko Jarvi (jajarvi at osl.iu.edu) // Jeremiah Willcock (jewillco at osl.iu.edu) // Andrew Lumsdaine (lums at osl.iu.edu) diff --git a/enable_if/test/partial_specializations.cpp b/enable_if/test/partial_specializations.cpp index 5c322ae..1d4db99 100644 --- a/enable_if/test/partial_specializations.cpp +++ b/enable_if/test/partial_specializations.cpp @@ -6,7 +6,7 @@ // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) -// Authors: Jaakko Järvi (jajarvi at osl.iu.edu) +// Authors: Jaakko Jarvi (jajarvi at osl.iu.edu) // Jeremiah Willcock (jewillco at osl.iu.edu) // Andrew Lumsdaine (lums at osl.iu.edu) From 34a27aaa3536c869df2671f92bf7beee6854ca5c Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Sun, 1 Jun 2014 02:17:34 +0300 Subject: [PATCH 106/144] Remove files left behind by the merge. --- addressof_fn_test.cpp | 76 ----------- addressof_np_test.cpp | 50 -------- addressof_test.cpp | 94 -------------- addressof_test2.cpp | 95 -------------- checked_delete_test.cpp | 28 ---- enable_if/test/Jamfile.v2 | 23 ---- enable_if/test/constructors.cpp | 62 --------- enable_if/test/dummy_arg_disambiguation.cpp | 46 ------- enable_if/test/lazy.cpp | 82 ------------ enable_if/test/lazy_test.cpp | 100 --------------- enable_if/test/member_templates.cpp | 43 ------- enable_if/test/namespace_disambiguation.cpp | 47 ------- enable_if/test/no_disambiguation.cpp | 43 ------- enable_if/test/partial_specializations.cpp | 67 ---------- ref_ct_test.cpp | 134 -------------------- ref_test.cpp | 121 ------------------ 16 files changed, 1111 deletions(-) delete mode 100644 addressof_fn_test.cpp delete mode 100644 addressof_np_test.cpp delete mode 100644 addressof_test.cpp delete mode 100644 addressof_test2.cpp delete mode 100644 checked_delete_test.cpp delete mode 100644 enable_if/test/Jamfile.v2 delete mode 100644 enable_if/test/constructors.cpp delete mode 100644 enable_if/test/dummy_arg_disambiguation.cpp delete mode 100644 enable_if/test/lazy.cpp delete mode 100644 enable_if/test/lazy_test.cpp delete mode 100644 enable_if/test/member_templates.cpp delete mode 100644 enable_if/test/namespace_disambiguation.cpp delete mode 100644 enable_if/test/no_disambiguation.cpp delete mode 100644 enable_if/test/partial_specializations.cpp delete mode 100644 ref_ct_test.cpp delete mode 100644 ref_test.cpp diff --git a/addressof_fn_test.cpp b/addressof_fn_test.cpp deleted file mode 100644 index 0d043bf..0000000 --- a/addressof_fn_test.cpp +++ /dev/null @@ -1,76 +0,0 @@ -#include - -#if defined(BOOST_MSVC) -#pragma warning(disable: 4786) // identifier truncated in debug info -#pragma warning(disable: 4710) // function not inlined -#pragma warning(disable: 4711) // function selected for automatic inline expansion -#pragma warning(disable: 4514) // unreferenced inline removed -#endif - -// addressof_fn_test.cpp: addressof( f ) -// -// Copyright (c) 2008, 2009 Peter Dimov -// -// 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 - - -void f0() -{ -} - -void f1(int) -{ -} - -void f2(int, int) -{ -} - -void f3(int, int, int) -{ -} - -void f4(int, int, int, int) -{ -} - -void f5(int, int, int, int, int) -{ -} - -void f6(int, int, int, int, int, int) -{ -} - -void f7(int, int, int, int, int, int, int) -{ -} - -void f8(int, int, int, int, int, int, int, int) -{ -} - -void f9(int, int, int, int, int, int, int, int, int) -{ -} - -int main() -{ - BOOST_TEST( boost::addressof( f0 ) == &f0 ); - BOOST_TEST( boost::addressof( f1 ) == &f1 ); - BOOST_TEST( boost::addressof( f2 ) == &f2 ); - BOOST_TEST( boost::addressof( f3 ) == &f3 ); - BOOST_TEST( boost::addressof( f4 ) == &f4 ); - BOOST_TEST( boost::addressof( f5 ) == &f5 ); - BOOST_TEST( boost::addressof( f6 ) == &f6 ); - BOOST_TEST( boost::addressof( f7 ) == &f7 ); - BOOST_TEST( boost::addressof( f8 ) == &f8 ); - BOOST_TEST( boost::addressof( f9 ) == &f9 ); - - return boost::report_errors(); -} diff --git a/addressof_np_test.cpp b/addressof_np_test.cpp deleted file mode 100644 index 9e155d4..0000000 --- a/addressof_np_test.cpp +++ /dev/null @@ -1,50 +0,0 @@ -// -// Copyright 2013 Peter Dimov -// -// 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 - -#if defined( BOOST_NO_CXX11_NULLPTR ) - -void nullptr_test() -{ -} - -#else - -void nullptr_test() -{ - { - auto x = nullptr; - BOOST_TEST( boost::addressof(x) == &x ); - } - - { - auto const x = nullptr; - BOOST_TEST( boost::addressof(x) == &x ); - } - - { - auto volatile x = nullptr; - BOOST_TEST( boost::addressof(x) == &x ); - } - - { - auto const volatile x = nullptr; - BOOST_TEST( boost::addressof(x) == &x ); - } -} - -#endif - -int main() -{ - nullptr_test(); - return boost::report_errors(); -} diff --git a/addressof_test.cpp b/addressof_test.cpp deleted file mode 100644 index 9619cc3..0000000 --- a/addressof_test.cpp +++ /dev/null @@ -1,94 +0,0 @@ -// Copyright (C) 2002 Brad King (brad.king@kitware.com) -// Douglas Gregor (gregod@cs.rpi.edu) -// -// 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 - - -#include - -#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300) -#pragma warning(push, 3) -#endif - -#include - -#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300) -#pragma warning(pop) -#endif - -#include - -template void scalar_test( T * = 0 ) -{ - T* px = new T(); - - T& x = *px; - BOOST_TEST( boost::addressof(x) == px ); - - const T& cx = *px; - const T* pcx = boost::addressof(cx); - BOOST_TEST( pcx == px ); - - volatile T& vx = *px; - volatile T* pvx = boost::addressof(vx); - BOOST_TEST( pvx == px ); - - const volatile T& cvx = *px; - const volatile T* pcvx = boost::addressof(cvx); - BOOST_TEST( pcvx == px ); - - delete px; -} - -template void array_test( T * = 0 ) -{ - T nrg[3] = {1,2,3}; - T (*pnrg)[3] = &nrg; - BOOST_TEST( boost::addressof(nrg) == pnrg ); - - T const cnrg[3] = {1,2,3}; - T const (*pcnrg)[3] = &cnrg; - BOOST_TEST( boost::addressof(cnrg) == pcnrg ); -} - -struct addressable -{ - addressable( int = 0 ) - { - } -}; - -struct useless_type {}; - -class nonaddressable { -public: - - nonaddressable( int = 0 ) - { - } - - void dummy(); // Silence GCC warning: all member of class are private - -private: - - useless_type operator&() const; -}; - -int main() -{ - scalar_test(); - scalar_test(); - scalar_test(); - scalar_test(); - - array_test(); - array_test(); - array_test(); - array_test(); - - return boost::report_errors(); -} diff --git a/addressof_test2.cpp b/addressof_test2.cpp deleted file mode 100644 index b1c36f8..0000000 --- a/addressof_test2.cpp +++ /dev/null @@ -1,95 +0,0 @@ -// Copyright (C) 2002 Brad King (brad.king@kitware.com) -// Douglas Gregor (gregod@cs.rpi.edu) -// -// Copyright 2009 Peter Dimov -// -// 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 - - -#include - -#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300) -#pragma warning(push, 3) -#endif - -#include - -#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300) -#pragma warning(pop) -#endif - -#include - -template void scalar_test( T * = 0 ) -{ - T* px = new T(); - - T& x = *px; - BOOST_TEST( boost::addressof(x) == px ); - - const T& cx = *px; - const T* pcx = boost::addressof(cx); - BOOST_TEST( pcx == px ); - - volatile T& vx = *px; - volatile T* pvx = boost::addressof(vx); - BOOST_TEST( pvx == px ); - - const volatile T& cvx = *px; - const volatile T* pcvx = boost::addressof(cvx); - BOOST_TEST( pcvx == px ); - - delete px; -} - -template void array_test( T * = 0 ) -{ - T nrg[3] = {1,2,3}; - T (*pnrg)[3] = &nrg; - BOOST_TEST( boost::addressof(nrg) == pnrg ); - - T const cnrg[3] = {1,2,3}; - T const (*pcnrg)[3] = &cnrg; - BOOST_TEST( boost::addressof(cnrg) == pcnrg ); -} - -class convertible { -public: - - convertible( int = 0 ) - { - } - - template operator U () const - { - return U(); - } -}; - -class convertible2 { -public: - - convertible2( int = 0 ) - { - } - - operator convertible2* () const - { - return 0; - } -}; - -int main() -{ - scalar_test(); - scalar_test(); - - array_test(); - array_test(); - - return boost::report_errors(); -} diff --git a/checked_delete_test.cpp b/checked_delete_test.cpp deleted file mode 100644 index 41fdc9a..0000000 --- a/checked_delete_test.cpp +++ /dev/null @@ -1,28 +0,0 @@ -// Boost checked_delete test program ---------------------------------------// - -// Copyright Beman Dawes 2001. 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/utility for documentation. - -// Revision History -// 21 May 01 Initial version (Beman Dawes) - -#include // for checked_delete - -// This program demonstrates compiler errors when trying to delete an -// incomplete type. - -namespace -{ - class Incomplete; -} - -int main() -{ - Incomplete * p = 0; - boost::checked_delete(p); // should cause compile time error - boost::checked_array_delete(p); // should cause compile time error - return 0; -} // main diff --git a/enable_if/test/Jamfile.v2 b/enable_if/test/Jamfile.v2 deleted file mode 100644 index 77a8798..0000000 --- a/enable_if/test/Jamfile.v2 +++ /dev/null @@ -1,23 +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) - -# For more information, see http://www.boost.org/ - -project - : requirements /boost/test//boost_test_exec_monitor - ; - -test-suite utility/enable_if - : - [ run constructors.cpp ] - [ run dummy_arg_disambiguation.cpp ] - [ run lazy.cpp ] - [ run lazy_test.cpp ] - [ run member_templates.cpp ] - [ run namespace_disambiguation.cpp ] - [ run no_disambiguation.cpp ] - [ run partial_specializations.cpp ] - ; - diff --git a/enable_if/test/constructors.cpp b/enable_if/test/constructors.cpp deleted file mode 100644 index 0d465de..0000000 --- a/enable_if/test/constructors.cpp +++ /dev/null @@ -1,62 +0,0 @@ -// Boost enable_if library - -// Copyright 2003 (c) The Trustees of Indiana University. - -// Use, modification, and distribution is subject to 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) - -// Authors: Jaakko Jarvi (jajarvi at osl.iu.edu) -// Jeremiah Willcock (jewillco at osl.iu.edu) -// Andrew Lumsdaine (lums at osl.iu.edu) - -#include - -#include -#include - -using boost::enable_if; -using boost::disable_if; -using boost::is_arithmetic; - -struct container { - bool my_value; - - template - container(const T&, const typename enable_if, T>::type * = 0): - my_value(true) {} - - template - container(const T&, const typename disable_if, T>::type * = 0): - my_value(false) {} -}; - -// example from Howard Hinnant (tests enable_if template members of a templated class) -template -struct xstring -{ - template - xstring(It begin, It end, typename - disable_if >::type* = 0) - : data(end-begin) {} - - int data; -}; - - -int test_main(int, char*[]) -{ - - BOOST_CHECK(container(1).my_value); - BOOST_CHECK(container(1.0).my_value); - - BOOST_CHECK(!container("1").my_value); - BOOST_CHECK(!container(static_cast(0)).my_value); - - char sa[] = "123456"; - BOOST_CHECK(xstring(sa, sa+6).data == 6); - - - return 0; -} - diff --git a/enable_if/test/dummy_arg_disambiguation.cpp b/enable_if/test/dummy_arg_disambiguation.cpp deleted file mode 100644 index 60dfdfd..0000000 --- a/enable_if/test/dummy_arg_disambiguation.cpp +++ /dev/null @@ -1,46 +0,0 @@ -// Boost enable_if library - -// Copyright 2003 (c) The Trustees of Indiana University. - -// Use, modification, and distribution is subject to 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) - -// Authors: Jaakko Jarvi (jajarvi at osl.iu.edu) -// Jeremiah Willcock (jewillco at osl.iu.edu) -// Andrew Lumsdaine (lums at osl.iu.edu) - -#include - -#include -#include - -using boost::enable_if; -using boost::disable_if; -using boost::is_arithmetic; - -template struct dummy { - dummy(int) {}; -}; - -template -typename enable_if, bool>::type -arithmetic_object(T t, dummy<0> = 0) { return true; } - -template -typename disable_if, bool>::type -arithmetic_object(T t, dummy<1> = 0) { return false; } - - -int test_main(int, char*[]) -{ - - BOOST_CHECK(arithmetic_object(1)); - BOOST_CHECK(arithmetic_object(1.0)); - - BOOST_CHECK(!arithmetic_object("1")); - BOOST_CHECK(!arithmetic_object(static_cast(0))); - - return 0; -} - diff --git a/enable_if/test/lazy.cpp b/enable_if/test/lazy.cpp deleted file mode 100644 index f04111e..0000000 --- a/enable_if/test/lazy.cpp +++ /dev/null @@ -1,82 +0,0 @@ -// Boost enable_if library - -// Copyright 2003 (c) The Trustees of Indiana University. - -// Use, modification, and distribution is subject to 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) - -// Authors: Jaakko Jarvi (jajarvi at osl.iu.edu) -// Jeremiah Willcock (jewillco at osl.iu.edu) -// Andrew Lumsdaine (lums at osl.iu.edu) - -#include - -#include -#include - -using boost::enable_if_c; -using boost::lazy_enable_if_c; - -// This class provides a reduced example of a traits class for -// computing the result of multiplying two types. The member typedef -// 'type' in this traits class defines the return type of this -// operator. The return type member is invalid unless both arguments -// for mult_traits are values that mult_traits expects (ints in this -// case). This kind of situation may arise if a traits class only -// makes sense for some set of types, not all C++ types. - -template struct is_int { - BOOST_STATIC_CONSTANT(bool, value = (boost::is_same::value)); -}; - -template -struct mult_traits { - typedef typename T::does_not_exist type; -}; - -template <> -struct mult_traits { - typedef int type; -}; - - -// Next, a forwarding function mult() is defined. It is enabled only -// when both arguments are of type int. The first version, using -// non-lazy enable_if_c does not work. - -#if 0 -template -typename enable_if_c< - is_int::value && is_int::value, - typename mult_traits::type ->::type -mult(const T& x, const U& y) {return x * y;} -#endif - -// A correct version uses lazy_enable_if_c. -// This template removes compiler errors from invalid code used as an -// argument to enable_if_c. - -#if 1 -template -typename lazy_enable_if_c< - is_int::value & is_int::value, - mult_traits ->::type -mult(const T& x, const U& y) {return x * y;} -#endif - -double mult(int i, double d) { return (double)i * d; } - -int test_main(int, char*[]) -{ - - - BOOST_CHECK(mult(1, 2) == 2); - - BOOST_CHECK(mult(1, 3.0) == 3.0); - - return 0; -} - diff --git a/enable_if/test/lazy_test.cpp b/enable_if/test/lazy_test.cpp deleted file mode 100644 index 9ec5324..0000000 --- a/enable_if/test/lazy_test.cpp +++ /dev/null @@ -1,100 +0,0 @@ -// Boost enable_if library - -// Copyright 2003 (c) The Trustees of Indiana University. - -// Use, modification, and distribution is subject to 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) - -// Authors: Jaakko Jarvi (jajarvi at osl.iu.edu) -// Jeremiah Willcock (jewillco at osl.iu.edu) -// Andrew Lumsdaine (lums at osl.iu.edu) - -// Testing all variations of lazy_enable_if. - -#include -#include - -#include -#include - -using boost::lazy_enable_if; -using boost::lazy_disable_if; - -using boost::lazy_enable_if_c; -using boost::lazy_disable_if_c; - - -template -struct is_int_or_double { - BOOST_STATIC_CONSTANT(bool, - value = (boost::is_same::value || - boost::is_same::value)); -}; - -template -struct some_traits { - typedef typename T::does_not_exist type; -}; - -template <> -struct some_traits { - typedef bool type; -}; - -template <> -struct some_traits { - typedef bool type; -}; - -template -struct make_bool { - typedef bool type; -}; - -template <> -struct make_bool {}; - -template <> -struct make_bool {}; - -namespace A { - - template - typename lazy_enable_if, some_traits >::type - foo(T t) { return true; } - - template - typename lazy_enable_if_c::value, some_traits >::type - foo2(T t) { return true; } -} - -namespace B { - template - typename lazy_disable_if, make_bool >::type - foo(T t) { return false; } - - template - typename lazy_disable_if_c::value, make_bool >::type - foo2(T t) { return false; } -} - -int test_main(int, char*[]) -{ - using namespace A; - using namespace B; - BOOST_CHECK(foo(1)); - BOOST_CHECK(foo(1.0)); - - BOOST_CHECK(!foo("1")); - BOOST_CHECK(!foo(static_cast(0))); - - BOOST_CHECK(foo2(1)); - BOOST_CHECK(foo2(1.0)); - - BOOST_CHECK(!foo2("1")); - BOOST_CHECK(!foo2(static_cast(0))); - - return 0; -} - diff --git a/enable_if/test/member_templates.cpp b/enable_if/test/member_templates.cpp deleted file mode 100644 index 55e2d80..0000000 --- a/enable_if/test/member_templates.cpp +++ /dev/null @@ -1,43 +0,0 @@ -// Boost enable_if library - -// Copyright 2003 (c) The Trustees of Indiana University. - -// Use, modification, and distribution is subject to 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) - -// Authors: Jaakko Jarvi (jajarvi at osl.iu.edu) -// Jeremiah Willcock (jewillco at osl.iu.edu) -// Andrew Lumsdaine (lums at osl.iu.edu) - -#include - -#include -#include - -using boost::enable_if; -using boost::disable_if; -using boost::is_arithmetic; - -struct container { - template - typename enable_if, bool>::type - arithmetic_object(const T&, const int* /* disambiguate */ = 0) {return true;} - - template - typename disable_if, bool>::type - arithmetic_object(const T&) {return false;} -}; - -int test_main(int, char*[]) -{ - - BOOST_CHECK(container().arithmetic_object(1)); - BOOST_CHECK(container().arithmetic_object(1.0)); - - BOOST_CHECK(!container().arithmetic_object("1")); - BOOST_CHECK(!container().arithmetic_object(static_cast(0))); - - return 0; -} - diff --git a/enable_if/test/namespace_disambiguation.cpp b/enable_if/test/namespace_disambiguation.cpp deleted file mode 100644 index 45d4f0a..0000000 --- a/enable_if/test/namespace_disambiguation.cpp +++ /dev/null @@ -1,47 +0,0 @@ -// Boost enable_if library - -// Copyright 2003 (c) The Trustees of Indiana University. - -// Use, modification, and distribution is subject to 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) - -// Authors: Jaakko Jarvi (jajarvi at osl.iu.edu) -// Jeremiah Willcock (jewillco at osl.iu.edu) -// Andrew Lumsdaine (lums at osl.iu.edu) - -#include -#include - -#include -#include - -using boost::enable_if; -using boost::mpl::not_; -using boost::is_arithmetic; - -namespace A { - template - typename enable_if, bool>::type - arithmetic_object(T t) { return true; } -} - -namespace B { - template - typename enable_if >, bool>::type - arithmetic_object(T t) { return false; } -} - -int test_main(int, char*[]) -{ - using namespace A; - using namespace B; - BOOST_CHECK(arithmetic_object(1)); - BOOST_CHECK(arithmetic_object(1.0)); - - BOOST_CHECK(!arithmetic_object("1")); - BOOST_CHECK(!arithmetic_object(static_cast(0))); - - return 0; -} - diff --git a/enable_if/test/no_disambiguation.cpp b/enable_if/test/no_disambiguation.cpp deleted file mode 100644 index e2416ed..0000000 --- a/enable_if/test/no_disambiguation.cpp +++ /dev/null @@ -1,43 +0,0 @@ -// Boost enable_if library - -// Copyright 2003 (c) The Trustees of Indiana University. - -// Use, modification, and distribution is subject to 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) - -// Authors: Jaakko Jarvi (jajarvi at osl.iu.edu) -// Jeremiah Willcock (jewillco at osl.iu.edu) -// Andrew Lumsdaine (lums at osl.iu.edu) - -#include -#include - -#include -#include - -using boost::mpl::not_; -using boost::enable_if; -using boost::is_arithmetic; - -template -typename enable_if, bool>::type -arithmetic_object(T t) { return true; } - -template -typename enable_if >, bool>::type -arithmetic_object(T t) { return false; } - - -int test_main(int, char*[]) -{ - - BOOST_CHECK(arithmetic_object(1)); - BOOST_CHECK(arithmetic_object(1.0)); - - BOOST_CHECK(!arithmetic_object("1")); - BOOST_CHECK(!arithmetic_object(static_cast(0))); - - return 0; -} - diff --git a/enable_if/test/partial_specializations.cpp b/enable_if/test/partial_specializations.cpp deleted file mode 100644 index 1d4db99..0000000 --- a/enable_if/test/partial_specializations.cpp +++ /dev/null @@ -1,67 +0,0 @@ -// Boost enable_if library - -// Copyright 2003 (c) The Trustees of Indiana University. - -// Use, modification, and distribution is subject to 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) - -// Authors: Jaakko Jarvi (jajarvi at osl.iu.edu) -// Jeremiah Willcock (jewillco at osl.iu.edu) -// Andrew Lumsdaine (lums at osl.iu.edu) - -#include - -#include -#include - -using boost::enable_if_c; -using boost::disable_if_c; -using boost::enable_if; -using boost::disable_if; -using boost::is_arithmetic; - -template -struct tester; - -template -struct tester::value>::type> { - BOOST_STATIC_CONSTANT(bool, value = true); -}; - -template -struct tester::value>::type> { - BOOST_STATIC_CONSTANT(bool, value = false); -}; - -template -struct tester2; - -template -struct tester2 >::type> { - BOOST_STATIC_CONSTANT(bool, value = true); -}; - -template -struct tester2 >::type> { - BOOST_STATIC_CONSTANT(bool, value = false); -}; - -int test_main(int, char*[]) -{ - - BOOST_CHECK(tester::value); - BOOST_CHECK(tester::value); - - BOOST_CHECK(!tester::value); - BOOST_CHECK(!tester::value); - - BOOST_CHECK(tester2::value); - BOOST_CHECK(tester2::value); - - BOOST_CHECK(!tester2::value); - BOOST_CHECK(!tester2::value); - - return 0; -} - diff --git a/ref_ct_test.cpp b/ref_ct_test.cpp deleted file mode 100644 index a3b5eea..0000000 --- a/ref_ct_test.cpp +++ /dev/null @@ -1,134 +0,0 @@ -// Copyright David Abrahams and Aleksey Gurtovoy -// 2002-2004. 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) - -// compile-time test for "boost/ref.hpp" header content -// see 'ref_test.cpp' for run-time part - -#include -#include -#include -#include -#include - -#include - -namespace { - -template< typename T, typename U > -void ref_test(boost::reference_wrapper) -{ - typedef typename boost::reference_wrapper::type type; - BOOST_STATIC_ASSERT((boost::is_same::value)); - BOOST_STATIC_ASSERT((boost::is_same::value)); -} - -template< typename T > -void assignable_test(T x) -{ - x = x; -} - -template< bool R, typename T > -void is_reference_wrapper_test(T) -{ - BOOST_STATIC_ASSERT(boost::is_reference_wrapper::value == R); -} - -template< typename R, typename Ref > -void cxx_reference_test(Ref) -{ -#if BOOST_WORKAROUND(__BORLANDC__, < 0x600) - typedef typename boost::remove_const::type ref; - BOOST_STATIC_ASSERT((boost::is_same::value)); -#else - BOOST_STATIC_ASSERT((boost::is_same::value)); -#endif -} - -template< typename R, typename Ref > -void unwrap_reference_test(Ref) -{ -#if BOOST_WORKAROUND(__BORLANDC__, < 0x600) - typedef typename boost::remove_const::type ref; - typedef typename boost::unwrap_reference::type type; -#else - typedef typename boost::unwrap_reference::type type; -#endif - BOOST_STATIC_ASSERT((boost::is_same::value)); -} - -} // namespace - -int main() -{ - int i = 0; - int& ri = i; - - int const ci = 0; - int const& rci = ci; - - // 'ref/cref' functions test - ref_test(boost::ref(i)); - ref_test(boost::ref(ri)); - ref_test(boost::ref(ci)); - ref_test(boost::ref(rci)); - - ref_test(boost::cref(i)); - ref_test(boost::cref(ri)); - ref_test(boost::cref(ci)); - ref_test(boost::cref(rci)); - - // test 'assignable' requirement - assignable_test(boost::ref(i)); - assignable_test(boost::ref(ri)); - assignable_test(boost::cref(i)); - assignable_test(boost::cref(ci)); - assignable_test(boost::cref(rci)); - - // 'is_reference_wrapper' test - is_reference_wrapper_test(boost::ref(i)); - is_reference_wrapper_test(boost::ref(ri)); - is_reference_wrapper_test(boost::cref(i)); - is_reference_wrapper_test(boost::cref(ci)); - is_reference_wrapper_test(boost::cref(rci)); - - is_reference_wrapper_test(i); - is_reference_wrapper_test(ri); - is_reference_wrapper_test(ci); - is_reference_wrapper_test(rci); - - // ordinary references/function template arguments deduction test - cxx_reference_test(i); - cxx_reference_test(ri); - cxx_reference_test(ci); - cxx_reference_test(rci); - - cxx_reference_test(i); - cxx_reference_test(ri); - cxx_reference_test(i); - cxx_reference_test(ri); - cxx_reference_test(ci); - cxx_reference_test(rci); - - // 'unwrap_reference' test - unwrap_reference_test(boost::ref(i)); - unwrap_reference_test(boost::ref(ri)); - unwrap_reference_test(boost::cref(i)); - unwrap_reference_test(boost::cref(ci)); - unwrap_reference_test(boost::cref(rci)); - - unwrap_reference_test(i); - unwrap_reference_test(ri); - unwrap_reference_test(ci); - unwrap_reference_test(rci); - unwrap_reference_test(i); - unwrap_reference_test(ri); - unwrap_reference_test(i); - unwrap_reference_test(ri); - unwrap_reference_test(ci); - unwrap_reference_test(rci); - - return 0; -} diff --git a/ref_test.cpp b/ref_test.cpp deleted file mode 100644 index 71481fa..0000000 --- a/ref_test.cpp +++ /dev/null @@ -1,121 +0,0 @@ -// Copyright David Abrahams and Aleksey Gurtovoy -// 2002-2004. 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) - -// run-time test for "boost/ref.hpp" header content -// see 'ref_ct_test.cpp' for compile-time part - -#if defined(_MSC_VER) && !defined(__ICL) -# pragma warning(disable: 4786) // identifier truncated in debug info -# pragma warning(disable: 4710) // function not inlined -# pragma warning(disable: 4711) // function selected for automatic inline expansion -# pragma warning(disable: 4514) // unreferenced inline removed -#endif - -#include - -#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300) -# pragma warning(push, 3) -#endif - -#include - -#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300) -# pragma warning(pop) -#endif - - -#define BOOST_INCLUDE_MAIN -#include - -namespace { -using namespace boost; - -template -struct ref_wrapper -{ - // Used to verify implicit conversion - static T* get_pointer(T& x) - { - return &x; - } - - static T const* get_const_pointer(T const& x) - { - return &x; - } - - template - static T* passthru(Arg x) - { - return get_pointer(x); - } - - template - static T const* cref_passthru(Arg x) - { - return get_const_pointer(x); - } - - static void test(T x) - { - BOOST_CHECK(passthru(ref(x)) == &x); - BOOST_CHECK(&ref(x).get() == &x); - - BOOST_CHECK(cref_passthru(cref(x)) == &x); - BOOST_CHECK(&cref(x).get() == &x); - } -}; - -struct copy_counter { - static int count_; - copy_counter(copy_counter const& /*other*/) { - ++count_; - } - copy_counter() {} - static void reset() { count_ = 0; } - static int count() { return copy_counter::count_; } -}; - -int copy_counter::count_ = 0; - -} // namespace unnamed - -template -void do_unwrap(T t) { - - /* typename unwrap_reference::type& lt = */ - unwrap_ref(t); - -} - -void unwrap_test() { - - int i = 3; - const int ci = 2; - - do_unwrap(i); - do_unwrap(ci); - do_unwrap(ref(i)); - do_unwrap(cref(ci)); - do_unwrap(ref(ci)); - - copy_counter cc; - BOOST_CHECK(cc.count() == 0); - - do_unwrap(cc); - do_unwrap(ref(cc)); - do_unwrap(cref(cc)); - - BOOST_CHECK(cc.count() == 1); - BOOST_CHECK(unwrap_ref(ref(cc)).count() == 1); -} - -int test_main(int, char * []) -{ - ref_wrapper::test(1); - ref_wrapper::test(1); - unwrap_test(); - return 0; -} From 1e5993f34a64bed8e57aaf6d28ebcf6bd419894a Mon Sep 17 00:00:00 2001 From: Andrey Semashev Date: Sun, 1 Sep 2013 16:31:16 +0000 Subject: [PATCH 107/144] Extracted BOOST_EXPLICIT_OPERATOR_BOOL macro from Boost.Log. [SVN r85543] --- doc/explicit_operator_bool.qbk | 68 ++++++++++ .../boost/utility/explicit_operator_bool.hpp | 128 ++++++++++++++++++ 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 ++++++ 7 files changed, 410 insertions(+) create mode 100644 doc/explicit_operator_bool.qbk create mode 100644 include/boost/utility/explicit_operator_bool.hpp create mode 100644 test/explicit_operator_bool.cpp create mode 100644 test/explicit_operator_bool_compile_fail_conv_int.cpp create mode 100644 test/explicit_operator_bool_compile_fail_conv_pvoid.cpp create mode 100644 test/explicit_operator_bool_compile_fail_delete.cpp create mode 100644 test/explicit_operator_bool_compile_fail_shift.cpp diff --git a/doc/explicit_operator_bool.qbk b/doc/explicit_operator_bool.qbk new file mode 100644 index 0000000..4a7e4b1 --- /dev/null +++ b/doc/explicit_operator_bool.qbk @@ -0,0 +1,68 @@ +[/ + / 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 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()` 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/include/boost/utility/explicit_operator_bool.hpp b/include/boost/utility/explicit_operator_bool.hpp new file mode 100644 index 0000000..8843e0c --- /dev/null +++ b/include/boost/utility/explicit_operator_bool.hpp @@ -0,0 +1,128 @@ +/* + * 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 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\ + {\ + 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) + + 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 is too eager to convert pointer to function to void* even though it 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_CONSTEXPR_EXPLICIT_OPERATOR_BOOL()\ + BOOST_FORCEINLINE BOOST_CONSTEXPR operator boost::detail::unspecified_bool_type () const\ + {\ + 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_CONSTEXPR_EXPLICIT_OPERATOR_BOOL()\ + BOOST_FORCEINLINE BOOST_CONSTEXPR operator bool () const\ + {\ + 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/test/explicit_operator_bool.cpp b/test/explicit_operator_bool.cpp new file mode 100644 index 0000000..07dd01b --- /dev/null +++ b/test/explicit_operator_bool.cpp @@ -0,0 +1,54 @@ +/* + * 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.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_compile + +#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 new file mode 100644 index 0000000..384f2ab --- /dev/null +++ b/test/explicit_operator_bool_compile_fail_conv_int.cpp @@ -0,0 +1,40 @@ +/* + * 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 new file mode 100644 index 0000000..0c007ba --- /dev/null +++ b/test/explicit_operator_bool_compile_fail_conv_pvoid.cpp @@ -0,0 +1,40 @@ +/* + * 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 new file mode 100644 index 0000000..d780f94 --- /dev/null +++ b/test/explicit_operator_bool_compile_fail_delete.cpp @@ -0,0 +1,40 @@ +/* + * 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 new file mode 100644 index 0000000..ce563a6 --- /dev/null +++ b/test/explicit_operator_bool_compile_fail_shift.cpp @@ -0,0 +1,40 @@ +/* + * 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; +} From 83ffbc7678f867ec9ad854052beee9081e47159b Mon Sep 17 00:00:00 2001 From: Andrey Semashev Date: Thu, 5 Sep 2013 08:28:24 +0000 Subject: [PATCH 108/144] Attempt to work around explicit_operator_bool_compile_fail_conv_pvoid test failure for VACPP. [SVN r85570] --- include/boost/utility/explicit_operator_bool.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/boost/utility/explicit_operator_bool.hpp b/include/boost/utility/explicit_operator_bool.hpp index 8843e0c..650caff 100644 --- a/include/boost/utility/explicit_operator_bool.hpp +++ b/include/boost/utility/explicit_operator_bool.hpp @@ -64,7 +64,7 @@ namespace boost { namespace detail { -#if !defined(_MSC_VER) +#if !defined(_MSC_VER) && !defined(__IBMCPP__) struct unspecified_bool { @@ -78,7 +78,7 @@ namespace detail { #else - // MSVC is too eager to convert pointer to function to void* even though it shouldn't + // 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 From 4652fa7415c18c7d04bbf4ceee1eb39ef7e1c6af Mon Sep 17 00:00:00 2001 From: Andrey Semashev Date: Sat, 26 Apr 2014 15:11:35 +0400 Subject: [PATCH 109/144] Added a new macro BOOST_EXPLICIT_OPERATOR_BOOL_NOEXCEPT, which implements a noexcept operator. Also added explicit noexcept specification for the constexpr macro. --- doc/explicit_operator_bool.qbk | 8 +- .../boost/utility/explicit_operator_bool.hpp | 31 ++++++- test/explicit_operator_bool.cpp | 4 +- test/explicit_operator_bool_noexcept.cpp | 89 +++++++++++++++++++ 4 files changed, 121 insertions(+), 11 deletions(-) create mode 100644 test/explicit_operator_bool_noexcept.cpp diff --git a/doc/explicit_operator_bool.qbk b/doc/explicit_operator_bool.qbk index 4a7e4b1..64c5be4 100644 --- a/doc/explicit_operator_bool.qbk +++ b/doc/explicit_operator_bool.qbk @@ -5,7 +5,7 @@ / file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) /] -[article BOOST_EXPLICIT_OPERATOR_BOOL and BOOST_CONSTEXPR_EXPLICIT_OPERATOR_BOOL +[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] @@ -20,7 +20,7 @@ [section Overview] [/===============] -`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 [@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`. +`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] @@ -62,7 +62,3 @@ Now `my_ptr` can be used in conditional expressions, similarly to a regular poin * The macro was extracted from Boost.Log. [endsect] - - - - diff --git a/include/boost/utility/explicit_operator_bool.hpp b/include/boost/utility/explicit_operator_bool.hpp index 650caff..e16f34d 100644 --- a/include/boost/utility/explicit_operator_bool.hpp +++ b/include/boost/utility/explicit_operator_bool.hpp @@ -38,6 +38,19 @@ 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 * @@ -46,7 +59,7 @@ * 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_FORCEINLINE BOOST_CONSTEXPR explicit operator bool () const BOOST_NOEXCEPT\ {\ return !this->operator! ();\ } @@ -101,8 +114,14 @@ namespace detail { 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_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);\ } @@ -115,8 +134,14 @@ namespace detail { 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_FORCEINLINE BOOST_CONSTEXPR operator bool () const BOOST_NOEXCEPT\ {\ return !this->operator! ();\ } diff --git a/test/explicit_operator_bool.cpp b/test/explicit_operator_bool.cpp index 07dd01b..5e85259 100644 --- a/test/explicit_operator_bool.cpp +++ b/test/explicit_operator_bool.cpp @@ -5,7 +5,7 @@ * http://www.boost.org/LICENSE_1_0.txt) */ /*! - * \file explicit_operator_bool_compile.cpp + * \file explicit_operator_bool.cpp * \author Andrey Semashev * \date 17.07.2010 * @@ -13,7 +13,7 @@ * the valid contexts. */ -#define BOOST_TEST_MODULE explicit_operator_bool_compile +#define BOOST_TEST_MODULE explicit_operator_bool #include diff --git a/test/explicit_operator_bool_noexcept.cpp b/test/explicit_operator_bool_noexcept.cpp new file mode 100644 index 0000000..c645cca --- /dev/null +++ b/test/explicit_operator_bool_noexcept.cpp @@ -0,0 +1,89 @@ +/* + * 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 From dc3212c4c2efac81105d36f4eae1ccc31613c263 Mon Sep 17 00:00:00 2001 From: Andrey Semashev Date: Thu, 5 Sep 2013 18:25:41 +0000 Subject: [PATCH 110/144] Extracted empty_deleter to Boost.Utility. [SVN r85577] --- include/boost/utility/empty_deleter.hpp | 43 +++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 include/boost/utility/empty_deleter.hpp diff --git a/include/boost/utility/empty_deleter.hpp b/include/boost/utility/empty_deleter.hpp new file mode 100644 index 0000000..ba919cd --- /dev/null +++ b/include/boost/utility/empty_deleter.hpp @@ -0,0 +1,43 @@ +/* + * 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_ From d814b6425d1315308c66ef8a5b5e7e2a75d25482 Mon Sep 17 00:00:00 2001 From: Joseph Gauterin Date: Sat, 5 Jul 2008 11:16:38 +0000 Subject: [PATCH 111/144] Moved utility\swap to the trunk, as discussed in trac issue #2056. [SVN r47093] --- include/boost/utility/swap.hpp | 51 +++++++++ swap.html | 94 +++++++++++++++ swap/test/Jamfile.v2 | 53 +++++++++ swap/test/lib_header_1.cpp | 18 +++ swap/test/lib_header_2.cpp | 20 ++++ swap/test/mixed_headers_1.cpp | 20 ++++ swap/test/mixed_headers_2.cpp | 20 ++++ swap/test/primitive.cpp | 44 +++++++ swap/test/root_header_1.cpp | 18 +++ swap/test/root_header_2.cpp | 20 ++++ swap/test/specialized_in_boost.cpp | 72 ++++++++++++ swap/test/specialized_in_global.cpp | 60 ++++++++++ swap/test/specialized_in_other.cpp | 72 ++++++++++++ swap/test/specialized_in_std.cpp | 70 ++++++++++++ swap/test/swap_arrays.cpp | 78 +++++++++++++ swap/test/swap_test_class.hpp | 171 ++++++++++++++++++++++++++++ 16 files changed, 881 insertions(+) create mode 100644 include/boost/utility/swap.hpp create mode 100644 swap.html create mode 100644 swap/test/Jamfile.v2 create mode 100644 swap/test/lib_header_1.cpp create mode 100644 swap/test/lib_header_2.cpp create mode 100644 swap/test/mixed_headers_1.cpp create mode 100644 swap/test/mixed_headers_2.cpp create mode 100644 swap/test/primitive.cpp create mode 100644 swap/test/root_header_1.cpp create mode 100644 swap/test/root_header_2.cpp create mode 100644 swap/test/specialized_in_boost.cpp create mode 100644 swap/test/specialized_in_global.cpp create mode 100644 swap/test/specialized_in_other.cpp create mode 100644 swap/test/specialized_in_std.cpp create mode 100644 swap/test/swap_arrays.cpp create mode 100644 swap/test/swap_test_class.hpp diff --git a/include/boost/utility/swap.hpp b/include/boost/utility/swap.hpp new file mode 100644 index 0000000..952adf5 --- /dev/null +++ b/include/boost/utility/swap.hpp @@ -0,0 +1,51 @@ +// Copyright (C) 2007, 2008 Steven Watanabe, 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) +// For more information, see http://www.boost.org +// +// Update: +// 29 June 2008 (Added support for built-in arrays.) Niels Dekker + + +#ifndef BOOST_UTILITY_SWAP_HPP +#define BOOST_UTILITY_SWAP_HPP + +#include //for std::swap +#include //for std::size_t + +namespace boost_swap_impl +{ + template + void swap_impl(T& left, T& right) + { + using std::swap;//use std::swap if argument dependent lookup fails + swap(left,right); + } + + template + 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 +{ + namespace swap_adl_barrier + { + template + void swap(T& left, T& right) + { + ::boost_swap_impl::swap_impl(left, right); + } + } + + using swap_adl_barrier::swap; +} + +#endif diff --git a/swap.html b/swap.html new file mode 100644 index 0000000..e317b11 --- /dev/null +++ b/swap.html @@ -0,0 +1,94 @@ +? + + + + + Boost: Swap Documentation + + + + C++ Boost +

    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 doesn't yet do so, but a request to add an overload of std::swap for built-in arrays has been well-received by the Library Working Group of 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 Wanatabe - for the idea to use a barrier namespace, enabling the function to have the name 'swap' without introducing ambiguity or infinite recursion +
    • +
    + + +
    +

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

    +

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

    + + +
    +

    Revised: 3 July 2008

    +

    + Copyright 2007, 2008 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 new file mode 100644 index 0000000..758bdaa --- /dev/null +++ b/swap/test/Jamfile.v2 @@ -0,0 +1,53 @@ +# 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 swap_arrays.cpp ../../../test/build//boost_test_exec_monitor/static ] + ; + + +# 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 swap_arrays.cpp ../../../test/build//boost_test_exec_monitor/static ] + ; + + + diff --git a/swap/test/lib_header_1.cpp b/swap/test/lib_header_1.cpp new file mode 100644 index 0000000..ea7c99a --- /dev/null +++ b/swap/test/lib_header_1.cpp @@ -0,0 +1,18 @@ +// 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 +// 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 new file mode 100644 index 0000000..0c9e409 --- /dev/null +++ b/swap/test/lib_header_2.cpp @@ -0,0 +1,20 @@ +// 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 +// 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 new file mode 100644 index 0000000..0c7571e --- /dev/null +++ b/swap/test/mixed_headers_1.cpp @@ -0,0 +1,20 @@ +// 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 +// 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 new file mode 100644 index 0000000..217873a --- /dev/null +++ b/swap/test/mixed_headers_2.cpp @@ -0,0 +1,20 @@ +// 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 +// 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/primitive.cpp b/swap/test/primitive.cpp new file mode 100644 index 0000000..76cd7b0 --- /dev/null +++ b/swap/test/primitive.cpp @@ -0,0 +1,44 @@ +// 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; +} +// 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 new file mode 100644 index 0000000..efa0028 --- /dev/null +++ b/swap/test/root_header_1.cpp @@ -0,0 +1,18 @@ +// 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 +// 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 new file mode 100644 index 0000000..d7e00f3 --- /dev/null +++ b/swap/test/root_header_2.cpp @@ -0,0 +1,20 @@ +// 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 +// 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 new file mode 100644 index 0000000..bc3840f --- /dev/null +++ b/swap/test/specialized_in_boost.cpp @@ -0,0 +1,72 @@ +// 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*[]) +{ + boost::swap_test_class object1; + boost::swap_test_class object2; + boost::swap(object1,object2); + + BOOST_CHECK_EQUAL(boost::swap_test_class::swap_count(),1); + BOOST_CHECK_EQUAL(boost::swap_test_class::copy_count(),0); + + return 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*[]) +{ + boost::swap_test_class object1; + boost::swap_test_class object2; + boost::swap(object1,object2); + + 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_global.cpp b/swap/test/specialized_in_global.cpp new file mode 100644 index 0000000..7f46187 --- /dev/null +++ b/swap/test/specialized_in_global.cpp @@ -0,0 +1,60 @@ +// 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*[]) +{ + swap_test_class object1; + swap_test_class object2; + boost::swap(object1,object2); + + BOOST_CHECK_EQUAL(swap_test_class::swap_count(),1); + BOOST_CHECK_EQUAL(swap_test_class::copy_count(),0); + + return 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*[]) +{ + swap_test_class object1; + swap_test_class object2; + boost::swap(object1,object2); + + 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 new file mode 100644 index 0000000..7dccab4 --- /dev/null +++ b/swap/test/specialized_in_other.cpp @@ -0,0 +1,72 @@ +// 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*[]) +{ + other::swap_test_class object1; + other::swap_test_class object2; + boost::swap(object1,object2); + + BOOST_CHECK_EQUAL(other::swap_test_class::swap_count(),1); + BOOST_CHECK_EQUAL(other::swap_test_class::copy_count(),0); + + return 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*[]) +{ + other::swap_test_class object1; + other::swap_test_class object2; + boost::swap(object1,object2); + + 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 new file mode 100644 index 0000000..c6effb0 --- /dev/null +++ b/swap/test/specialized_in_std.cpp @@ -0,0 +1,70 @@ +// 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*[]) +{ + swap_test_class object1; + swap_test_class object2; + boost::swap(object1,object2); + + BOOST_CHECK_EQUAL(swap_test_class::swap_count(),1); + BOOST_CHECK_EQUAL(swap_test_class::copy_count(),0); + + return 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*[]) +{ + swap_test_class object1; + swap_test_class object2; + boost::swap(object1,object2); + + 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/swap_arrays.cpp b/swap/test/swap_arrays.cpp new file mode 100644 index 0000000..f032f5b --- /dev/null +++ b/swap/test/swap_arrays.cpp @@ -0,0 +1,78 @@ +// 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) + +#include +#define BOOST_INCLUDE_MAIN +#include + +//Put test class in the global namespace +#include "./swap_test_class.hpp" + + +int test_main(int, char*[]) +{ + const std::size_t dimension = 7; + + swap_test_class array1[dimension]; + swap_test_class array2[dimension]; + boost::swap(array1, array2); + + BOOST_CHECK_EQUAL(swap_test_class::swap_count(), dimension); + BOOST_CHECK_EQUAL(swap_test_class::copy_count(), 0); + + swap_test_class::reset(); + + const std::size_t firstDimension = 3; + const std::size_t secondDimension = 4; + + swap_test_class two_d_array1[firstDimension][secondDimension]; + swap_test_class two_d_array2[firstDimension][secondDimension]; + boost::swap(two_d_array1, two_d_array1); + + BOOST_CHECK_EQUAL(swap_test_class::swap_count(), firstDimension*secondDimension); + BOOST_CHECK_EQUAL(swap_test_class::copy_count(), 0); + + return 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) + +#include +#define BOOST_INCLUDE_MAIN +#include + +//Put test class in the global namespace +#include "./swap_test_class.hpp" + + +int test_main(int, char*[]) +{ + const std::size_t dimension = 7; + + swap_test_class array1[dimension]; + swap_test_class array2[dimension]; + boost::swap(array1, array2); + + BOOST_CHECK_EQUAL(swap_test_class::swap_count(), dimension); + BOOST_CHECK_EQUAL(swap_test_class::copy_count(), 0); + + swap_test_class::reset(); + + const std::size_t firstDimension = 3; + const std::size_t secondDimension = 4; + + swap_test_class two_d_array1[firstDimension][secondDimension]; + swap_test_class two_d_array2[firstDimension][secondDimension]; + boost::swap(two_d_array1, two_d_array1); + + BOOST_CHECK_EQUAL(swap_test_class::swap_count(), firstDimension*secondDimension); + BOOST_CHECK_EQUAL(swap_test_class::copy_count(), 0); + + return 0; +} diff --git a/swap/test/swap_test_class.hpp b/swap/test/swap_test_class.hpp new file mode 100644 index 0000000..2b23f20 --- /dev/null +++ b/swap/test/swap_test_class.hpp @@ -0,0 +1,171 @@ +// 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 + +#ifndef BOOST_UTILITY_SWAP_TEST_CLASS_HPP +#define BOOST_UTILITY_SWAP_TEST_CLASS_HPP + + +class swap_test_class +{ +public: + swap_test_class() + { + ++constructCount(); + } + + ~swap_test_class() + { + ++destructCount(); + } + + swap_test_class(const swap_test_class&) + { + ++copyCount(); + ++destructCount(); + } + + swap_test_class& operator=(const swap_test_class&) + { + ++copyCount(); + return *this; + } + + void swap(swap_test_class& other) + { + ++swapCount(); + } + + + 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; + } + +}; + +#endif + +// 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 + +#ifndef BOOST_UTILITY_SWAP_TEST_CLASS_HPP +#define BOOST_UTILITY_SWAP_TEST_CLASS_HPP + + +class swap_test_class +{ +public: + swap_test_class() + { + ++constructCount(); + } + + ~swap_test_class() + { + ++destructCount(); + } + + swap_test_class(const swap_test_class&) + { + ++copyCount(); + ++destructCount(); + } + + swap_test_class& operator=(const swap_test_class&) + { + ++copyCount(); + return *this; + } + + void swap(swap_test_class& other) + { + ++swapCount(); + } + + + 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; + } + +}; + +#endif + + From 82cca4ccec6668f241ba82f7511f3a0b3a850392 Mon Sep 17 00:00:00 2001 From: Vladimir Prus Date: Sat, 12 Jul 2008 17:56:01 +0000 Subject: [PATCH 112/144] Remove duplicate content. [SVN r47360] --- swap/test/Jamfile.v2 | 27 --------------------------- 1 file changed, 27 deletions(-) diff --git a/swap/test/Jamfile.v2 b/swap/test/Jamfile.v2 index 758bdaa..a13cbd0 100644 --- a/swap/test/Jamfile.v2 +++ b/swap/test/Jamfile.v2 @@ -22,32 +22,5 @@ test-suite utility/swap [ run specialized_in_std.cpp ../../../test/build//boost_test_exec_monitor/static ] [ run swap_arrays.cpp ../../../test/build//boost_test_exec_monitor/static ] ; - - -# 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 swap_arrays.cpp ../../../test/build//boost_test_exec_monitor/static ] - ; - From 0f249e530ac510eee5125317bb4a69e2b4423746 Mon Sep 17 00:00:00 2001 From: Joseph Gauterin Date: Sat, 19 Jul 2008 19:40:12 +0000 Subject: [PATCH 113/144] Corrected duplicated file contents [SVN r47607] --- swap/test/lib_header_1.cpp | 11 +--- swap/test/lib_header_2.cpp | 9 --- swap/test/mixed_headers_1.cpp | 9 --- swap/test/mixed_headers_2.cpp | 8 --- swap/test/primitive.cpp | 21 ------- swap/test/root_header_1.cpp | 8 --- swap/test/root_header_2.cpp | 9 --- swap/test/specialized_in_boost.cpp | 35 ----------- swap/test/specialized_in_global.cpp | 29 --------- swap/test/specialized_in_other.cpp | 35 ----------- swap/test/specialized_in_std.cpp | 34 ----------- swap/test/swap_arrays.cpp | 38 ------------ swap/test/swap_test_class.hpp | 91 +---------------------------- 13 files changed, 3 insertions(+), 334 deletions(-) diff --git a/swap/test/lib_header_1.cpp b/swap/test/lib_header_1.cpp index ea7c99a..d3efc63 100644 --- a/swap/test/lib_header_1.cpp +++ b/swap/test/lib_header_1.cpp @@ -6,13 +6,4 @@ // Tests that the swap header compiles as a standalone translation unit -#include -// 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 +#include \ No newline at end of file diff --git a/swap/test/lib_header_2.cpp b/swap/test/lib_header_2.cpp index 0c9e409..e88909d 100644 --- a/swap/test/lib_header_2.cpp +++ b/swap/test/lib_header_2.cpp @@ -8,13 +8,4 @@ #include #include -// 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 index 0c7571e..cdb9fe5 100644 --- a/swap/test/mixed_headers_1.cpp +++ b/swap/test/mixed_headers_1.cpp @@ -8,13 +8,4 @@ #include #include -// 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 index 217873a..94e9d87 100644 --- a/swap/test/mixed_headers_2.cpp +++ b/swap/test/mixed_headers_2.cpp @@ -8,13 +8,5 @@ #include #include -// 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/primitive.cpp b/swap/test/primitive.cpp index 76cd7b0..380edb3 100644 --- a/swap/test/primitive.cpp +++ b/swap/test/primitive.cpp @@ -20,25 +20,4 @@ int test_main(int, char*[]) return 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 index efa0028..575d2cb 100644 --- a/swap/test/root_header_1.cpp +++ b/swap/test/root_header_1.cpp @@ -7,12 +7,4 @@ // Tests that the swap header compiles as a standalone translation unit #include -// 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 index d7e00f3..d26b3a6 100644 --- a/swap/test/root_header_2.cpp +++ b/swap/test/root_header_2.cpp @@ -8,13 +8,4 @@ #include #include -// 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 index bc3840f..55ac390 100644 --- a/swap/test/specialized_in_boost.cpp +++ b/swap/test/specialized_in_boost.cpp @@ -34,39 +34,4 @@ int test_main(int, char*[]) return 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*[]) -{ - boost::swap_test_class object1; - boost::swap_test_class object2; - boost::swap(object1,object2); - - 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_global.cpp b/swap/test/specialized_in_global.cpp index 7f46187..f76754f 100644 --- a/swap/test/specialized_in_global.cpp +++ b/swap/test/specialized_in_global.cpp @@ -28,33 +28,4 @@ int test_main(int, char*[]) return 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*[]) -{ - swap_test_class object1; - swap_test_class object2; - boost::swap(object1,object2); - - 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 index 7dccab4..c3071f5 100644 --- a/swap/test/specialized_in_other.cpp +++ b/swap/test/specialized_in_other.cpp @@ -34,39 +34,4 @@ int test_main(int, char*[]) return 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*[]) -{ - other::swap_test_class object1; - other::swap_test_class object2; - boost::swap(object1,object2); - - 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 index c6effb0..641aa82 100644 --- a/swap/test/specialized_in_std.cpp +++ b/swap/test/specialized_in_std.cpp @@ -33,38 +33,4 @@ int test_main(int, char*[]) return 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*[]) -{ - swap_test_class object1; - swap_test_class object2; - boost::swap(object1,object2); - - 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/swap_arrays.cpp b/swap/test/swap_arrays.cpp index f032f5b..96b7939 100644 --- a/swap/test/swap_arrays.cpp +++ b/swap/test/swap_arrays.cpp @@ -37,42 +37,4 @@ int test_main(int, char*[]) return 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) -#include -#define BOOST_INCLUDE_MAIN -#include - -//Put test class in the global namespace -#include "./swap_test_class.hpp" - - -int test_main(int, char*[]) -{ - const std::size_t dimension = 7; - - swap_test_class array1[dimension]; - swap_test_class array2[dimension]; - boost::swap(array1, array2); - - BOOST_CHECK_EQUAL(swap_test_class::swap_count(), dimension); - BOOST_CHECK_EQUAL(swap_test_class::copy_count(), 0); - - swap_test_class::reset(); - - const std::size_t firstDimension = 3; - const std::size_t secondDimension = 4; - - swap_test_class two_d_array1[firstDimension][secondDimension]; - swap_test_class two_d_array2[firstDimension][secondDimension]; - boost::swap(two_d_array1, two_d_array1); - - BOOST_CHECK_EQUAL(swap_test_class::swap_count(), firstDimension*secondDimension); - BOOST_CHECK_EQUAL(swap_test_class::copy_count(), 0); - - return 0; -} diff --git a/swap/test/swap_test_class.hpp b/swap/test/swap_test_class.hpp index 2b23f20..aa68444 100644 --- a/swap/test/swap_test_class.hpp +++ b/swap/test/swap_test_class.hpp @@ -1,10 +1,10 @@ -// Copyright (c) 2007 Joseph Gauterin +// 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 that the swap header compiles as a standalone translation unit +// Tests class used by the Boost.Swap tests #ifndef BOOST_UTILITY_SWAP_TEST_CLASS_HPP #define BOOST_UTILITY_SWAP_TEST_CLASS_HPP @@ -82,90 +82,3 @@ private: }; #endif - -// 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 - -#ifndef BOOST_UTILITY_SWAP_TEST_CLASS_HPP -#define BOOST_UTILITY_SWAP_TEST_CLASS_HPP - - -class swap_test_class -{ -public: - swap_test_class() - { - ++constructCount(); - } - - ~swap_test_class() - { - ++destructCount(); - } - - swap_test_class(const swap_test_class&) - { - ++copyCount(); - ++destructCount(); - } - - swap_test_class& operator=(const swap_test_class&) - { - ++copyCount(); - return *this; - } - - void swap(swap_test_class& other) - { - ++swapCount(); - } - - - 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; - } - -}; - -#endif - - From 2157555d888abb9e2e9cac2a25209ca3861bbfd7 Mon Sep 17 00:00:00 2001 From: Niels Dekker Date: Sun, 20 Jul 2008 11:05:49 +0000 Subject: [PATCH 114/144] Fixed silly little bug of mine in swap/test/swap_arrays.cpp [SVN r47626] --- swap/test/swap_arrays.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/swap/test/swap_arrays.cpp b/swap/test/swap_arrays.cpp index 96b7939..6689db7 100644 --- a/swap/test/swap_arrays.cpp +++ b/swap/test/swap_arrays.cpp @@ -30,7 +30,7 @@ int test_main(int, char*[]) swap_test_class two_d_array1[firstDimension][secondDimension]; swap_test_class two_d_array2[firstDimension][secondDimension]; - boost::swap(two_d_array1, two_d_array1); + boost::swap(two_d_array1, two_d_array2); BOOST_CHECK_EQUAL(swap_test_class::swap_count(), firstDimension*secondDimension); BOOST_CHECK_EQUAL(swap_test_class::copy_count(), 0); From f1947e8d0efa72a13cab9c55761c4d3ea92efe43 Mon Sep 17 00:00:00 2001 From: Niels Dekker Date: Sun, 20 Jul 2008 12:13:33 +0000 Subject: [PATCH 115/144] Added swap_test_class swap functions to test/swap_arrays.cpp. My fault, they should have been there already! [SVN r47628] --- swap/test/swap_arrays.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/swap/test/swap_arrays.cpp b/swap/test/swap_arrays.cpp index 6689db7..154ae30 100644 --- a/swap/test/swap_arrays.cpp +++ b/swap/test/swap_arrays.cpp @@ -11,6 +11,25 @@ //Put test class in the global namespace #include "./swap_test_class.hpp" +//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: Effectice 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*[]) { From c300d2627c0eaf7556907d536e92f51dce8499e5 Mon Sep 17 00:00:00 2001 From: Niels Dekker Date: Sun, 20 Jul 2008 12:18:25 +0000 Subject: [PATCH 116/144] Fixed silly little typo of mine, in test/swap_arrays.cpp [SVN r47629] --- swap/test/swap_arrays.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/swap/test/swap_arrays.cpp b/swap/test/swap_arrays.cpp index 154ae30..79c6d68 100644 --- a/swap/test/swap_arrays.cpp +++ b/swap/test/swap_arrays.cpp @@ -14,7 +14,7 @@ //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: Effectice C++, +//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) { From 911e2525d3fe6cc4372bc2f8595f6b75d9b0853c Mon Sep 17 00:00:00 2001 From: Niels Dekker Date: Fri, 25 Jul 2008 18:48:09 +0000 Subject: [PATCH 117/144] Added test_adl_barrier to swap/test, as discussed with Joseph Gauterin. [SVN r47808] --- swap/test/Jamfile.v2 | 5 ++--- swap/test/test_adl_barrier.cpp | 36 ++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 3 deletions(-) create mode 100644 swap/test/test_adl_barrier.cpp diff --git a/swap/test/Jamfile.v2 b/swap/test/Jamfile.v2 index a13cbd0..d648de2 100644 --- a/swap/test/Jamfile.v2 +++ b/swap/test/Jamfile.v2 @@ -20,7 +20,6 @@ test-suite utility/swap [ 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 swap_arrays.cpp ../../../test/build//boost_test_exec_monitor/static ] + [ run test_adl_barrier.cpp ../../../test/build//boost_test_exec_monitor/static ] + [ run swap_arrays.cpp ../../../test/build//boost_test_exec_monitor/static ] ; - - diff --git a/swap/test/test_adl_barrier.cpp b/swap/test/test_adl_barrier.cpp new file mode 100644 index 0000000..e30a1b6 --- /dev/null +++ b/swap/test/test_adl_barrier.cpp @@ -0,0 +1,36 @@ +// 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 +// (ADL). The implementation of boost::swap resolves this issue by +// using a barrier namespace. The following test checks this "ADL barrier". + +#include +#define BOOST_INCLUDE_MAIN +#include + +//Put test class in namespace boost +namespace boost +{ + #include "./swap_test_class.hpp" +} + + +int test_main(int, char*[]) +{ + boost::swap_test_class object1; + boost::swap_test_class object2; + boost::swap(object1,object2); + + BOOST_CHECK_EQUAL(boost::swap_test_class::swap_count(),0); + BOOST_CHECK_EQUAL(boost::swap_test_class::copy_count(),3); + + return 0; +} + From 568e680e9e156ed666a834894f9d8bdb53e311dd Mon Sep 17 00:00:00 2001 From: Niels Dekker Date: Sat, 26 Jul 2008 17:47:59 +0000 Subject: [PATCH 118/144] Added a newline to swap/test/lib_header_1.cpp, hoping to fix Sun 5.x compile issue, "Error: There is extra text on this line" [SVN r47829] --- swap/test/lib_header_1.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/swap/test/lib_header_1.cpp b/swap/test/lib_header_1.cpp index d3efc63..923dea6 100644 --- a/swap/test/lib_header_1.cpp +++ b/swap/test/lib_header_1.cpp @@ -6,4 +6,5 @@ // Tests that the swap header compiles as a standalone translation unit -#include \ No newline at end of file +#include + From ac010b6e3c82371bab823d2fdc77498e3f45d719 Mon Sep 17 00:00:00 2001 From: Niels Dekker Date: Sun, 27 Jul 2008 11:35:33 +0000 Subject: [PATCH 119/144] Added specialized_in_boost_and_other to swap/test, as discussed at "[boost] [swap] End-user allowed to add overloads to boost namespace?", http://lists.boost.org/Archives/boost/2008/07/140327.php [SVN r47839] --- swap/test/Jamfile.v2 | 15 +++--- swap/test/specialized_in_boost_and_other.cpp | 56 ++++++++++++++++++++ 2 files changed, 64 insertions(+), 7 deletions(-) create mode 100644 swap/test/specialized_in_boost_and_other.cpp diff --git a/swap/test/Jamfile.v2 b/swap/test/Jamfile.v2 index d648de2..abce519 100644 --- a/swap/test/Jamfile.v2 +++ b/swap/test/Jamfile.v2 @@ -15,11 +15,12 @@ test-suite utility/swap [ 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 test_adl_barrier.cpp ../../../test/build//boost_test_exec_monitor/static ] - [ run swap_arrays.cpp ../../../test/build//boost_test_exec_monitor/static ] + [ 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 test_adl_barrier.cpp ../../../test/build//boost_test_exec_monitor/static ] + [ run swap_arrays.cpp ../../../test/build//boost_test_exec_monitor/static ] ; diff --git a/swap/test/specialized_in_boost_and_other.cpp b/swap/test/specialized_in_boost_and_other.cpp new file mode 100644 index 0000000..fc76251 --- /dev/null +++ b/swap/test/specialized_in_boost_and_other.cpp @@ -0,0 +1,56 @@ +// 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 two object in a namespace other than boost are properly +// swapped, when both boost and the other namespace have a custom swap function +// for their 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 compilers, 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*[]) +{ + other::swap_test_class object1; + other::swap_test_class object2; + boost::swap(object1,object2); + + BOOST_CHECK_EQUAL(other::swap_test_class::swap_count(),1); + BOOST_CHECK_EQUAL(other::swap_test_class::copy_count(),0); + + return 0; +} + From d87b285fe93e1ed10c3c5c622a23ff507c556285 Mon Sep 17 00:00:00 2001 From: Niels Dekker Date: Sun, 27 Jul 2008 12:46:45 +0000 Subject: [PATCH 120/144] Fixed comment in swap/test/specialized_in_boost_and_other.cpp [SVN r47840] --- swap/test/specialized_in_boost_and_other.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/swap/test/specialized_in_boost_and_other.cpp b/swap/test/specialized_in_boost_and_other.cpp index fc76251..9adc5c0 100644 --- a/swap/test/specialized_in_boost_and_other.cpp +++ b/swap/test/specialized_in_boost_and_other.cpp @@ -4,15 +4,15 @@ // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) -// Tests whether two object in a namespace other than boost are properly -// swapped, when both boost and the other namespace have a custom swap function -// for their 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 compilers, 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. +// 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 From 5dfbe2185c1fb34d32c12083cb6084420983ab73 Mon Sep 17 00:00:00 2001 From: Niels Dekker Date: Wed, 30 Jul 2008 08:04:34 +0000 Subject: [PATCH 121/144] Applied "swap.hpp.patch" by Steven Watanabe, "Re: [boost] [swap] How to fix ADL barrier for XL, Intel, GCC, Sun and Como?", http://lists.boost.org/Archives/boost/2008/07/140482.php [SVN r47877] --- include/boost/utility/swap.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/boost/utility/swap.hpp b/include/boost/utility/swap.hpp index 952adf5..16750c8 100644 --- a/include/boost/utility/swap.hpp +++ b/include/boost/utility/swap.hpp @@ -38,8 +38,8 @@ namespace boost { namespace swap_adl_barrier { - template - void swap(T& left, T& right) + template + void swap(T1& left, T2& right) { ::boost_swap_impl::swap_impl(left, right); } From 6e45e6a4c16f9276049aa04b9486c0bf1e71845e Mon Sep 17 00:00:00 2001 From: Niels Dekker Date: Thu, 31 Jul 2008 20:18:04 +0000 Subject: [PATCH 122/144] Removed swap_adl_barrier namespace, as discussed at "Re: [boost] [swap] How to fix ADL barrier for XL, Intel, GCC, Sun and Como?", http://lists.boost.org/Archives/boost/2008/07/140511.php [SVN r47920] --- include/boost/utility/swap.hpp | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/include/boost/utility/swap.hpp b/include/boost/utility/swap.hpp index 16750c8..da293ee 100644 --- a/include/boost/utility/swap.hpp +++ b/include/boost/utility/swap.hpp @@ -36,16 +36,11 @@ namespace boost_swap_impl namespace boost { - namespace swap_adl_barrier + template + void swap(T1& left, T2& right) { - template - void swap(T1& left, T2& right) - { - ::boost_swap_impl::swap_impl(left, right); - } + ::boost_swap_impl::swap_impl(left, right); } - - using swap_adl_barrier::swap; } #endif From fbbcc966f670ae96b8121950618a136dcbd44a4a Mon Sep 17 00:00:00 2001 From: Niels Dekker Date: Sat, 2 Aug 2008 11:41:47 +0000 Subject: [PATCH 123/144] Added swap tests for std types, as discussed at "Re: [boost] [swap] Workaround for ADL failures of MSVC 7.1 and Borland okay?", http://lists.boost.org/Archives/boost/2008/08/140589.php [SVN r47943] --- swap/test/Jamfile.v2 | 7 ++++ 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 | 54 ++++++++++++++++++++++++++++++ swap/test/std_vector_of_global.cpp | 47 ++++++++++++++++++++++++++ swap/test/std_vector_of_other.cpp | 54 ++++++++++++++++++++++++++++++ 8 files changed, 290 insertions(+) create mode 100644 swap/test/std_bitset.cpp create mode 100644 swap/test/std_dateorder.cpp create mode 100644 swap/test/std_string.cpp create mode 100644 swap/test/std_typeinfo_ptr.cpp create mode 100644 swap/test/std_vector_of_boost.cpp create mode 100644 swap/test/std_vector_of_global.cpp create mode 100644 swap/test/std_vector_of_other.cpp diff --git a/swap/test/Jamfile.v2 b/swap/test/Jamfile.v2 index abce519..d08a47a 100644 --- a/swap/test/Jamfile.v2 +++ b/swap/test/Jamfile.v2 @@ -21,6 +21,13 @@ test-suite utility/swap [ 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 test_adl_barrier.cpp ../../../test/build//boost_test_exec_monitor/static ] [ run swap_arrays.cpp ../../../test/build//boost_test_exec_monitor/static ] ; diff --git a/swap/test/std_bitset.cpp b/swap/test/std_bitset.cpp new file mode 100644 index 0000000..4b9fbae --- /dev/null +++ b/swap/test/std_bitset.cpp @@ -0,0 +1,33 @@ +// 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::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 = 1ul; + const bitset_type initial_value2 = 2ul; + + 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 new file mode 100644 index 0000000..b593f6f --- /dev/null +++ b/swap/test/std_dateorder.cpp @@ -0,0 +1,32 @@ +// 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 new file mode 100644 index 0000000..b7d3d4d --- /dev/null +++ b/swap/test/std_string.cpp @@ -0,0 +1,31 @@ +// 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 new file mode 100644 index 0000000..38e293a --- /dev/null +++ b/swap/test/std_typeinfo_ptr.cpp @@ -0,0 +1,32 @@ +// 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 new file mode 100644 index 0000000..f9c3888 --- /dev/null +++ b/swap/test/std_vector_of_boost.cpp @@ -0,0 +1,54 @@ +// 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; + + vector_type object1(initial_size1); + vector_type object2(initial_size2); + + 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_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 new file mode 100644 index 0000000..ef6b52b --- /dev/null +++ b/swap/test/std_vector_of_global.cpp @@ -0,0 +1,47 @@ +// 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; + + vector_type object1(initial_size1); + vector_type object2(initial_size2); + + swap_test_class::reset(); + + boost::swap(object1,object2); + + BOOST_CHECK_EQUAL(object1.size(),initial_size2); + BOOST_CHECK_EQUAL(object2.size(),initial_size1); + + 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 new file mode 100644 index 0000000..3834269 --- /dev/null +++ b/swap/test/std_vector_of_other.cpp @@ -0,0 +1,54 @@ +// 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; + + vector_type object1(initial_size1); + vector_type object2(initial_size2); + + 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_EQUAL(swap_test_class_type::swap_count(),0); + BOOST_CHECK_EQUAL(swap_test_class_type::copy_count(),0); + + return 0; +} + From 594890dd999b25585b14c40970ee012091acf4f6 Mon Sep 17 00:00:00 2001 From: Joseph Gauterin Date: Mon, 4 Aug 2008 11:21:02 +0000 Subject: [PATCH 124/144] Changed 'using std::swap;' to 'using namesapce std;' in swap_impl function to work around ADL bugs in some compilers. [SVN r47967] --- include/boost/utility/swap.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/boost/utility/swap.hpp b/include/boost/utility/swap.hpp index da293ee..71cc454 100644 --- a/include/boost/utility/swap.hpp +++ b/include/boost/utility/swap.hpp @@ -20,7 +20,7 @@ namespace boost_swap_impl template void swap_impl(T& left, T& right) { - using std::swap;//use std::swap if argument dependent lookup fails + using namespace std;//use std::swap if argument dependent lookup fails swap(left,right); } From 21936ba16c0b65536eb2436f6afa69799d5a7f85 Mon Sep 17 00:00:00 2001 From: Joseph Gauterin Date: Mon, 4 Aug 2008 18:16:16 +0000 Subject: [PATCH 125/144] Updated copyright info. [SVN r47971] --- include/boost/utility/swap.hpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/include/boost/utility/swap.hpp b/include/boost/utility/swap.hpp index 71cc454..f42264c 100644 --- a/include/boost/utility/swap.hpp +++ b/include/boost/utility/swap.hpp @@ -1,12 +1,9 @@ -// Copyright (C) 2007, 2008 Steven Watanabe, Joseph Gauterin +// 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 -// -// Update: -// 29 June 2008 (Added support for built-in arrays.) Niels Dekker #ifndef BOOST_UTILITY_SWAP_HPP From 8471db6a2199f011b27e03864c96f5840bc141d4 Mon Sep 17 00:00:00 2001 From: Joseph Gauterin Date: Mon, 4 Aug 2008 18:22:10 +0000 Subject: [PATCH 126/144] Renamed 'test_adl_barrier.cpp' to 'no_ambiguity_in_boost.cpp' and altered comments to reflect new disambiguation technique. [SVN r47972] --- swap/test/Jamfile.v2 | 2 +- .../{test_adl_barrier.cpp => no_ambiguity_in_boost.cpp} | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) rename swap/test/{test_adl_barrier.cpp => no_ambiguity_in_boost.cpp} (84%) diff --git a/swap/test/Jamfile.v2 b/swap/test/Jamfile.v2 index d08a47a..7071837 100644 --- a/swap/test/Jamfile.v2 +++ b/swap/test/Jamfile.v2 @@ -28,6 +28,6 @@ test-suite utility/swap [ 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 test_adl_barrier.cpp ../../../test/build//boost_test_exec_monitor/static ] + [ run no_ambiguity_in_boost.cpp ../../../test/build//boost_test_exec_monitor/static ] [ run swap_arrays.cpp ../../../test/build//boost_test_exec_monitor/static ] ; diff --git a/swap/test/test_adl_barrier.cpp b/swap/test/no_ambiguity_in_boost.cpp similarity index 84% rename from swap/test/test_adl_barrier.cpp rename to swap/test/no_ambiguity_in_boost.cpp index e30a1b6..17fe9d6 100644 --- a/swap/test/test_adl_barrier.cpp +++ b/swap/test/no_ambiguity_in_boost.cpp @@ -7,9 +7,10 @@ // 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 -// (ADL). The implementation of boost::swap resolves this issue by -// using a barrier namespace. The following test checks this "ADL barrier". +// 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 From 534d6f07729c1650abc2cf7e59aa0deee5ffe31c Mon Sep 17 00:00:00 2001 From: Joseph Gauterin Date: Mon, 4 Aug 2008 18:25:45 +0000 Subject: [PATCH 127/144] Updated documentation to remove references to the 'ADL barrier' [SVN r47973] --- swap.html | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/swap.html b/swap.html index e317b11..dfe9b84 100644 --- a/swap.html +++ b/swap.html @@ -1,4 +1,4 @@ -? + @@ -73,7 +73,7 @@ Joseph Gauterin - for the initial idea, implementation, tests, and documentation
  • - Steven Wanatabe - for the idea to use a barrier namespace, enabling the function to have the name 'swap' without introducing ambiguity or infinite recursion + Steven Wanatabe - for the idea to make boost::swap less specialized than std::swap, thereby allowing the function to have the name 'swap' without introducing ambiguity
  • @@ -84,7 +84,7 @@
    -

    Revised: 3 July 2008

    +

    Revised: 4 August 2008

    Copyright 2007, 2008 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>.) From 4d5ff5d8e0af72544327fc21b18706b00cfdfc2f Mon Sep 17 00:00:00 2001 From: Daniel James Date: Wed, 13 Aug 2008 22:00:35 +0000 Subject: [PATCH 128/144] Fix Windows-1252 dash in UTF-8 document. [SVN r48133] --- swap.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/swap.html b/swap.html index dfe9b84..2af5a88 100644 --- a/swap.html +++ b/swap.html @@ -60,7 +60,7 @@

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

    From 055afeaf4666fd7929d124d72fe9ae8e66b76507 Mon Sep 17 00:00:00 2001 From: Niels Dekker Date: Sat, 16 Aug 2008 08:56:19 +0000 Subject: [PATCH 129/144] Added explanatory comments, requested by Isaac Dupree, "Re: [boost] [swap] Renaming boost_swap_impl::swap_impl and/or its namespace?", http://lists.boost.org/Archives/boost/2008/08/141007.php [SVN r48171] --- include/boost/utility/swap.hpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/include/boost/utility/swap.hpp b/include/boost/utility/swap.hpp index f42264c..6845e79 100644 --- a/include/boost/utility/swap.hpp +++ b/include/boost/utility/swap.hpp @@ -9,6 +9,18 @@ #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 #include //for std::size_t From 3179176c5941c381b5a40541667820a37ab0bde9 Mon Sep 17 00:00:00 2001 From: Niels Dekker Date: Wed, 20 Aug 2008 08:25:23 +0000 Subject: [PATCH 130/144] Added a data member to swap_test_class and made it EqualityComparable, as I mentioned at "Re: [boost] [swap] Renaming boost_swap_impl::swap_impl and/or its namespace?", http://lists.boost.org/Archives/boost/2008/08/141027.php [SVN r48245] --- swap/test/swap_test_class.hpp | 36 ++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/swap/test/swap_test_class.hpp b/swap/test/swap_test_class.hpp index aa68444..8cf1fe9 100644 --- a/swap/test/swap_test_class.hpp +++ b/swap/test/swap_test_class.hpp @@ -12,8 +12,11 @@ class swap_test_class { + int m_data; public: - swap_test_class() + explicit swap_test_class(int arg = 0) + : + m_data(arg) { ++constructCount(); } @@ -23,24 +26,40 @@ public: ++destructCount(); } - swap_test_class(const swap_test_class&) + swap_test_class(const swap_test_class& arg) + : + m_data(arg.m_data) { ++copyCount(); ++destructCount(); } - swap_test_class& operator=(const swap_test_class&) + 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(); } @@ -81,4 +100,15 @@ private: }; + +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 From e3b6996fb24b651d38523c5a3c009d9ef9383bdc Mon Sep 17 00:00:00 2001 From: Niels Dekker Date: Wed, 20 Aug 2008 08:28:35 +0000 Subject: [PATCH 131/144] Added extra checks, checking that boost::swap does correctly exchange the values of its arguments, as I mentioned at "Re: [boost] [swap] Renaming boost_swap_impl::swap_impl and/or its namespace?", http://lists.boost.org/Archives/boost/2008/08/141027.php [SVN r48246] --- swap/test/no_ambiguity_in_boost.cpp | 11 +++++++++-- swap/test/specialized_in_boost.cpp | 12 ++++++++++-- swap/test/specialized_in_boost_and_other.cpp | 12 ++++++++++-- swap/test/specialized_in_global.cpp | 12 ++++++++++-- swap/test/specialized_in_other.cpp | 12 ++++++++++-- swap/test/specialized_in_std.cpp | 12 ++++++++++-- swap/test/std_vector_of_boost.cpp | 10 ++++++++-- swap/test/std_vector_of_global.cpp | 10 ++++++++-- swap/test/std_vector_of_other.cpp | 10 ++++++++-- 9 files changed, 83 insertions(+), 18 deletions(-) diff --git a/swap/test/no_ambiguity_in_boost.cpp b/swap/test/no_ambiguity_in_boost.cpp index 17fe9d6..e269252 100644 --- a/swap/test/no_ambiguity_in_boost.cpp +++ b/swap/test/no_ambiguity_in_boost.cpp @@ -25,10 +25,17 @@ namespace boost int test_main(int, char*[]) { - boost::swap_test_class object1; - boost::swap_test_class object2; + 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); diff --git a/swap/test/specialized_in_boost.cpp b/swap/test/specialized_in_boost.cpp index 55ac390..7b3e12e 100644 --- a/swap/test/specialized_in_boost.cpp +++ b/swap/test/specialized_in_boost.cpp @@ -25,10 +25,18 @@ namespace boost int test_main(int, char*[]) { - boost::swap_test_class object1; - boost::swap_test_class object2; + 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); diff --git a/swap/test/specialized_in_boost_and_other.cpp b/swap/test/specialized_in_boost_and_other.cpp index 9adc5c0..ba6247f 100644 --- a/swap/test/specialized_in_boost_and_other.cpp +++ b/swap/test/specialized_in_boost_and_other.cpp @@ -44,10 +44,18 @@ namespace other int test_main(int, char*[]) { - other::swap_test_class object1; - other::swap_test_class object2; + 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); diff --git a/swap/test/specialized_in_global.cpp b/swap/test/specialized_in_global.cpp index f76754f..0a0a029 100644 --- a/swap/test/specialized_in_global.cpp +++ b/swap/test/specialized_in_global.cpp @@ -19,10 +19,18 @@ void swap(swap_test_class& left, swap_test_class& right) int test_main(int, char*[]) { - swap_test_class object1; - swap_test_class object2; + 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); diff --git a/swap/test/specialized_in_other.cpp b/swap/test/specialized_in_other.cpp index c3071f5..a39896f 100644 --- a/swap/test/specialized_in_other.cpp +++ b/swap/test/specialized_in_other.cpp @@ -25,10 +25,18 @@ namespace other int test_main(int, char*[]) { - other::swap_test_class object1; - other::swap_test_class object2; + 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); diff --git a/swap/test/specialized_in_std.cpp b/swap/test/specialized_in_std.cpp index 641aa82..e31e850 100644 --- a/swap/test/specialized_in_std.cpp +++ b/swap/test/specialized_in_std.cpp @@ -24,10 +24,18 @@ namespace std int test_main(int, char*[]) { - swap_test_class object1; - swap_test_class object2; + 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); diff --git a/swap/test/std_vector_of_boost.cpp b/swap/test/std_vector_of_boost.cpp index f9c3888..b0c6355 100644 --- a/swap/test/std_vector_of_boost.cpp +++ b/swap/test/std_vector_of_boost.cpp @@ -36,8 +36,11 @@ int test_main(int, char*[]) const vector_type::size_type initial_size1 = 1; const vector_type::size_type initial_size2 = 2; - vector_type object1(initial_size1); - vector_type object2(initial_size2); + 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(); @@ -46,6 +49,9 @@ int test_main(int, char*[]) 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); diff --git a/swap/test/std_vector_of_global.cpp b/swap/test/std_vector_of_global.cpp index ef6b52b..96a9b6a 100644 --- a/swap/test/std_vector_of_global.cpp +++ b/swap/test/std_vector_of_global.cpp @@ -29,8 +29,11 @@ int test_main(int, char*[]) const vector_type::size_type initial_size1 = 1; const vector_type::size_type initial_size2 = 2; - vector_type object1(initial_size1); - vector_type object2(initial_size2); + 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(); @@ -39,6 +42,9 @@ int test_main(int, char*[]) 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); diff --git a/swap/test/std_vector_of_other.cpp b/swap/test/std_vector_of_other.cpp index 3834269..2176f6e 100644 --- a/swap/test/std_vector_of_other.cpp +++ b/swap/test/std_vector_of_other.cpp @@ -36,8 +36,11 @@ int test_main(int, char*[]) const vector_type::size_type initial_size1 = 1; const vector_type::size_type initial_size2 = 2; - vector_type object1(initial_size1); - vector_type object2(initial_size2); + 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(); @@ -46,6 +49,9 @@ int test_main(int, char*[]) 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); From 6ed1377d5cc82fb256b7fe3bea88bb5dc83dbf60 Mon Sep 17 00:00:00 2001 From: Niels Dekker Date: Wed, 20 Aug 2008 08:29:54 +0000 Subject: [PATCH 132/144] Extended swap_arrays test, checking that boost::swap does correctly exchange the values of its arguments. [SVN r48247] --- swap/test/swap_arrays.cpp | 63 ++++++++++++++++++++++++++++++++------- 1 file changed, 52 insertions(+), 11 deletions(-) diff --git a/swap/test/swap_arrays.cpp b/swap/test/swap_arrays.cpp index 79c6d68..eeb64bc 100644 --- a/swap/test/swap_arrays.cpp +++ b/swap/test/swap_arrays.cpp @@ -11,6 +11,9 @@ //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 @@ -30,29 +33,67 @@ namespace std } } - -int test_main(int, char*[]) +// Tests swapping 1-dimensional arrays. +void test_swapping_1D_arrays() { - const std::size_t dimension = 7; - + const std::size_t dimension = 2; + const swap_test_class initial_array1[dimension] = { swap_test_class(1), swap_test_class(2) }; + const swap_test_class initial_array2[dimension] = { swap_test_class(3), swap_test_class(4) }; + swap_test_class array1[dimension]; swap_test_class array2[dimension]; + + std::copy(initial_array1, initial_array1 + dimension, array1); + std::copy(initial_array2, initial_array2 + dimension, array2); + + swap_test_class::reset(); boost::swap(array1, array2); + BOOST_CHECK(std::equal(array1, array1 + dimension, initial_array2)); + BOOST_CHECK(std::equal(array2, array2 + dimension, initial_array1)); + BOOST_CHECK_EQUAL(swap_test_class::swap_count(), dimension); BOOST_CHECK_EQUAL(swap_test_class::copy_count(), 0); +} + + +// Tests swapping 2-dimensional arrays. +void test_swapping_2D_arrays() +{ + 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) ); + } swap_test_class::reset(); + boost::swap(array1, array2); - const std::size_t firstDimension = 3; - const std::size_t secondDimension = 4; + 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) ); + } - swap_test_class two_d_array1[firstDimension][secondDimension]; - swap_test_class two_d_array2[firstDimension][secondDimension]; - boost::swap(two_d_array1, two_d_array2); - - BOOST_CHECK_EQUAL(swap_test_class::swap_count(), firstDimension*secondDimension); + BOOST_CHECK_EQUAL(swap_test_class::swap_count(), number_of_elements); BOOST_CHECK_EQUAL(swap_test_class::copy_count(), 0); +} + + +int test_main(int, char*[]) +{ + test_swapping_1D_arrays(); + test_swapping_2D_arrays(); return 0; } From edbdd3f4d2ad8e7904e2f99c63c8b51192eab3d4 Mon Sep 17 00:00:00 2001 From: Niels Dekker Date: Tue, 21 Oct 2008 09:55:54 +0000 Subject: [PATCH 133/144] Swap documentation: fixed a misspelling of the name of Steven Watanabe. [SVN r49416] --- swap.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/swap.html b/swap.html index 2af5a88..01afd7c 100644 --- a/swap.html +++ b/swap.html @@ -73,7 +73,7 @@ Joseph Gauterin - for the initial idea, implementation, tests, and documentation
  • - Steven Wanatabe - for the idea to make boost::swap less specialized than std::swap, thereby allowing the function to have the name 'swap' without introducing ambiguity + 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
  • @@ -84,7 +84,7 @@
    -

    Revised: 4 August 2008

    +

    Revised: 21 October 2008

    Copyright 2007, 2008 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>.) From da33d1b283aa694dbcbf8c7bd2d6312c5fd25d6d Mon Sep 17 00:00:00 2001 From: Niels Dekker Date: Sat, 15 Nov 2008 15:07:42 +0000 Subject: [PATCH 134/144] Updated swap.html because LWG issue 809 is now accepted as a defect. Fixed some HTML formatting. [SVN r49771] --- swap.html | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/swap.html b/swap.html index 01afd7c..4022e0b 100644 --- a/swap.html +++ b/swap.html @@ -14,7 +14,7 @@ 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.

    @@ -24,10 +24,10 @@

    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. + 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 doesn't yet do so, but a request to add an overload of std::swap for built-in arrays has been well-received by the Library Working Group of the C++ Standards Committee2. + 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.

    @@ -45,11 +45,11 @@

    Or:

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

    Or:

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

    Or:

      @@ -73,18 +73,18 @@ 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 + 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 issue 809 (std::swap should be overloaded for array types)

    +

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


    -

    Revised: 21 October 2008

    +

    Revised: 15 November 2008

    Copyright 2007, 2008 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>.) From 9c0a284f8f67aed1d0bf889b1fe1c66c0e57ccca Mon Sep 17 00:00:00 2001 From: Niels Dekker Date: Fri, 21 Nov 2008 21:28:47 +0000 Subject: [PATCH 135/144] Added array_of_template test, testing the boost::swap utility on an array of objects of a template class. [SVN r49862] --- swap/test/Jamfile.v2 | 1 + swap/test/array_of_template.cpp | 68 +++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 swap/test/array_of_template.cpp diff --git a/swap/test/Jamfile.v2 b/swap/test/Jamfile.v2 index 7071837..617f7e8 100644 --- a/swap/test/Jamfile.v2 +++ b/swap/test/Jamfile.v2 @@ -29,5 +29,6 @@ test-suite utility/swap [ 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_template.cpp ../../../test/build//boost_test_exec_monitor/static ] [ run swap_arrays.cpp ../../../test/build//boost_test_exec_monitor/static ] ; diff --git a/swap/test/array_of_template.cpp b/swap/test/array_of_template.cpp new file mode 100644 index 0000000..e6e465f --- /dev/null +++ b/swap/test/array_of_template.cpp @@ -0,0 +1,68 @@ +// 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) + +#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: + 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 dimension = 2; + const swap_test_template initial_array1[dimension] = { swap_test_class(1), swap_test_class(2) }; + const swap_test_template initial_array2[dimension] = { swap_test_class(3), swap_test_class(4) }; + + swap_test_template array1[dimension]; + swap_test_template array2[dimension]; + + std::copy(initial_array1, initial_array1 + dimension, array1); + std::copy(initial_array2, initial_array2 + dimension, array2); + + swap_test_class::reset(); + boost::swap(array1, array2); + + BOOST_CHECK(std::equal(array1, array1 + dimension, initial_array2)); + BOOST_CHECK(std::equal(array2, array2 + dimension, initial_array1)); + + BOOST_CHECK_EQUAL(swap_test_class::swap_count(), dimension); + BOOST_CHECK_EQUAL(swap_test_class::copy_count(), 0); + + return 0; +} From 58aa6b4ad3c8a1d6a3905c1c6ba484fb75709fb7 Mon Sep 17 00:00:00 2001 From: Niels Dekker Date: Mon, 24 Nov 2008 17:41:15 +0000 Subject: [PATCH 136/144] Replaced swap/test/swap_arrays by more specific tests: array_of_array, array_of_class, and array_of_int. [SVN r49916] --- swap/test/Jamfile.v2 | 6 +- .../{swap_arrays.cpp => array_of_array.cpp} | 35 +---------- swap/test/array_of_class.cpp | 59 +++++++++++++++++++ swap/test/array_of_int.cpp | 33 +++++++++++ 4 files changed, 97 insertions(+), 36 deletions(-) rename swap/test/{swap_arrays.cpp => array_of_array.cpp} (66%) create mode 100644 swap/test/array_of_class.cpp create mode 100644 swap/test/array_of_int.cpp diff --git a/swap/test/Jamfile.v2 b/swap/test/Jamfile.v2 index 617f7e8..de1cd69 100644 --- a/swap/test/Jamfile.v2 +++ b/swap/test/Jamfile.v2 @@ -29,6 +29,8 @@ test-suite utility/swap [ 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_template.cpp ../../../test/build//boost_test_exec_monitor/static ] - [ run swap_arrays.cpp ../../../test/build//boost_test_exec_monitor/static ] + [ run array_of_array.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/swap_arrays.cpp b/swap/test/array_of_array.cpp similarity index 66% rename from swap/test/swap_arrays.cpp rename to swap/test/array_of_array.cpp index eeb64bc..06eee48 100644 --- a/swap/test/swap_arrays.cpp +++ b/swap/test/array_of_array.cpp @@ -33,32 +33,8 @@ namespace std } } -// Tests swapping 1-dimensional arrays. -void test_swapping_1D_arrays() -{ - const std::size_t dimension = 2; - const swap_test_class initial_array1[dimension] = { swap_test_class(1), swap_test_class(2) }; - const swap_test_class initial_array2[dimension] = { swap_test_class(3), swap_test_class(4) }; - - swap_test_class array1[dimension]; - swap_test_class array2[dimension]; - std::copy(initial_array1, initial_array1 + dimension, array1); - std::copy(initial_array2, initial_array2 + dimension, array2); - - swap_test_class::reset(); - boost::swap(array1, array2); - - BOOST_CHECK(std::equal(array1, array1 + dimension, initial_array2)); - BOOST_CHECK(std::equal(array2, array2 + dimension, initial_array1)); - - BOOST_CHECK_EQUAL(swap_test_class::swap_count(), dimension); - BOOST_CHECK_EQUAL(swap_test_class::copy_count(), 0); -} - - -// Tests swapping 2-dimensional arrays. -void test_swapping_2D_arrays() +int test_main(int, char*[]) { const std::size_t first_dimension = 3; const std::size_t second_dimension = 4; @@ -76,7 +52,6 @@ void test_swapping_2D_arrays() ptr2[i].set_data( static_cast(i + number_of_elements) ); } - swap_test_class::reset(); boost::swap(array1, array2); for (std::size_t i = 0; i < number_of_elements; ++i) @@ -87,14 +62,6 @@ void test_swapping_2D_arrays() BOOST_CHECK_EQUAL(swap_test_class::swap_count(), number_of_elements); BOOST_CHECK_EQUAL(swap_test_class::copy_count(), 0); -} - - -int test_main(int, char*[]) -{ - test_swapping_1D_arrays(); - test_swapping_2D_arrays(); return 0; } - diff --git a/swap/test/array_of_class.cpp b/swap/test/array_of_class.cpp new file mode 100644 index 0000000..df79801 --- /dev/null +++ b/swap/test/array_of_class.cpp @@ -0,0 +1,59 @@ +// 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) + +#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 new file mode 100644 index 0000000..f919613 --- /dev/null +++ b/swap/test/array_of_int.cpp @@ -0,0 +1,33 @@ +// 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) + +#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; +} From 9ec5d6d3cdd80b0e5fc5c065a9e4d1e7287607f2 Mon Sep 17 00:00:00 2001 From: Niels Dekker Date: Thu, 27 Nov 2008 11:08:05 +0000 Subject: [PATCH 137/144] Added comment to various array swapping tests, added member typedef to swap_test_template, to make the test more realistic. [SVN r49953] --- swap/test/array_of_class.cpp | 2 ++ swap/test/array_of_int.cpp | 2 ++ swap/test/array_of_template.cpp | 23 +++++++++++++---------- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/swap/test/array_of_class.cpp b/swap/test/array_of_class.cpp index df79801..356762d 100644 --- a/swap/test/array_of_class.cpp +++ b/swap/test/array_of_class.cpp @@ -4,6 +4,8 @@ // (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 diff --git a/swap/test/array_of_int.cpp b/swap/test/array_of_int.cpp index f919613..22a7dde 100644 --- a/swap/test/array_of_int.cpp +++ b/swap/test/array_of_int.cpp @@ -4,6 +4,8 @@ // (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 diff --git a/swap/test/array_of_template.cpp b/swap/test/array_of_template.cpp index e6e465f..8f350ad 100644 --- a/swap/test/array_of_template.cpp +++ b/swap/test/array_of_template.cpp @@ -4,6 +4,8 @@ // (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 @@ -18,6 +20,7 @@ template class swap_test_template { public: + typedef T template_argument; swap_test_class swap_test_object; }; @@ -45,23 +48,23 @@ void swap(swap_test_template& left, swap_test_template& right) int test_main(int, char*[]) { - const std::size_t dimension = 2; - const swap_test_template initial_array1[dimension] = { swap_test_class(1), swap_test_class(2) }; - const swap_test_template initial_array2[dimension] = { swap_test_class(3), swap_test_class(4) }; + 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[dimension]; - swap_test_template array2[dimension]; + swap_test_template array1[array_size]; + swap_test_template array2[array_size]; - std::copy(initial_array1, initial_array1 + dimension, array1); - std::copy(initial_array2, initial_array2 + dimension, array2); + 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 + dimension, initial_array2)); - BOOST_CHECK(std::equal(array2, array2 + dimension, initial_array1)); + 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(), dimension); + BOOST_CHECK_EQUAL(swap_test_class::swap_count(), array_size); BOOST_CHECK_EQUAL(swap_test_class::copy_count(), 0); return 0; From 67f5d2afb08dbf5af4cf60db28739cd19fc10d12 Mon Sep 17 00:00:00 2001 From: Niels Dekker Date: Thu, 27 Nov 2008 11:14:52 +0000 Subject: [PATCH 138/144] Distinguished between testing array-of-array-of-class and array-of-array-of-int, as the latter appears to succeed on CodeGear 6.10 while the former does not. [SVN r49954] --- swap/test/Jamfile.v2 | 3 +- ..._array.cpp => array_of_array_of_class.cpp} | 2 + swap/test/array_of_array_of_int.cpp | 42 +++++++++++++++++++ 3 files changed, 46 insertions(+), 1 deletion(-) rename swap/test/{array_of_array.cpp => array_of_array_of_class.cpp} (95%) create mode 100644 swap/test/array_of_array_of_int.cpp diff --git a/swap/test/Jamfile.v2 b/swap/test/Jamfile.v2 index de1cd69..f5b0d46 100644 --- a/swap/test/Jamfile.v2 +++ b/swap/test/Jamfile.v2 @@ -29,7 +29,8 @@ test-suite utility/swap [ 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.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.cpp b/swap/test/array_of_array_of_class.cpp similarity index 95% rename from swap/test/array_of_array.cpp rename to swap/test/array_of_array_of_class.cpp index 06eee48..4f02578 100644 --- a/swap/test/array_of_array.cpp +++ b/swap/test/array_of_array_of_class.cpp @@ -4,6 +4,8 @@ // (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 diff --git a/swap/test/array_of_array_of_int.cpp b/swap/test/array_of_array_of_int.cpp new file mode 100644 index 0000000..c1778ec --- /dev/null +++ b/swap/test/array_of_array_of_int.cpp @@ -0,0 +1,42 @@ +// 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; +} From 2fcd4580d01e9e6cb93c61534317a98fe856a3bc Mon Sep 17 00:00:00 2001 From: Jeremiah Willcock Date: Wed, 20 May 2009 19:19:00 +0000 Subject: [PATCH 139/144] Fixed most tab and min/max issues from trunk inspection report [SVN r53141] --- swap/test/std_bitset.cpp | 2 +- swap/test/swap_test_class.hpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/swap/test/std_bitset.cpp b/swap/test/std_bitset.cpp index 4b9fbae..d8d69e7 100644 --- a/swap/test/std_bitset.cpp +++ b/swap/test/std_bitset.cpp @@ -19,7 +19,7 @@ int test_main(int, char*[]) typedef std::bitset<8> bitset_type; const bitset_type initial_value1 = 1ul; const bitset_type initial_value2 = 2ul; - + bitset_type object1 = initial_value1; bitset_type object2 = initial_value2; diff --git a/swap/test/swap_test_class.hpp b/swap/test/swap_test_class.hpp index 8cf1fe9..a25dbbd 100644 --- a/swap/test/swap_test_class.hpp +++ b/swap/test/swap_test_class.hpp @@ -12,7 +12,7 @@ class swap_test_class { - int m_data; + int m_data; public: explicit swap_test_class(int arg = 0) : From 2f871d6ff75ba51a664fc271e05fe1682a80ebb1 Mon Sep 17 00:00:00 2001 From: Niels Dekker Date: Tue, 8 Sep 2009 16:54:54 +0000 Subject: [PATCH 140/144] Mentioned swap.hpp header, as requested by Thorsten Ottosen and David Abrahams [SVN r56107] --- swap.html | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/swap.html b/swap.html index 4022e0b..50722b2 100644 --- a/swap.html +++ b/swap.html @@ -7,7 +7,11 @@ +

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

    +

    Swap

    From fb683885c8094ad62054e39231938360d0d6f450 Mon Sep 17 00:00:00 2001 From: Niels Dekker Date: Tue, 8 Sep 2009 17:07:13 +0000 Subject: [PATCH 141/144] Updated revision date of Boost Swap documentation [SVN r56108] --- swap.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/swap.html b/swap.html index 50722b2..36f8425 100644 --- a/swap.html +++ b/swap.html @@ -88,9 +88,9 @@


    -

    Revised: 15 November 2008

    +

    Revised: 08 September 2009

    - Copyright 2007, 2008 Joseph Gauterin. Use, modification, and distribution are subject to the Boost Software License, Version 1.0. + 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>.)

    From a37890985ac2a3501af1efecbf05cde19042d2ae Mon Sep 17 00:00:00 2001 From: Niels Dekker Date: Sun, 7 Mar 2010 21:42:22 +0000 Subject: [PATCH 142/144] Hopefully fixed #3984 (std::bitset constructor issue). Tested by Juergen Hunold on msvc-10.0, msvc-9.0, and gcc-4.4. See thread starting at http://lists.boost.org/Archives/boost/2010/03/162690.php [SVN r60331] --- swap/test/std_bitset.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/swap/test/std_bitset.cpp b/swap/test/std_bitset.cpp index d8d69e7..8c0851a 100644 --- a/swap/test/std_bitset.cpp +++ b/swap/test/std_bitset.cpp @@ -17,8 +17,8 @@ int test_main(int, char*[]) { typedef std::bitset<8> bitset_type; - const bitset_type initial_value1 = 1ul; - const bitset_type initial_value2 = 2ul; + const bitset_type initial_value1 = 1; + const bitset_type initial_value2 = 2; bitset_type object1 = initial_value1; bitset_type object2 = initial_value2; From 134ad9fe5121820c6ffd8ed4dae4b66c6d46b96a Mon Sep 17 00:00:00 2001 From: Niels Dekker Date: Mon, 5 Apr 2010 19:08:01 +0000 Subject: [PATCH 143/144] Updated copyright notice. [SVN r61075] --- swap/test/std_bitset.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/swap/test/std_bitset.cpp b/swap/test/std_bitset.cpp index 8c0851a..c46b686 100644 --- a/swap/test/std_bitset.cpp +++ b/swap/test/std_bitset.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2008 Joseph Gauterin, Niels Dekker +// 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 From e27c7d8e6933a7c8eca34507a22c2a58ceafe3fe Mon Sep 17 00:00:00 2001 From: Eric Niebler Date: Thu, 1 May 2014 15:29:43 -0700 Subject: [PATCH 144/144] value_init and swap work on nvidia gpu's --- include/boost/utility/swap.hpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/include/boost/utility/swap.hpp b/include/boost/utility/swap.hpp index 6845e79..5ee6dc1 100644 --- a/include/boost/utility/swap.hpp +++ b/include/boost/utility/swap.hpp @@ -21,12 +21,15 @@ // avoid ambiguity when swapping objects of a Boost type that does // not have its own boost::swap overload. -#include //for std::swap +#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 @@ -34,6 +37,7 @@ namespace boost_swap_impl } template + BOOST_GPU_ENABLED void swap_impl(T (& left)[N], T (& right)[N]) { for (std::size_t i = 0; i < N; ++i) @@ -46,6 +50,7 @@ namespace boost_swap_impl namespace boost { template + BOOST_GPU_ENABLED void swap(T1& left, T2& right) { ::boost_swap_impl::swap_impl(left, right);
    - boost.png (6897 bytes) + boost.png (6897 bytes) +

    checked_delete.hpp