forked from boostorg/utility
merged from trunk
[SVN r47983]
This commit is contained in:
@ -6,7 +6,7 @@
|
|||||||
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||||
// http://www.boost.org/LICENSE_1_0.txt)
|
// http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
|
||||||
// Authors: Jaakko J<EFBFBD>rvi (jajarvi at osl.iu.edu)
|
// Authors: Jaakko Jarvi (jajarvi at osl.iu.edu)
|
||||||
// Jeremiah Willcock (jewillco at osl.iu.edu)
|
// Jeremiah Willcock (jewillco at osl.iu.edu)
|
||||||
// Andrew Lumsdaine (lums at osl.iu.edu)
|
// Andrew Lumsdaine (lums at osl.iu.edu)
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||||
// http://www.boost.org/LICENSE_1_0.txt)
|
// http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
|
||||||
// Authors: Jaakko J<EFBFBD>rvi (jajarvi at osl.iu.edu)
|
// Authors: Jaakko Jarvi (jajarvi at osl.iu.edu)
|
||||||
// Jeremiah Willcock (jewillco at osl.iu.edu)
|
// Jeremiah Willcock (jewillco at osl.iu.edu)
|
||||||
// Andrew Lumsdaine (lums at osl.iu.edu)
|
// Andrew Lumsdaine (lums at osl.iu.edu)
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||||
// http://www.boost.org/LICENSE_1_0.txt)
|
// http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
|
||||||
// Authors: Jaakko J<EFBFBD>rvi (jajarvi at osl.iu.edu)
|
// Authors: Jaakko Jarvi (jajarvi at osl.iu.edu)
|
||||||
// Jeremiah Willcock (jewillco at osl.iu.edu)
|
// Jeremiah Willcock (jewillco at osl.iu.edu)
|
||||||
// Andrew Lumsdaine (lums at osl.iu.edu)
|
// Andrew Lumsdaine (lums at osl.iu.edu)
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||||
// http://www.boost.org/LICENSE_1_0.txt)
|
// http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
|
||||||
// Authors: Jaakko J<EFBFBD>rvi (jajarvi at osl.iu.edu)
|
// Authors: Jaakko Jarvi (jajarvi at osl.iu.edu)
|
||||||
// Jeremiah Willcock (jewillco at osl.iu.edu)
|
// Jeremiah Willcock (jewillco at osl.iu.edu)
|
||||||
// Andrew Lumsdaine (lums at osl.iu.edu)
|
// Andrew Lumsdaine (lums at osl.iu.edu)
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||||
// http://www.boost.org/LICENSE_1_0.txt)
|
// http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
|
||||||
// Authors: Jaakko J<EFBFBD>rvi (jajarvi at osl.iu.edu)
|
// Authors: Jaakko Jarvi (jajarvi at osl.iu.edu)
|
||||||
// Jeremiah Willcock (jewillco at osl.iu.edu)
|
// Jeremiah Willcock (jewillco at osl.iu.edu)
|
||||||
// Andrew Lumsdaine (lums at osl.iu.edu)
|
// Andrew Lumsdaine (lums at osl.iu.edu)
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||||
// http://www.boost.org/LICENSE_1_0.txt)
|
// http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
|
||||||
// Authors: Jaakko J<EFBFBD>rvi (jajarvi at osl.iu.edu)
|
// Authors: Jaakko Jarvi (jajarvi at osl.iu.edu)
|
||||||
// Jeremiah Willcock (jewillco at osl.iu.edu)
|
// Jeremiah Willcock (jewillco at osl.iu.edu)
|
||||||
// Andrew Lumsdaine (lums at osl.iu.edu)
|
// Andrew Lumsdaine (lums at osl.iu.edu)
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||||
// http://www.boost.org/LICENSE_1_0.txt)
|
// http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
|
||||||
// Authors: Jaakko J<EFBFBD>rvi (jajarvi at osl.iu.edu)
|
// Authors: Jaakko Jarvi (jajarvi at osl.iu.edu)
|
||||||
// Jeremiah Willcock (jewillco at osl.iu.edu)
|
// Jeremiah Willcock (jewillco at osl.iu.edu)
|
||||||
// Andrew Lumsdaine (lums at osl.iu.edu)
|
// Andrew Lumsdaine (lums at osl.iu.edu)
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||||
// http://www.boost.org/LICENSE_1_0.txt)
|
// http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
|
||||||
// Authors: Jaakko J<EFBFBD>rvi (jajarvi at osl.iu.edu)
|
// Authors: Jaakko Jarvi (jajarvi at osl.iu.edu)
|
||||||
// Jeremiah Willcock (jewillco at osl.iu.edu)
|
// Jeremiah Willcock (jewillco at osl.iu.edu)
|
||||||
// Andrew Lumsdaine (lums at osl.iu.edu)
|
// Andrew Lumsdaine (lums at osl.iu.edu)
|
||||||
|
|
||||||
|
@ -6,6 +6,12 @@
|
|||||||
#ifndef UUID_1D94A7C6054E11DB9804B622A1EF5492
|
#ifndef UUID_1D94A7C6054E11DB9804B622A1EF5492
|
||||||
#define UUID_1D94A7C6054E11DB9804B622A1EF5492
|
#define UUID_1D94A7C6054E11DB9804B622A1EF5492
|
||||||
|
|
||||||
|
#include <boost/exception/diagnostic_information.hpp>
|
||||||
|
#include <boost/exception/enable_current_exception.hpp>
|
||||||
|
#include <boost/exception/enable_error_info.hpp>
|
||||||
|
#include <boost/exception/error_info.hpp>
|
||||||
|
#include <boost/exception/exception.hpp>
|
||||||
|
#include <boost/exception/info.hpp>
|
||||||
#include <boost/exception/info_tuple.hpp>
|
#include <boost/exception/info_tuple.hpp>
|
||||||
#include <boost/exception_ptr.hpp>
|
#include <boost/exception_ptr.hpp>
|
||||||
#include <boost/throw_exception.hpp>
|
#include <boost/throw_exception.hpp>
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
//
|
//
|
||||||
// ref.hpp - ref/cref, useful helper functions
|
// ref.hpp - ref/cref, useful helper functions
|
||||||
//
|
//
|
||||||
// Copyright (C) 1999, 2000 Jaakko J<EFBFBD>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) 2001, 2002 Peter Dimov
|
||||||
// Copyright (C) 2002 David Abrahams
|
// Copyright (C) 2002 David Abrahams
|
||||||
//
|
//
|
||||||
@ -173,6 +173,12 @@ class unwrap_reference
|
|||||||
|
|
||||||
# endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
# endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
||||||
|
|
||||||
|
template <class T> inline typename unwrap_reference<T>::type&
|
||||||
|
unwrap_ref(T& t)
|
||||||
|
{
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace boost
|
} // namespace boost
|
||||||
|
|
||||||
#endif // #ifndef BOOST_REF_HPP_INCLUDED
|
#endif // #ifndef BOOST_REF_HPP_INCLUDED
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||||
// http://www.boost.org/LICENSE_1_0.txt)
|
// http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
|
||||||
// Authors: Jaakko J<EFBFBD>rvi (jajarvi at osl.iu.edu)
|
// Authors: Jaakko Jarvi (jajarvi at osl.iu.edu)
|
||||||
// Jeremiah Willcock (jewillco at osl.iu.edu)
|
// Jeremiah Willcock (jewillco at osl.iu.edu)
|
||||||
// Andrew Lumsdaine (lums at osl.iu.edu)
|
// Andrew Lumsdaine (lums at osl.iu.edu)
|
||||||
|
|
||||||
|
@ -24,12 +24,13 @@
|
|||||||
<a href="iterator_adaptors.htm">iterator_adaptors</a><br>
|
<a href="iterator_adaptors.htm">iterator_adaptors</a><br>
|
||||||
<a href="generator_iterator.htm">generator iterator adaptors</a><br>
|
<a href="generator_iterator.htm">generator iterator adaptors</a><br>
|
||||||
<a href="operators.htm">operators</a><br>
|
<a href="operators.htm">operators</a><br>
|
||||||
|
<a href="swap.html">swap</a><br>
|
||||||
<a href="throw_exception.html">throw_exception</a><br>
|
<a href="throw_exception.html">throw_exception</a><br>
|
||||||
<a href="utility.htm">utility</a><br>
|
<a href="utility.htm">utility</a><br>
|
||||||
<a href="value_init.htm">value_init</a></p>
|
<a href="value_init.htm">value_init</a></p>
|
||||||
</blockquote>
|
</blockquote>
|
||||||
<hr>
|
<hr>
|
||||||
<p>© Copyright Beman Dawes, 2001</p>
|
<p>© Copyright Beman Dawes, 2001</p>
|
||||||
<p>Distributed under the Boost Software License, Version 1.0. (See
|
<p>Distributed under the Boost Software License, Version 1.0. (See
|
||||||
accompanying file <a href="../../LICENSE_1_0.txt">
|
accompanying file <a href="../../LICENSE_1_0.txt">
|
||||||
LICENSE_1_0.txt</a> or copy at
|
LICENSE_1_0.txt</a> or copy at
|
||||||
|
43
ref_test.cpp
43
ref_test.cpp
@ -68,11 +68,54 @@ 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
|
} // namespace unnamed
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
void do_unwrap(T t) {
|
||||||
|
|
||||||
|
/* typename unwrap_reference<T>::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 * [])
|
int test_main(int, char * [])
|
||||||
{
|
{
|
||||||
ref_wrapper<int>::test(1);
|
ref_wrapper<int>::test(1);
|
||||||
ref_wrapper<int const>::test(1);
|
ref_wrapper<int const>::test(1);
|
||||||
|
unwrap_test();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
33
swap/test/Jamfile.v2
Normal file
33
swap/test/Jamfile.v2
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
# 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/<link>static ]
|
||||||
|
[ run specialized_in_boost.cpp ../../../test/build//boost_test_exec_monitor/<link>static ]
|
||||||
|
[ run specialized_in_global.cpp ../../../test/build//boost_test_exec_monitor/<link>static ]
|
||||||
|
[ run specialized_in_other.cpp ../../../test/build//boost_test_exec_monitor/<link>static ]
|
||||||
|
[ run specialized_in_std.cpp ../../../test/build//boost_test_exec_monitor/<link>static ]
|
||||||
|
[ run specialized_in_boost_and_other.cpp ../../../test/build//boost_test_exec_monitor/<link>static ]
|
||||||
|
[ run std_bitset.cpp ../../../test/build//boost_test_exec_monitor/<link>static ]
|
||||||
|
[ run std_dateorder.cpp ../../../test/build//boost_test_exec_monitor/<link>static ]
|
||||||
|
[ run std_string.cpp ../../../test/build//boost_test_exec_monitor/<link>static ]
|
||||||
|
[ run std_typeinfo_ptr.cpp ../../../test/build//boost_test_exec_monitor/<link>static ]
|
||||||
|
[ run std_vector_of_boost.cpp ../../../test/build//boost_test_exec_monitor/<link>static ]
|
||||||
|
[ run std_vector_of_global.cpp ../../../test/build//boost_test_exec_monitor/<link>static ]
|
||||||
|
[ run std_vector_of_other.cpp ../../../test/build//boost_test_exec_monitor/<link>static ]
|
||||||
|
[ run no_ambiguity_in_boost.cpp ../../../test/build//boost_test_exec_monitor/<link>static ]
|
||||||
|
[ run swap_arrays.cpp ../../../test/build//boost_test_exec_monitor/<link>static ]
|
||||||
|
;
|
10
swap/test/lib_header_1.cpp
Normal file
10
swap/test/lib_header_1.cpp
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
// 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 <boost/utility/swap.hpp>
|
||||||
|
|
11
swap/test/lib_header_2.cpp
Normal file
11
swap/test/lib_header_2.cpp
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
// 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 <boost/utility/swap.hpp>
|
||||||
|
#include <boost/utility/swap.hpp>
|
||||||
|
|
11
swap/test/mixed_headers_1.cpp
Normal file
11
swap/test/mixed_headers_1.cpp
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
// 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 <boost/swap.hpp>
|
||||||
|
#include <boost/utility/swap.hpp>
|
||||||
|
|
12
swap/test/mixed_headers_2.cpp
Normal file
12
swap/test/mixed_headers_2.cpp
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
// 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 <boost/utility/swap.hpp>
|
||||||
|
#include <boost/swap.hpp>
|
||||||
|
|
||||||
|
|
37
swap/test/no_ambiguity_in_boost.cpp
Normal file
37
swap/test/no_ambiguity_in_boost.cpp
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
// Copyright (c) 2008 Joseph Gauterin, Niels Dekker
|
||||||
|
//
|
||||||
|
// Distributed under the Boost Software License, Version 1.0.
|
||||||
|
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||||
|
// http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
|
||||||
|
// boost::swap internally does an unqualified function call to swap.
|
||||||
|
// This could have led to ambiguity or infinite recursion, when the
|
||||||
|
// objects to be swapped would themselves be from the boost namespace.
|
||||||
|
// If so, boost::swap itself might be found by argument dependent lookup.
|
||||||
|
// The implementation of boost::swap resolves this issue by giving
|
||||||
|
// boost::swap two template argumetns, thereby making it less specialized
|
||||||
|
// than std::swap.
|
||||||
|
|
||||||
|
#include <boost/utility/swap.hpp>
|
||||||
|
#define BOOST_INCLUDE_MAIN
|
||||||
|
#include <boost/test/test_tools.hpp>
|
||||||
|
|
||||||
|
//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;
|
||||||
|
}
|
||||||
|
|
23
swap/test/primitive.cpp
Normal file
23
swap/test/primitive.cpp
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
// 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 <boost/utility/swap.hpp>
|
||||||
|
#define BOOST_INCLUDE_MAIN
|
||||||
|
#include <boost/test/test_tools.hpp>
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
10
swap/test/root_header_1.cpp
Normal file
10
swap/test/root_header_1.cpp
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
// 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 <boost/swap.hpp>
|
||||||
|
|
11
swap/test/root_header_2.cpp
Normal file
11
swap/test/root_header_2.cpp
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
// 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 <boost/swap.hpp>
|
||||||
|
#include <boost/swap.hpp>
|
||||||
|
|
37
swap/test/specialized_in_boost.cpp
Normal file
37
swap/test/specialized_in_boost.cpp
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
// 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 <boost/utility/swap.hpp>
|
||||||
|
#define BOOST_INCLUDE_MAIN
|
||||||
|
#include <boost/test/test_tools.hpp>
|
||||||
|
|
||||||
|
//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;
|
||||||
|
}
|
||||||
|
|
56
swap/test/specialized_in_boost_and_other.cpp
Normal file
56
swap/test/specialized_in_boost_and_other.cpp
Normal file
@ -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 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 <boost/utility/swap.hpp>
|
||||||
|
#define BOOST_INCLUDE_MAIN
|
||||||
|
#include <boost/test/test_tools.hpp>
|
||||||
|
|
||||||
|
//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;
|
||||||
|
}
|
||||||
|
|
31
swap/test/specialized_in_global.cpp
Normal file
31
swap/test/specialized_in_global.cpp
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
// 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 <boost/utility/swap.hpp>
|
||||||
|
#define BOOST_INCLUDE_MAIN
|
||||||
|
#include <boost/test/test_tools.hpp>
|
||||||
|
|
||||||
|
//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;
|
||||||
|
}
|
||||||
|
|
37
swap/test/specialized_in_other.cpp
Normal file
37
swap/test/specialized_in_other.cpp
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
// 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 <boost/utility/swap.hpp>
|
||||||
|
#define BOOST_INCLUDE_MAIN
|
||||||
|
#include <boost/test/test_tools.hpp>
|
||||||
|
|
||||||
|
//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;
|
||||||
|
}
|
||||||
|
|
36
swap/test/specialized_in_std.cpp
Normal file
36
swap/test/specialized_in_std.cpp
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
// 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 <boost/utility/swap.hpp>
|
||||||
|
#define BOOST_INCLUDE_MAIN
|
||||||
|
#include <boost/test/test_tools.hpp>
|
||||||
|
|
||||||
|
//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;
|
||||||
|
}
|
||||||
|
|
33
swap/test/std_bitset.cpp
Normal file
33
swap/test/std_bitset.cpp
Normal file
@ -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<T> objects by means of boost::swap.
|
||||||
|
// Unlike most other Standard C++ Library template classes,
|
||||||
|
// std::bitset<T> does not have its own std::swap overload.
|
||||||
|
|
||||||
|
#include <boost/utility/swap.hpp>
|
||||||
|
#define BOOST_INCLUDE_MAIN
|
||||||
|
#include <boost/test/test_tools.hpp>
|
||||||
|
|
||||||
|
#include <bitset>
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
32
swap/test/std_dateorder.cpp
Normal file
32
swap/test/std_dateorder.cpp
Normal file
@ -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 <boost/utility/swap.hpp>
|
||||||
|
#define BOOST_INCLUDE_MAIN
|
||||||
|
#include <boost/test/test_tools.hpp>
|
||||||
|
|
||||||
|
#include <locale>
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
31
swap/test/std_string.cpp
Normal file
31
swap/test/std_string.cpp
Normal file
@ -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 <boost/utility/swap.hpp>
|
||||||
|
#define BOOST_INCLUDE_MAIN
|
||||||
|
#include <boost/test/test_tools.hpp>
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
32
swap/test/std_typeinfo_ptr.cpp
Normal file
32
swap/test/std_typeinfo_ptr.cpp
Normal file
@ -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 <boost/utility/swap.hpp>
|
||||||
|
#define BOOST_INCLUDE_MAIN
|
||||||
|
#include <boost/test/test_tools.hpp>
|
||||||
|
|
||||||
|
#include <typeinfo>
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
54
swap/test/std_vector_of_boost.cpp
Normal file
54
swap/test/std_vector_of_boost.cpp
Normal file
@ -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 <boost/utility/swap.hpp>
|
||||||
|
#define BOOST_INCLUDE_MAIN
|
||||||
|
#include <boost/test/test_tools.hpp>
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
//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<swap_test_class_type> 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;
|
||||||
|
}
|
||||||
|
|
47
swap/test/std_vector_of_global.cpp
Normal file
47
swap/test/std_vector_of_global.cpp
Normal file
@ -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 <boost/utility/swap.hpp>
|
||||||
|
#define BOOST_INCLUDE_MAIN
|
||||||
|
#include <boost/test/test_tools.hpp>
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
//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<swap_test_class> 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;
|
||||||
|
}
|
||||||
|
|
54
swap/test/std_vector_of_other.cpp
Normal file
54
swap/test/std_vector_of_other.cpp
Normal file
@ -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 <boost/utility/swap.hpp>
|
||||||
|
#define BOOST_INCLUDE_MAIN
|
||||||
|
#include <boost/test/test_tools.hpp>
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
//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<swap_test_class_type> 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;
|
||||||
|
}
|
||||||
|
|
59
swap/test/swap_arrays.cpp
Normal file
59
swap/test/swap_arrays.cpp
Normal file
@ -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 <boost/utility/swap.hpp>
|
||||||
|
#define BOOST_INCLUDE_MAIN
|
||||||
|
#include <boost/test/test_tools.hpp>
|
||||||
|
|
||||||
|
//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: 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 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_array2);
|
||||||
|
|
||||||
|
BOOST_CHECK_EQUAL(swap_test_class::swap_count(), firstDimension*secondDimension);
|
||||||
|
BOOST_CHECK_EQUAL(swap_test_class::copy_count(), 0);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
84
swap/test/swap_test_class.hpp
Normal file
84
swap/test/swap_test_class.hpp
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
// Copyright (c) 2007-2008 Joseph Gauterin
|
||||||
|
//
|
||||||
|
// Distributed under the Boost Software License, Version 1.0.
|
||||||
|
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||||
|
// http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
|
||||||
|
// Tests class used by the Boost.Swap tests
|
||||||
|
|
||||||
|
#ifndef BOOST_UTILITY_SWAP_TEST_CLASS_HPP
|
||||||
|
#define BOOST_UTILITY_SWAP_TEST_CLASS_HPP
|
||||||
|
|
||||||
|
|
||||||
|
class swap_test_class
|
||||||
|
{
|
||||||
|
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
|
Reference in New Issue
Block a user