Make sure test suite/examples/bench compile with exceptions disabled (exception-handling=off)

This commit is contained in:
Ion Gaztañaga
2020-10-22 01:12:59 +02:00
parent 03f030af69
commit 4bebeb2353
16 changed files with 399 additions and 323 deletions

View File

@ -11,6 +11,7 @@ Distributed under the [Boost Software License, Version 1.0](http://www.boost.org
* C++03
* Mostly header-only, library compilation is required for few features.
* Supports compiler modes without exceptions support (e.g. `-fno-exceptions`).
### Build Status

View File

@ -13,6 +13,8 @@
#endif
#include <boost/container/detail/dlmalloc.hpp>
#include <boost/core/no_exceptions_support.hpp>
#include <boost/container/throw_exception.hpp>
#define BOOST_INTERPROCESS_VECTOR_ALLOC_STATS
@ -61,7 +63,7 @@ void allocation_timing_test(unsigned int num_iterations, unsigned int num_elemen
dlmalloc_free(first_mem);
++numalloc;
try{
BOOST_TRY{
dlmalloc_command_ret_t ret;
for(size_t e = capacity + 1; e < num_elements; ++e){
size_t received_size;
@ -73,8 +75,7 @@ void allocation_timing_test(unsigned int num_iterations, unsigned int num_elemen
( m_mode, sizeof(POD)
, min, max, &received_size, addr);
if(!ret.first){
std::cout << "(!ret.first)!" << std::endl;
throw int(0);
throw_runtime_error("!ret.first)");
}
if(!ret.second){
assert(m_mode == BOOST_CONTAINER_ALLOCATE_NEW);
@ -100,10 +101,11 @@ void allocation_timing_test(unsigned int num_iterations, unsigned int num_elemen
}
dlmalloc_free(addr);
}
catch(...){
BOOST_CATCH(...){
dlmalloc_free(addr);
throw;
BOOST_RETHROW;
}
BOOST_CATCH_END
}
assert( dlmalloc_allocated_memory() == 0);

View File

@ -13,6 +13,7 @@
#endif
#include <boost/container/allocator.hpp>
#include <boost/core/no_exceptions_support.hpp>
#define BOOST_CONTAINER_VECTOR_ALLOC_STATS
@ -109,7 +110,7 @@ void vector_test_template(unsigned int num_iterations, unsigned int num_elements
bc::vector<MyInt, IntAllocator> v;
v.reset_alloc_stats();
void *first_mem = 0;
try{
BOOST_TRY{
first_mem = bc::dlmalloc_malloc(sizeof(MyInt)*num_elements*3/2);
v.push_back(MyInt(0));
bc::dlmalloc_free(first_mem);
@ -121,10 +122,11 @@ void vector_test_template(unsigned int num_iterations, unsigned int num_elements
numexpand += v.num_expand_bwd;
capacity = static_cast<unsigned int>(v.capacity());
}
catch(...){
BOOST_CATCH(...){
bc::dlmalloc_free(first_mem);
throw;
BOOST_RETHROW;
}
BOOST_CATCH_END
}
assert(bc::dlmalloc_allocated_memory() == 0);

View File

@ -19,6 +19,7 @@
#include <iomanip>
#include <boost/container/vector.hpp>
#include <boost/container/string.hpp>
#include <boost/core/no_exceptions_support.hpp>
using boost::timer::cpu_timer;
using boost::timer::cpu_times;
@ -394,91 +395,87 @@ template<class BoostClass, class StdClass>
void launch_tests(const char *BoostContName, const char *StdContName)
{
typedef range_provider<typename BoostClass::value_type> get_range_t;
try {
std::cout << "**********************************************" << '\n';
std::cout << "**********************************************" << '\n';
std::cout << '\n';
std::cout << BoostContName << " .VS " << StdContName << '\n';
std::cout << '\n';
std::cout << "**********************************************" << '\n';
std::cout << "**********************************************" << '\n' << std::endl;
{
std::cout << "Copy/Assign/Destroy benchmark:" << BoostContName << std::endl;
cpu_times boost_set_time = copy_destroy_time< BoostClass >(get_range_t::sorted_unique());
std::cout << "Copy/Assign/Destroy benchmark:" << StdContName << std::endl;
cpu_times std_set_time = copy_destroy_time< StdClass >(get_range_t::sorted_unique());
std::cout << "**********************************************" << '\n';
std::cout << "**********************************************" << '\n';
std::cout << '\n';
std::cout << BoostContName << " .VS " << StdContName << '\n';
std::cout << '\n';
std::cout << "**********************************************" << '\n';
std::cout << "**********************************************" << '\n' << std::endl;
{
std::cout << "Copy/Assign/Destroy benchmark:" << BoostContName << std::endl;
cpu_times boost_set_time = copy_destroy_time< BoostClass >(get_range_t::sorted_unique());
std::cout << BoostContName << "/" << StdContName << ": ";
compare_times(boost_set_time, std_set_time);
}
{
std::cout << "Ordered construct benchmark:" << BoostContName << std::endl;
cpu_times boost_set_time = construct_time< BoostClass >(get_range_t::sorted_unique(), get_range_t::sorted(), "(ord)");
std::cout << "Copy/Assign/Destroy benchmark:" << StdContName << std::endl;
cpu_times std_set_time = copy_destroy_time< StdClass >(get_range_t::sorted_unique());
std::cout << "Ordered construct benchmark:" << StdContName << std::endl;
cpu_times std_set_time = construct_time< StdClass >(get_range_t::sorted_unique(), get_range_t::sorted(), "(ord)");;
std::cout << BoostContName << "/" << StdContName << ": ";
compare_times(boost_set_time, std_set_time);
}
{
std::cout << "Ordered construct benchmark:" << BoostContName << std::endl;
cpu_times boost_set_time = construct_time< BoostClass >(get_range_t::sorted_unique(), get_range_t::sorted(), "(ord)");
std::cout << BoostContName << "/" << StdContName << ": ";
compare_times(boost_set_time, std_set_time);
}
{
std::cout << "Random construct benchmark:" << BoostContName << std::endl;
cpu_times boost_set_time = construct_time< BoostClass >(get_range_t::random_unique(), get_range_t::random(), "(rnd)");
std::cout << "Ordered construct benchmark:" << StdContName << std::endl;
cpu_times std_set_time = construct_time< StdClass >(get_range_t::sorted_unique(), get_range_t::sorted(), "(ord)");;
std::cout << "Random construct benchmark:" << StdContName << std::endl;
cpu_times std_set_time = construct_time< StdClass >(get_range_t::random_unique(), get_range_t::random(), "(rnd)");;
std::cout << BoostContName << "/" << StdContName << ": ";
compare_times(boost_set_time, std_set_time);
}
{
std::cout << "Random construct benchmark:" << BoostContName << std::endl;
cpu_times boost_set_time = construct_time< BoostClass >(get_range_t::random_unique(), get_range_t::random(), "(rnd)");
std::cout << BoostContName << "/" << StdContName << ": ";
compare_times(boost_set_time, std_set_time);
}
{
std::cout << "Ordered Insert benchmark:" << BoostContName << std::endl;
cpu_times boost_set_time = insert_time< BoostClass >(get_range_t::sorted_unique(), get_range_t::sorted(), "(ord)");
std::cout << "Random construct benchmark:" << StdContName << std::endl;
cpu_times std_set_time = construct_time< StdClass >(get_range_t::random_unique(), get_range_t::random(), "(rnd)");;
std::cout << "Ordered Insert benchmark:" << StdContName << std::endl;
cpu_times std_set_time = insert_time< StdClass >(get_range_t::sorted_unique(), get_range_t::sorted(), "(ord)");
std::cout << BoostContName << "/" << StdContName << ": ";
compare_times(boost_set_time, std_set_time);
}
{
std::cout << "Ordered Insert benchmark:" << BoostContName << std::endl;
cpu_times boost_set_time = insert_time< BoostClass >(get_range_t::sorted_unique(), get_range_t::sorted(), "(ord)");
std::cout << BoostContName << "/" << StdContName << ": ";
compare_times(boost_set_time, std_set_time);
}
{
std::cout << "Random Insert benchmark:" << BoostContName << std::endl;
cpu_times boost_set_time = insert_time< BoostClass >(get_range_t::random_unique(), get_range_t::random(), "(rnd)");
std::cout << "Ordered Insert benchmark:" << StdContName << std::endl;
cpu_times std_set_time = insert_time< StdClass >(get_range_t::sorted_unique(), get_range_t::sorted(), "(ord)");
std::cout << "Random Insert benchmark:" << StdContName << std::endl;
cpu_times std_set_time = insert_time< StdClass >(get_range_t::random_unique(), get_range_t::random(), "(rnd)");
std::cout << BoostContName << "/" << StdContName << ": ";
compare_times(boost_set_time, std_set_time);
}
{
std::cout << "Random Insert benchmark:" << BoostContName << std::endl;
cpu_times boost_set_time = insert_time< BoostClass >(get_range_t::random_unique(), get_range_t::random(), "(rnd)");
std::cout << BoostContName << "/" << StdContName << ": ";
compare_times(boost_set_time, std_set_time);
}
{
std::cout << "Ordered Search benchmark:" << BoostContName << std::endl;
cpu_times boost_set_time = search_time< BoostClass >(get_range_t::sorted_unique(), "(ord)");
std::cout << "Random Insert benchmark:" << StdContName << std::endl;
cpu_times std_set_time = insert_time< StdClass >(get_range_t::random_unique(), get_range_t::random(), "(rnd)");
std::cout << "Ordered Search benchmark:" << StdContName << std::endl;
cpu_times std_set_time = search_time< StdClass >(get_range_t::sorted_unique(), "(ord)");
std::cout << BoostContName << "/" << StdContName << ": ";
compare_times(boost_set_time, std_set_time);
}
{
std::cout << "Ordered Search benchmark:" << BoostContName << std::endl;
cpu_times boost_set_time = search_time< BoostClass >(get_range_t::sorted_unique(), "(ord)");
std::cout << BoostContName << "/" << StdContName << ": ";
compare_times(boost_set_time, std_set_time);
}
{
std::cout << "Random Search benchmark:" << BoostContName << std::endl;
cpu_times boost_set_time = search_time< BoostClass >(get_range_t::random_unique(), "(rnd)");
std::cout << "Ordered Search benchmark:" << StdContName << std::endl;
cpu_times std_set_time = search_time< StdClass >(get_range_t::sorted_unique(), "(ord)");
std::cout << "Random Search benchmark:" << StdContName << std::endl;
cpu_times std_set_time = search_time< StdClass >(get_range_t::random_unique(), "(rnd)");
std::cout << BoostContName << "/" << StdContName << ": ";
compare_times(boost_set_time, std_set_time);
}
{
std::cout << "Random Search benchmark:" << BoostContName << std::endl;
cpu_times boost_set_time = search_time< BoostClass >(get_range_t::random_unique(), "(rnd)");
std::cout << BoostContName << "/" << StdContName << ": ";
compare_times(boost_set_time, std_set_time);
}
{
std::cout << "Extensions benchmark:" << BoostContName << std::endl;
extensions_time< BoostClass >(get_range_t::sorted_unique());
}
std::cout << "Random Search benchmark:" << StdContName << std::endl;
cpu_times std_set_time = search_time< StdClass >(get_range_t::random_unique(), "(rnd)");
}catch(std::exception &e){
std::cout << e.what();
std::cout << BoostContName << "/" << StdContName << ": ";
compare_times(boost_set_time, std_set_time);
}
{
std::cout << "Extensions benchmark:" << BoostContName << std::endl;
extensions_time< BoostClass >(get_range_t::sorted_unique());
}
}

View File

@ -14,8 +14,10 @@
// @brief varray_benchmark.cpp compares the performance of boost::container::varray to boost::container::vector
#include "varray.hpp"
#include "boost/container/vector.hpp"
#include "boost/container/static_vector.hpp"
#include <boost/container/vector.hpp>
#include <boost/container/static_vector.hpp>
#include <boost/core/no_exceptions_support.hpp>
#include "../test/movable_int.hpp"
#include <vector>
#include <iostream>
@ -114,31 +116,28 @@ void compare_times(cpu_times time_numerator, cpu_times time_denominator){
int main()
{
try {
std::cout << "N = " << N << " Iter = " << Iter << "\n\n";
std::cout << "N = " << N << " Iter = " << Iter << "\n\n";
std::cout << "varray benchmark:" << std::endl;
cpu_times time_varray = time_it<boost::container::varray<boost::container::varray<basic_type_t,N>,N > >();
std::cout << "varray benchmark:" << std::endl;
cpu_times time_varray = time_it<boost::container::varray<boost::container::varray<basic_type_t,N>,N > >();
std::cout << "boost::container::static_vector benchmark" << std::endl;
cpu_times time_boost_static_vector = time_it<boost::container::static_vector<boost::container::static_vector<basic_type_t,N>,N > >();
std::cout << "boost::container::static_vector benchmark" << std::endl;
cpu_times time_boost_static_vector = time_it<boost::container::static_vector<boost::container::static_vector<basic_type_t,N>,N > >();
std::cout << "boost::container::vector benchmark" << std::endl;
cpu_times time_boost_vector = time_it<boost::container::vector<boost::container::vector<basic_type_t> > >();
std::cout << "boost::container::vector benchmark" << std::endl;
cpu_times time_boost_vector = time_it<boost::container::vector<boost::container::vector<basic_type_t> > >();
std::cout << "std::vector benchmark" << std::endl;
cpu_times time_standard_vector = time_it<std::vector<std::vector<basic_type_t> > >();
std::cout << "std::vector benchmark" << std::endl;
cpu_times time_standard_vector = time_it<std::vector<std::vector<basic_type_t> > >();
std::cout << "varray/boost::container::vector total time comparison:";
compare_times(time_varray, time_boost_vector);
std::cout << "varray/boost::container::vector total time comparison:";
compare_times(time_varray, time_boost_vector);
std::cout << "varray/boost::container::static_vector total time comparison:";
compare_times(time_varray, time_boost_static_vector);
std::cout << "varray/boost::container::static_vector total time comparison:";
compare_times(time_varray, time_boost_static_vector);
std::cout << "varray/std::vector total time comparison:";
compare_times(time_varray,time_standard_vector);
std::cout << "varray/std::vector total time comparison:";
compare_times(time_varray,time_standard_vector);
}catch(std::exception &e){
std::cout << e.what();
}
return 0;
}

View File

@ -40,13 +40,13 @@ int main ()
//
//AVLTree based set container
typedef set<int, std::less<int>, std::allocator<int>, AVLTree> AvlSet;
typedef set<int, std::less<int>, new_allocator<int>, AVLTree> AvlSet;
//AVLTree based set container without size optimization
typedef set<int, std::less<int>, std::allocator<int>, AVLTreeNoSizeOpt> AvlSetNoSizeOpt;
typedef set<int, std::less<int>, new_allocator<int>, AVLTreeNoSizeOpt> AvlSetNoSizeOpt;
//Splay tree based multiset container
typedef multiset<int, std::less<int>, std::allocator<int>, SplayTree> SplayMultiset;
typedef multiset<int, std::less<int>, new_allocator<int>, SplayTree> SplayMultiset;
//Use them
//

View File

@ -7,9 +7,11 @@
// See http://www.boost.org/libs/container for documentation.
//
//////////////////////////////////////////////////////////////////////////////
#include <boost/core/no_exceptions_support.hpp>
//[doc_custom_vector
#include <boost/container/vector.hpp>
#include <boost/static_assert.hpp>
#include <boost/core/no_exceptions_support.hpp>
//Make sure assertions are active
#ifdef NDEBUG
@ -32,8 +34,16 @@ int main ()
//Requesting capacity for more elements than representable by "unsigned char"
//is an error in the size optimized vector.
bool exception_thrown = false;
try { size_optimized_vector_t v(256); }
catch(...){ exception_thrown = true; }
/*<-*/
#ifndef BOOST_NO_EXCEPTIONS
BOOST_TRY{ size_optimized_vector_t v(256); } BOOST_CATCH(...){ exception_thrown = true; } BOOST_CATCH_END
#else
exception_thrown = true;
#endif //BOOST_NO_EXCEPTIONS
/*->*/
//=try { size_optimized_vector_t v(256); }
//=catch(...){ exception_thrown = true; }
assert(exception_thrown == true);
//This option specifies that a vector will increase its capacity 50%

View File

@ -17,6 +17,7 @@ using namespace boost::container;
template<class Unsigned, class DevectorType>
void test_stored_size_type_impl()
{
#ifndef BOOST_NO_EXCEPTIONS
DevectorType v;
typedef typename DevectorType::size_type size_type;
typedef typename DevectorType::value_type value_type;
@ -29,6 +30,7 @@ void test_stored_size_type_impl()
BOOST_TEST_THROWS(v.emplace(v.begin(), value_type(1)),std::exception);
BOOST_TEST_THROWS(v.reserve(max+1), std::exception);
BOOST_TEST_THROWS(DevectorType v2(max+1), std::exception);
#endif
}
template<class Unsigned>

View File

@ -16,6 +16,7 @@
#include <limits>
#include <boost/container/list.hpp>
#include <boost/container/vector.hpp>
#include <boost/core/no_exceptions_support.hpp>
#include <boost/type_traits/is_default_constructible.hpp>
#include <boost/type_traits/is_nothrow_move_constructible.hpp>
#include "dummy_test_allocator.hpp"
@ -133,8 +134,6 @@ template <class Devector> void test_constructor_reserve_only_front_back()
template <class Devector> void test_constructor_n()
{
typedef typename Devector::value_type T;
{
Devector a(8);
const int expected [] = {0, 0, 0, 0, 0, 0, 0, 0};
@ -148,6 +147,9 @@ template <class Devector> void test_constructor_n()
BOOST_TEST(b.get_alloc_count() == 0u);
}
#ifndef BOOST_NO_EXCEPTIONS
typedef typename Devector::value_type T;
BOOST_IF_CONSTEXPR (! boost::move_detail::is_nothrow_default_constructible<T>::value)
{
test_elem_throw::on_ctor_after(4);
@ -155,15 +157,18 @@ template <class Devector> void test_constructor_n()
BOOST_TEST(test_elem_base::no_living_elem());
test_elem_throw::do_not_throw();
}
#endif //#ifndef BOOST_NO_EXCEPTIONS
}
template <class Devector> void test_constructor_n_copy_throwing(dtl::true_)
{
#ifndef BOOST_NO_EXCEPTIONS
typedef typename Devector::value_type T;
test_elem_throw::on_copy_after(4);
const T x(404);
BOOST_TEST_THROWS(Devector(8, x), test_exception);
test_elem_throw::do_not_throw();
#endif //#ifndef BOOST_NO_EXCEPTIONS
}
@ -220,6 +225,7 @@ template <class Devector> void test_constructor_input_range()
BOOST_TEST(test_elem_base::no_living_elem());
/* //if move_if_noexcept is implemented
#ifndef BOOST_NO_EXCEPTIONS
if (! boost::move_detail::is_nothrow_copy_constructible<T>::value)
{
devector<T> input; get_range<devector<T> >(16, input);
@ -233,6 +239,7 @@ template <class Devector> void test_constructor_input_range()
}
BOOST_TEST(test_elem_base::no_living_elem());
#endif //#ifndef BOOST_NO_EXCEPTIONS
*/
}
@ -272,12 +279,14 @@ template <class Devector> void test_constructor_forward_range()
BOOST_TEST(b.get_alloc_count() == 0u);
}
#ifndef BOOST_NO_EXCEPTIONS
BOOST_IF_CONSTEXPR (! boost::move_detail::is_nothrow_copy_constructible<T>::value)
{
test_elem_throw::on_copy_after(4);
BOOST_TEST_THROWS(Devector c(x.begin(), x.end()), test_exception);
test_elem_throw::do_not_throw();
}
#endif //#ifndef BOOST_NO_EXCEPTIONS
}
template <class Devector> void test_constructor_pointer_range()
@ -303,18 +312,18 @@ template <class Devector> void test_constructor_pointer_range()
BOOST_TEST(b.get_alloc_count() == 0u);
}
#ifndef BOOST_NO_EXCEPTIONS
if (! boost::move_detail::is_nothrow_copy_constructible<T>::value)
{
test_elem_throw::on_copy_after(4);
BOOST_TEST_THROWS(Devector c(xbeg, xend), test_exception);
test_elem_throw::do_not_throw();
}
#endif //#ifndef BOOST_NO_EXCEPTIONS
}
template <class Devector> void test_copy_constructor()
{
typedef typename Devector::value_type T;
{
Devector a;
Devector b(a);
@ -331,6 +340,9 @@ template <class Devector> void test_copy_constructor()
BOOST_TEST(b.get_alloc_count() <= 1u);
}
#ifndef BOOST_NO_EXCEPTIONS
typedef typename Devector::value_type T;
if (! boost::move_detail::is_nothrow_copy_constructible<T>::value)
{
Devector a; get_range<Devector>(8, a);
@ -339,6 +351,7 @@ template <class Devector> void test_copy_constructor()
BOOST_TEST_THROWS(Devector b(a), test_exception);
test_elem_throw::do_not_throw();
}
#endif //#ifndef BOOST_NO_EXCEPTIONS
}
template <class Devector> void test_move_constructor()
@ -385,7 +398,6 @@ template <class Devector> void test_destructor()
template <class Devector> void test_assignment()
{
typedef typename Devector::value_type T;
const typename Devector::size_type alloc_count =
boost::container::allocator_traits
< typename Devector::allocator_type >::propagate_on_container_copy_assignment::value;
@ -462,6 +474,8 @@ template <class Devector> void test_assignment()
BOOST_TEST(a.get_alloc_count() == alloc_count);
}
#ifndef BOOST_NO_EXCEPTIONS
typedef typename Devector::value_type T;
BOOST_IF_CONSTEXPR (! boost::move_detail::is_nothrow_copy_constructible<T>::value)
{
// strong guarantee if reallocation is needed (no guarantee otherwise)
@ -475,8 +489,8 @@ template <class Devector> void test_assignment()
const int expected[] = {1, 2, 3, 4, 5, 6};
test_equal_range(a, expected);
}
#endif //#ifndef BOOST_NO_EXCEPTIONS
}
template <class Devector> void test_move_assignment_throwing(dtl::true_)
@ -501,8 +515,6 @@ template <class Devector> void test_move_assignment_throwing(dtl::false_)
template <class Devector> void test_move_assignment()
{
typedef typename Devector::value_type T;
{ // assign to empty (maybe small)
Devector a;
Devector b; get_range<Devector>(6, b);
@ -539,6 +551,7 @@ template <class Devector> void test_move_assignment()
test_equal_range(b);
}
typedef typename Devector::value_type T;
test_move_assignment_throwing<Devector>
(boost::move_detail::bool_<! boost::move_detail::is_nothrow_copy_constructible<T>::value>());
}
@ -546,7 +559,6 @@ template <class Devector> void test_move_assignment()
template <class Devector> void test_il_assignment()
{
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
typedef typename Devector::value_type T;
{ // assign to empty (maybe small)
Devector a;
@ -603,6 +615,8 @@ template <class Devector> void test_il_assignment()
BOOST_TEST(a.get_alloc_count() == 0u);
}
#ifndef BOOST_NO_EXCEPTIONS
typedef typename Devector::value_type T;
if (! boost::move_detail::is_nothrow_copy_constructible<T>::value)
{
// strong guarantee if reallocation is needed (no guarantee otherwise)
@ -610,130 +624,135 @@ template <class Devector> void test_il_assignment()
test_elem_throw::on_copy_after(3);
try
BOOST_TRY
{
a = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
BOOST_TEST(false);
} catch(const test_exception&) {}
}
BOOST_CATCH(const test_exception&) {}
BOOST_CATCH_END
test_elem_throw::do_not_throw();
test_equal_range(a, {1, 2, 3, 4, 5, 6});
}
#endif //BOOST_NO_EXCEPTIONS
#endif //#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
}
template <class Devector> void test_assign_input_range()
{
typedef typename Devector::value_type T;
typedef typename Devector::value_type T;
{ // assign to empty, keep it small
devector<T> expected; get_range<Devector>(1, 13, 13, 25, expected);
devector<T> input = expected;
{ // assign to empty, keep it small
devector<T> expected; get_range<Devector>(1, 13, 13, 25, expected);
devector<T> input = expected;
input_iterator<Devector> input_begin = make_input_iterator(input, input.begin());
input_iterator<Devector> input_end = make_input_iterator(input, input.end());
input_iterator<Devector> input_begin = make_input_iterator(input, input.begin());
input_iterator<Devector> input_end = make_input_iterator(input, input.end());
Devector a;
a.reset_alloc_stats();
a.assign(input_begin, input_end);
Devector a;
a.reset_alloc_stats();
a.assign(input_begin, input_end);
BOOST_TEST(a == expected);
}
BOOST_TEST(a == expected);
}
{ // assign to empty (maybe small)
devector<T> input; get_range<devector<T> >(6, input);
{ // assign to empty (maybe small)
devector<T> input; get_range<devector<T> >(6, input);
input_iterator<Devector> input_begin = make_input_iterator(input, input.begin());
input_iterator<Devector> input_end = make_input_iterator(input, input.end());
input_iterator<Devector> input_begin = make_input_iterator(input, input.begin());
input_iterator<Devector> input_end = make_input_iterator(input, input.end());
Devector a;
Devector a;
a.assign(input_begin, input_end);
const int expected [] = {1, 2, 3, 4, 5, 6};
test_equal_range(a, expected);
}
a.assign(input_begin, input_end);
const int expected [] = {1, 2, 3, 4, 5, 6};
test_equal_range(a, expected);
}
{ // assign from empty
devector<T> input; get_range<devector<T> >(6, input);
input_iterator<Devector> input_begin = make_input_iterator(input, input.begin());
{ // assign from empty
devector<T> input; get_range<devector<T> >(6, input);
input_iterator<Devector> input_begin = make_input_iterator(input, input.begin());
Devector a; get_range<Devector>(6, a);
a.assign(input_begin, input_begin);
Devector a; get_range<Devector>(6, a);
a.assign(input_begin, input_begin);
test_equal_range(a);
}
test_equal_range(a);
}
{ // assign to non-empty
devector<T> input; get_range<devector<T> >(6, input);
input_iterator<Devector> input_begin = make_input_iterator(input, input.begin());
input_iterator<Devector> input_end = make_input_iterator(input, input.end());
{ // assign to non-empty
devector<T> input; get_range<devector<T> >(6, input);
input_iterator<Devector> input_begin = make_input_iterator(input, input.begin());
input_iterator<Devector> input_end = make_input_iterator(input, input.end());
Devector a; get_range<Devector>(11, 15, 15, 19, a);
a.assign(input_begin, input_end);
const int expected [] = {1, 2, 3, 4, 5, 6};
test_equal_range(a, expected);
}
Devector a; get_range<Devector>(11, 15, 15, 19, a);
a.assign(input_begin, input_end);
const int expected [] = {1, 2, 3, 4, 5, 6};
test_equal_range(a, expected);
}
{ // assign to free front
devector<T> input; get_range<devector<T> >(6, input);
input_iterator<Devector> input_begin = make_input_iterator(input, input.begin());
input_iterator<Devector> input_end = make_input_iterator(input, input.end());
{ // assign to free front
devector<T> input; get_range<devector<T> >(6, input);
input_iterator<Devector> input_begin = make_input_iterator(input, input.begin());
input_iterator<Devector> input_end = make_input_iterator(input, input.end());
Devector a; get_range<Devector>(11, 15, 15, 19, a);
a.reserve_front(8);
a.reset_alloc_stats();
Devector a; get_range<Devector>(11, 15, 15, 19, a);
a.reserve_front(8);
a.reset_alloc_stats();
a.assign(input_begin, input_end);
const int expected[] = {1, 2, 3, 4, 5, 6};
test_equal_range(a, expected);
}
a.assign(input_begin, input_end);
const int expected[] = {1, 2, 3, 4, 5, 6};
test_equal_range(a, expected);
}
{ // assignment overlaps contents
devector<T> input; get_range<devector<T> >(6, input);
input_iterator<Devector> input_begin = make_input_iterator(input, input.begin());
input_iterator<Devector> input_end = make_input_iterator(input, input.end());
{ // assignment overlaps contents
devector<T> input; get_range<devector<T> >(6, input);
input_iterator<Devector> input_begin = make_input_iterator(input, input.begin());
input_iterator<Devector> input_end = make_input_iterator(input, input.end());
Devector a; get_range<Devector>(11, 15, 15, 19, a);
a.reserve_front(12);
a.reset_alloc_stats();
Devector a; get_range<Devector>(11, 15, 15, 19, a);
a.reserve_front(12);
a.reset_alloc_stats();
a.assign(input_begin, input_end);
const int expected[] = {1, 2, 3, 4, 5, 6};
test_equal_range(a, expected);
}
a.assign(input_begin, input_end);
const int expected[] = {1, 2, 3, 4, 5, 6};
test_equal_range(a, expected);
}
{ // assignment exceeds contents
devector<T> input; get_range<devector<T> >(12, input);
input_iterator<Devector> input_begin = make_input_iterator(input, input.begin());
input_iterator<Devector> input_end = make_input_iterator(input, input.end());
{ // assignment exceeds contents
devector<T> input; get_range<devector<T> >(12, input);
input_iterator<Devector> input_begin = make_input_iterator(input, input.begin());
input_iterator<Devector> input_end = make_input_iterator(input, input.end());
Devector a; get_range<Devector>(11, 13, 13, 15, a);
a.reserve_front(8);
a.reserve_back(8);
a.reset_alloc_stats();
Devector a; get_range<Devector>(11, 13, 13, 15, a);
a.reserve_front(8);
a.reserve_back(8);
a.reset_alloc_stats();
a.assign(input_begin, input_end);
const int expected[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
test_equal_range(a, expected);
}
a.assign(input_begin, input_end);
const int expected[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
test_equal_range(a, expected);
}
if (! boost::move_detail::is_nothrow_copy_constructible<T>::value)
{
// strong guarantee if reallocation is needed (no guarantee otherwise)
#ifndef BOOST_NO_EXCEPTIONS
if (! boost::move_detail::is_nothrow_copy_constructible<T>::value)
{
// strong guarantee if reallocation is needed (no guarantee otherwise)
devector<T> input; get_range<devector<T> >(12, input);
input_iterator<Devector> input_begin = make_input_iterator(input, input.begin());
input_iterator<Devector> input_end = make_input_iterator(input, input.end());
devector<T> input; get_range<devector<T> >(12, input);
input_iterator<Devector> input_begin = make_input_iterator(input, input.begin());
input_iterator<Devector> input_end = make_input_iterator(input, input.end());
Devector a; get_range<Devector>(6, a);
Devector a; get_range<Devector>(6, a);
test_elem_throw::on_copy_after(3);
BOOST_TEST_THROWS(a.assign(input_begin, input_end), test_exception);
test_elem_throw::do_not_throw();
test_elem_throw::on_copy_after(3);
BOOST_TEST_THROWS(a.assign(input_begin, input_end), test_exception);
test_elem_throw::do_not_throw();
const int expected[] = {1, 2, 3, 4, 5, 6};
test_equal_range(a, expected);
}
const int expected[] = {1, 2, 3, 4, 5, 6};
test_equal_range(a, expected);
}
#endif //#ifndef BOOST_NO_EXCEPTIONS
}
template <class Devector> void test_assign_forward_range_throwing(dtl::false_)
@ -829,6 +848,7 @@ template <class Devector> void test_assign_forward_range()
BOOST_TEST(a.get_alloc_count() == 0u);
}
#ifndef BOOST_NO_EXCEPTIONS
BOOST_IF_CONSTEXPR(! boost::move_detail::is_nothrow_copy_constructible<T>::value)
{
// strong guarantee if reallocation is needed (no guarantee otherwise)
@ -841,6 +861,7 @@ template <class Devector> void test_assign_forward_range()
const int expected [] = {1, 2, 3, 4, 5, 6};
test_equal_range(a, expected);
}
#endif //#ifndef BOOST_NO_EXCEPTIONS
}
template <class Devector> void test_assign_pointer_range()
@ -915,6 +936,7 @@ template <class Devector> void test_assign_pointer_range()
BOOST_TEST(a.get_alloc_count() == 0u);
}
#ifndef BOOST_NO_EXCEPTIONS
if (! boost::move_detail::is_nothrow_copy_constructible<T>::value)
{
// strong guarantee if reallocation is needed (no guarantee otherwise)
@ -927,6 +949,7 @@ template <class Devector> void test_assign_pointer_range()
const int expected[] = {1, 2, 3, 4, 5, 6};
test_equal_range(a, expected);
}
#endif //#ifndef BOOST_NO_EXCEPTIONS
}
template <class Devector> void test_assign_n()
@ -996,6 +1019,7 @@ template <class Devector> void test_assign_n()
BOOST_TEST(a.get_alloc_count() == 0u);
}
#ifndef BOOST_NO_EXCEPTIONS
if (! boost::move_detail::is_nothrow_copy_constructible<T>::value)
{
// strong guarantee if reallocation is needed (no guarantee otherwise)
@ -1008,12 +1032,12 @@ template <class Devector> void test_assign_n()
const int expected[] = {1, 2, 3, 4, 5, 6};
test_equal_range(a, expected);
}
#endif //#ifndef BOOST_NO_EXCEPTIONS
}
template <class Devector> void test_assign_il()
{
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
typedef typename Devector::value_type T;
{ // assign to empty (maybe small)
Devector a;
@ -1073,6 +1097,8 @@ template <class Devector> void test_assign_il()
BOOST_TEST(a.get_alloc_count() == 0u);
}
#ifndef BOOST_NO_EXCEPTIONS
typedef typename Devector::value_type T;
if (! boost::move_detail::is_nothrow_copy_constructible<T>::value)
{
// strong guarantee if reallocation is needed (no guarantee otherwise)
@ -1084,6 +1110,7 @@ template <class Devector> void test_assign_il()
test_equal_range(a, {1, 2, 3, 4, 5, 6});
}
#endif //#ifndef BOOST_NO_EXCEPTIONS
#endif //#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
}
@ -1154,10 +1181,12 @@ void test_max_size()
void test_exceeding_max_size()
{/*
using Devector = gp_devector<unsigned char>;
#ifndef BOOST_NO_EXCEPTIONS
using Devector = gp_devector<unsigned char>;
Devector a((std::numeric_limits<typename Devector::size_type>::max)());
BOOST_TEST_THROWS(a.emplace_back(404), std::length_error);
Devector a((std::numeric_limits<typename Devector::size_type>::max)());
BOOST_TEST_THROWS(a.emplace_back(404), std::length_error);
#endif //#ifndef BOOST_NO_EXCEPTIONS
*/
}
@ -1195,6 +1224,7 @@ template <class Devector> void test_capacity()
template <class Devector> void test_resize_front_throwing(dtl::true_)
{
#ifndef BOOST_NO_EXCEPTIONS
typedef typename Devector::iterator iterator;
Devector d; get_range<Devector>(5, d);
@ -1207,6 +1237,7 @@ template <class Devector> void test_resize_front_throwing(dtl::true_)
test_equal_range(d, d_origi);
BOOST_TEST(origi_begin == d.begin());
#endif //#ifndef BOOST_NO_EXCEPTIONS
}
template <class Devector> void test_resize_front_throwing(dtl::false_)
@ -1277,6 +1308,7 @@ template <class Devector> void test_resize_front()
template <class Devector> void test_resize_front_copy_throwing(dtl::true_)
{
#ifndef BOOST_NO_EXCEPTIONS
typedef typename Devector::value_type T;
typedef typename Devector::iterator iterator;
@ -1305,6 +1337,7 @@ template <class Devector> void test_resize_front_copy_throwing(dtl::true_)
test_equal_range(c, c_origi);
BOOST_TEST(origi_begin == c.begin());
}
#endif //#ifndef BOOST_NO_EXCEPTIONS
}
template <class Devector> void test_resize_front_copy_throwing(dtl::false_)
@ -1371,6 +1404,7 @@ template <class Devector> void test_resize_front_copy()
template <class Devector> void test_resize_back_throwing(dtl::true_)
// size < required, constructor throws
{
#ifndef BOOST_NO_EXCEPTIONS
typedef typename Devector::iterator iterator;
Devector d; get_range<Devector>(5, d);
@ -1383,6 +1417,7 @@ template <class Devector> void test_resize_back_throwing(dtl::true_)
test_equal_range(d, d_origi);
BOOST_TEST(origi_begin == d.begin());
#endif //#ifndef BOOST_NO_EXCEPTIONS
}
template <class Devector> void test_resize_back_throwing(dtl::false_)
@ -1452,6 +1487,7 @@ template <class Devector> void test_resize_back()
template <class Devector> void test_resize_back_copy_throwing(dtl::true_)
{
#ifndef BOOST_NO_EXCEPTIONS
typedef typename Devector::value_type T;
typedef typename Devector::iterator iterator;
@ -1494,6 +1530,7 @@ template <class Devector> void test_resize_back_copy_throwing(dtl::true_)
test_equal_range(c, c_origi);
BOOST_TEST(origi_begin == c.begin());
}
#endif //#ifndef BOOST_NO_EXCEPTIONS
}
template <class Devector> void test_resize_back_copy_throwing(dtl::false_)
@ -1560,8 +1597,6 @@ template <class Devector> void test_resize_back_copy()
/*
template <class Devector> void test_constructor_unsafe_uninitialized()
{
typedef typename Devector::value_type T;
{
Devector a(8, unsafe_uninitialized_tag_t());
BOOST_TEST(a.size() == 8u);
@ -1799,26 +1834,28 @@ template <class Devector> void test_index_operator()
template <class Devector> void test_at()
{
typedef typename Devector::value_type T;
#ifndef BOOST_NO_EXCEPTIONS
typedef typename Devector::value_type T;
{ // non-const at
Devector a; get_range<Devector>(3, a);
{ // non-const at
Devector a; get_range<Devector>(3, a);
BOOST_TEST(a.at(0) == 1);
a.at(0) = T(100);
BOOST_TEST(a.at(0) == 100);
BOOST_TEST(a.at(0) == 1);
a.at(0) = T(100);
BOOST_TEST(a.at(0) == 100);
BOOST_TEST_THROWS(a.at(3), std::out_of_range);
}
BOOST_TEST_THROWS(a.at(3), std::out_of_range);
}
{ // const at
Devector b; get_range<Devector>(3, b);
const Devector &a = b;
{ // const at
Devector b; get_range<Devector>(3, b);
const Devector &a = b;
BOOST_TEST(a.at(0) == 1);
BOOST_TEST(a.at(0) == 1);
BOOST_TEST_THROWS(a.at(3), std::out_of_range);
}
BOOST_TEST_THROWS(a.at(3), std::out_of_range);
}
#endif //#ifndef BOOST_NO_EXCEPTIONS
}
template <class Devector> void test_front()
@ -1879,6 +1916,7 @@ void test_data()
template <class Devector> void test_emplace_front(dtl::true_)
{
#ifndef BOOST_NO_EXCEPTIONS
typedef typename Devector::iterator iterator;
Devector b; get_range<Devector>(4, b);
@ -1892,6 +1930,7 @@ template <class Devector> void test_emplace_front(dtl::true_)
BOOST_TEST(origi_begin == new_begin);
BOOST_TEST(b.size() == 4u);
#endif //#ifndef BOOST_NO_EXCEPTIONS
}
template <class Devector> void test_emplace_front(dtl::false_)
@ -1921,7 +1960,6 @@ template <class Devector> void test_emplace_front()
template <class Devector> void test_push_front()
{
typedef typename Devector::value_type T;
typedef typename Devector::iterator iterator;
{
boost::container::vector<int> expected; get_range<boost::container::vector<int> >(16, expected);
std::reverse(expected.begin(), expected.end());
@ -1936,6 +1974,8 @@ template <class Devector> void test_push_front()
test_equal_range(a, expected);
}
#ifndef BOOST_NO_EXCEPTIONS
typedef typename Devector::iterator iterator;
if (! boost::move_detail::is_nothrow_copy_constructible<T>::value)
{
Devector b; get_range<Devector>(4, b);
@ -1961,10 +2001,12 @@ template <class Devector> void test_push_front()
const int expected[] = {2, 1, 2, 3, 4};
test_equal_range(c, expected);
}
#endif //#ifndef BOOST_NO_EXCEPTIONS
}
template <class Devector> void test_push_front_rvalue_throwing(dtl::true_)
{
#ifndef BOOST_NO_EXCEPTIONS
typedef typename Devector::value_type T;
typedef typename Devector::iterator iterator;
@ -1979,6 +2021,7 @@ template <class Devector> void test_push_front_rvalue_throwing(dtl::true_)
BOOST_TEST(origi_begin == new_begin);
BOOST_TEST(b.size() == 4u);
#endif //#ifndef BOOST_NO_EXCEPTIONS
}
template <class Devector> void test_push_front_rvalue_throwing(dtl::false_)
@ -2038,6 +2081,7 @@ template <class Devector> void test_pop_front()
template <class Devector> void test_emplace_back_throwing(dtl::true_)
{
#ifndef BOOST_NO_EXCEPTIONS
typedef typename Devector::iterator iterator;
Devector b; get_range<Devector>(4, b);
@ -2051,6 +2095,7 @@ template <class Devector> void test_emplace_back_throwing(dtl::true_)
BOOST_TEST(origi_begin == new_begin);
BOOST_TEST(b.size() == 4u);
#endif //#ifndef BOOST_NO_EXCEPTIONS
}
template <class Devector> void test_emplace_back_throwing(dtl::false_)
@ -2078,6 +2123,7 @@ template <class Devector> void test_emplace_back()
template <class Devector> void test_push_back_throwing(dtl::true_)
{
#ifndef BOOST_NO_EXCEPTIONS
typedef typename Devector::value_type T;
typedef typename Devector::iterator iterator;
@ -2094,6 +2140,7 @@ template <class Devector> void test_push_back_throwing(dtl::true_)
BOOST_TEST(origi_begin == new_begin);
BOOST_TEST(b.size() == 4u);
#endif //#ifndef BOOST_NO_EXCEPTIONS
}
template <class Devector> void test_push_back_throwing(dtl::false_)
@ -2129,6 +2176,7 @@ template <class Devector> void test_push_back()
template <class Devector> void test_push_back_rvalue_throwing(dtl::true_)
{
#ifndef BOOST_NO_EXCEPTIONS
typedef typename Devector::value_type T;
typedef typename Devector::iterator iterator;
@ -2143,6 +2191,7 @@ template <class Devector> void test_push_back_rvalue_throwing(dtl::true_)
BOOST_TEST(origi_begin == new_begin);
BOOST_TEST(b.size() == 4u);
#endif //#ifndef BOOST_NO_EXCEPTIONS
}
template <class Devector> void test_push_back_rvalue_throwing(dtl::false_)
@ -2189,6 +2238,7 @@ template <class Devector> void test_unsafe_push_front()
test_equal_range(a, expected);
}
#ifndef BOOST_NO_EXCEPTIONS
if (! boost::move_detail::is_nothrow_copy_constructible<T>::value)
{
Devector b; get_range<Devector>(4, b);
@ -2206,6 +2256,7 @@ template <class Devector> void test_unsafe_push_front()
BOOST_TEST(origi_begin == new_begin);
BOOST_TEST(b.size() == 4u);
}
#endif //#ifndef BOOST_NO_EXCEPTIONS
}
template <class Devector> void test_unsafe_push_front_rvalue()
@ -2248,6 +2299,7 @@ template <class Devector> void test_unsafe_push_back()
test_equal_range(a, expected);
}
#ifndef BOOST_NO_EXCEPTIONS
if (! boost::move_detail::is_nothrow_copy_constructible<T>::value)
{
Devector b; get_range<Devector>(4, b);
@ -2265,6 +2317,7 @@ template <class Devector> void test_unsafe_push_back()
BOOST_TEST(origi_begin == new_begin);
BOOST_TEST(b.size() == 4u);
}
#endif
}
template <class Devector> void test_unsafe_push_back_rvalue()
@ -2320,6 +2373,7 @@ template <class Devector> void test_pop_back()
template <class Devector> void test_emplace_throwing(dtl::true_)
{
#ifndef BOOST_NO_EXCEPTIONS
typedef typename Devector::iterator iterator;
Devector j; get_range<Devector>(4, j);
@ -2332,6 +2386,7 @@ template <class Devector> void test_emplace_throwing(dtl::true_)
const int expected[] = {1, 2, 3, 4};
test_equal_range(j, expected);
BOOST_TEST(origi_begin == j.begin());
#endif
}
template <class Devector> void test_emplace_throwing(dtl::false_)
@ -2340,7 +2395,6 @@ template <class Devector> void test_emplace_throwing(dtl::false_)
template <class Devector> void test_emplace()
{
typedef typename Devector::value_type T;
typedef typename Devector::iterator iterator;
{
@ -2433,12 +2487,14 @@ template <class Devector> void test_emplace()
test_equal_range(i, expected);
}
typedef typename Devector::value_type T;
test_emplace_throwing<Devector>
(dtl::bool_<! boost::move_detail::is_nothrow_default_constructible<T>::value>());
}
template <class Devector> void test_insert_throwing(dtl::true_)
{
#ifndef BOOST_NO_EXCEPTIONS
typedef typename Devector::value_type T;
typedef typename Devector::iterator iterator;
@ -2454,6 +2510,7 @@ template <class Devector> void test_insert_throwing(dtl::true_)
const int expected[] = {1, 2, 3, 4};
test_equal_range(j, expected);
BOOST_TEST(origi_begin == j.begin());
#endif //#ifndef BOOST_NO_EXCEPTIONS
}
template <class Devector> void test_insert_throwing(dtl::false_)
@ -2581,6 +2638,7 @@ template <class Devector> void test_insert()
template <class Devector> void test_insert_rvalue_throwing(dtl::true_)
{
#ifndef BOOST_NO_EXCEPTIONS
typedef typename Devector::value_type T;
typedef typename Devector::iterator iterator;
@ -2594,6 +2652,7 @@ template <class Devector> void test_insert_rvalue_throwing(dtl::true_)
const int expected[] = {1, 2, 3, 4};
test_equal_range(j, expected);
BOOST_TEST(origi_begin == j.begin());
#endif //#ifndef BOOST_NO_EXCEPTIONS
}
template <class Devector> void test_insert_rvalue_throwing(dtl::false_)
@ -2701,6 +2760,7 @@ template <class Devector> void test_insert_rvalue()
template <class Devector> void test_insert_n_throwing(dtl::true_)
{
#ifndef BOOST_NO_EXCEPTIONS
typedef typename Devector::value_type T;
// insert at begin
{
@ -2723,6 +2783,7 @@ template <class Devector> void test_insert_n_throwing(dtl::true_)
BOOST_TEST_THROWS(k.insert(k.end(), 4, x), test_exception);
test_elem_throw::do_not_throw();
}
#endif //#ifndef BOOST_NO_EXCEPTIONS
}
template <class Devector> void test_insert_n_throwing(dtl::false_)
@ -3049,6 +3110,7 @@ template <class Devector> void test_insert_input_range()
test_equal_range(h, expected);
}
#ifndef BOOST_NO_EXCEPTIONS
if (! boost::move_detail::is_nothrow_copy_constructible<T>::value)
{
// insert at begin
@ -3079,6 +3141,7 @@ template <class Devector> void test_insert_input_range()
test_elem_throw::do_not_throw();
}
}
#endif //#ifndef BOOST_NO_EXCEPTIONS
}
template <class Devector> void test_insert_range()
@ -3221,6 +3284,7 @@ template <class Devector> void test_insert_range()
BOOST_TEST(h.get_alloc_count() == 0u);
}
#ifndef BOOST_NO_EXCEPTIONS
if (! boost::move_detail::is_nothrow_copy_constructible<T>::value)
{
// insert at begin
@ -3241,6 +3305,7 @@ template <class Devector> void test_insert_range()
test_elem_throw::do_not_throw();
}
}
#endif //#ifndef BOOST_NO_EXCEPTIONS
}
template <class Devector> void test_insert_init_list()
@ -3342,6 +3407,7 @@ template <class Devector> void test_insert_init_list()
BOOST_TEST(ret == g.begin() + 2);
}
#ifndef BOOST_NO_EXCEPTIONS
BOOST_IF_CONSTEXPR (! boost::move_detail::is_nothrow_copy_constructible<T>::value)
{
// insert at begin
@ -3361,6 +3427,7 @@ template <class Devector> void test_insert_init_list()
test_elem_throw::do_not_throw();
}
}
#endif //#ifndef BOOST_NO_EXCEPTIONS
#endif // #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
}

View File

@ -86,20 +86,23 @@ void test_null_memory_resource()
{
//Make sure it throw or returns null
memory_resource *mr = null_memory_resource();
BOOST_TEST(mr != 0);
#if !defined(BOOST_NO_EXCEPTIONS)
bool bad_allocexception_thrown = false;
try{
BOOST_TRY{
mr->allocate(1, 1);
}
catch(std::bad_alloc&) {
BOOST_CATCH(std::bad_alloc&) {
bad_allocexception_thrown = true;
}
catch(...) {
BOOST_CATCH(...) {
}
BOOST_CATCH_END
BOOST_TEST(bad_allocexception_thrown == true);
#else
BOOST_TEST(0 == mr->allocate(1, 1));
#endif
#endif //BOOST_NO_EXCEPTIONS
}
void test_default_resource()

View File

@ -13,6 +13,7 @@
#include <boost/container/pmr/memory_resource.hpp>
#include <boost/container/vector.hpp>
#include <boost/container/throw_exception.hpp>
#include <cstdlib>
class memory_resource_logger
@ -41,7 +42,7 @@ class memory_resource_logger
{
char *addr =(char*)std::malloc(bytes);
if(!addr){
throw std::bad_alloc();
boost::container::throw_bad_alloc();
}
allocation_info info;
info.address = addr;

View File

@ -10,8 +10,10 @@
#define BOOST_ENABLE_ASSERT_HANDLER
#include <boost/container/static_vector.hpp>
#include <boost/core/lightweight_test.hpp>
#include <boost/core/no_exceptions_support.hpp>
#include <new> //for bad_alloc
#include <boost/assert.hpp>
#include <cstdlib>
using namespace boost::container;
//User-defined assertion to test throw_on_overflow
@ -21,12 +23,20 @@ struct throw_on_overflow_off
namespace boost {
void assertion_failed(char const *, char const *, char const *, long)
{
#ifdef BOOST_NO_EXCEPTIONS
std::abort();
#else
throw throw_on_overflow_off();
#endif
}
void assertion_failed_msg(char const *, char const *, char const *, char const *, long )
{
#ifdef BOOST_NO_EXCEPTIONS
std::abort();
#else
throw throw_on_overflow_off();
#endif
}
}
@ -76,15 +86,18 @@ void test_throw_on_overflow()
v.resize(Capacity);
bool expected_type_thrown = false;
try{
BOOST_TRY{
v.push_back(0);
}
catch(std::bad_alloc&)
BOOST_CATCH(std::bad_alloc&)
{
expected_type_thrown = true;
}
catch(...)
BOOST_CATCH(...)
{}
BOOST_CATCH_END
BOOST_TEST(expected_type_thrown == true);
BOOST_TEST(v.capacity() == Capacity);
}
@ -101,15 +114,18 @@ void test_throw_on_overflow()
v.resize(Capacity);
bool expected_type_thrown = false;
try{
BOOST_TRY{
v.push_back(0);
}
catch(throw_on_overflow_off)
BOOST_CATCH(throw_on_overflow_off)
{
expected_type_thrown = true;
}
catch(...)
BOOST_CATCH(...)
{}
BOOST_CATCH_END
BOOST_TEST(expected_type_thrown == true);
BOOST_TEST(v.capacity() == Capacity);
}

View File

@ -75,12 +75,12 @@ void test_support_for_initializer_list()
{
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
{
static_vector<int, 2> sv = {10, 8};
typedef static_vector<int, 2> sv_cap_2;
sv_cap_2 sv = {10, 8};
BOOST_TEST(10 == sv[0]);
BOOST_TEST(8 == sv[1]);
typedef static_vector<int, 1> sv_cap_1;
BOOST_TEST_THROWS(sv_cap_1({1, 1}), std::bad_alloc);
BOOST_TEST_THROWS(sv_cap_2({1, 1, 1}), std::bad_alloc);
}
{
@ -160,15 +160,15 @@ void test_push_back_nd()
for ( size_t i = 0 ; i < N ; ++i )
{
T t(i);
T t(static_cast<int>(i));
s.push_back(t);
BOOST_TEST(s.size() == i + 1);
BOOST_TEST_THROWS( s.at(i + 1), std::out_of_range );
BOOST_TEST(T(i) == s.at(i));
BOOST_TEST(T(i) == s[i]);
BOOST_TEST(T(i) == s.back());
BOOST_TEST(T((int)i) == s.at(i));
BOOST_TEST(T((int)i) == s[i]);
BOOST_TEST(T((int)i) == s.back());
BOOST_TEST(T(0) == s.front());
BOOST_TEST(T(i) == *(s.data() + i));
BOOST_TEST(T((int)i) == *(s.data() + i));
}
}
@ -179,7 +179,7 @@ void test_pop_back_nd()
for ( size_t i = 0 ; i < N ; ++i )
{
T t(i);
T t((int)i);
s.push_back(t);
}
@ -188,9 +188,9 @@ void test_pop_back_nd()
s.pop_back();
BOOST_TEST(s.size() == i - 1);
BOOST_TEST_THROWS( s.at(i - 1), std::out_of_range );
BOOST_TEST(T(i - 2) == s.at(i - 2));
BOOST_TEST(T(i - 2) == s[i - 2]);
BOOST_TEST(T(i - 2) == s.back());
BOOST_TEST(T((int)i - 2) == s.at(i - 2));
BOOST_TEST(T((int)i - 2) == s[i - 2]);
BOOST_TEST(T((int)i - 2) == s.back());
BOOST_TEST(T(0) == s.front());
}
}
@ -229,7 +229,7 @@ void test_copy_and_assign_nd(T const& val)
for ( size_t i = 0 ; i < N ; ++i )
{
T t(i);
T t((int)i);
s.push_back(t);
v.push_back(t);
l.push_back(t);
@ -272,8 +272,8 @@ void test_iterators_nd()
for ( size_t i = 0 ; i < N ; ++i )
{
s.push_back(T(i));
v.push_back(T(i));
s.push_back(T((int)i));
v.push_back(T((int)i));
}
test_compare_ranges(s.begin(), s.end(), v.begin(), v.end());
@ -292,7 +292,7 @@ void test_erase_nd()
typedef typename static_vector<T, N>::iterator It;
for ( size_t i = 0 ; i < N ; ++i )
s.push_back(T(i));
s.push_back(T((int)i));
// erase(pos)
{
@ -303,9 +303,9 @@ void test_erase_nd()
BOOST_TEST(s1.begin() + i == it);
BOOST_TEST(s1.size() == N - 1);
for ( size_t j = 0 ; j < i ; ++j )
BOOST_TEST(s1[j] == T(j));
BOOST_TEST(s1[j] == T((int)j));
for ( size_t j = i+1 ; j < N ; ++j )
BOOST_TEST(s1[j-1] == T(j));
BOOST_TEST(s1[j-1] == T((int)j));
}
}
// erase(first, last)
@ -319,9 +319,9 @@ void test_erase_nd()
BOOST_TEST(s1.begin() + i == it);
BOOST_TEST(s1.size() == N - removed);
for ( size_t j = 0 ; j < i ; ++j )
BOOST_TEST(s1[j] == T(j));
BOOST_TEST(s1[j] == T((int)j));
for ( size_t j = i+n ; j < N ; ++j )
BOOST_TEST(s1[j-n] == T(j));
BOOST_TEST(s1[j-n] == T((int)j));
}
}
}
@ -344,11 +344,11 @@ void test_insert(SV const& s, C const& c)
BOOST_TEST(s1.begin() + i == it1);
BOOST_TEST(s1.size() == h+n);
for ( size_t j = 0 ; j < i ; ++j )
BOOST_TEST(s1[j] == T(j));
BOOST_TEST(s1[j] == T((int)j));
for ( size_t j = 0 ; j < n ; ++j )
BOOST_TEST(s1[j+i] == T(100 + j));
BOOST_TEST(s1[j+i] == T(100 + (int)j));
for ( size_t j = 0 ; j < h-i ; ++j )
BOOST_TEST(s1[j+i+n] == T(j+i));
BOOST_TEST(s1[j+i+n] == T((int)j+(int)i));
}
}
@ -365,10 +365,10 @@ void test_insert_nd(T const& val)
for ( size_t i = 0 ; i < h ; ++i )
{
s.push_back(T(i));
ss.push_back(T(100 + i));
v.push_back(T(100 + i));
l.push_back(T(100 + i));
s.push_back(T((int)i));
ss.push_back(T(100 + (int)i));
v.push_back(T(100 + (int)i));
l.push_back(T(100 + (int)i));
}
// insert(pos, val)
@ -380,10 +380,10 @@ void test_insert_nd(T const& val)
BOOST_TEST(s1.begin() + i == it);
BOOST_TEST(s1.size() == h+1);
for ( size_t j = 0 ; j < i ; ++j )
BOOST_TEST(s1[j] == T(j));
BOOST_TEST(s1[j] == T((int)j));
BOOST_TEST(s1[i] == val);
for ( size_t j = 0 ; j < h-i ; ++j )
BOOST_TEST(s1[j+i+1] == T(j+i));
BOOST_TEST(s1[j+i+1] == T((int)j+(int)i));
}
}
// insert(pos, n, val)
@ -396,11 +396,11 @@ void test_insert_nd(T const& val)
BOOST_TEST(s1.begin() + i == it);
BOOST_TEST(s1.size() == h+n);
for ( size_t j = 0 ; j < i ; ++j )
BOOST_TEST(s1[j] == T(j));
BOOST_TEST(s1[j] == T((int)j));
for ( size_t j = 0 ; j < n ; ++j )
BOOST_TEST(s1[j+i] == val);
for ( size_t j = 0 ; j < h-i ; ++j )
BOOST_TEST(s1[j+i+n] == T(j+i));
BOOST_TEST(s1[j+i+n] == T((int)j+(int)i));
}
}
// insert(pos, first, last)
@ -414,7 +414,8 @@ void test_capacity_0_nd()
{
static_vector<T, 10> v(5u, T(0));
static_vector<T, 0 > s;
typedef static_vector<T, 0> static_vector_0_t;
static_vector_0_t s;
BOOST_TEST(s.size() == 0);
BOOST_TEST(s.capacity() == 0);
BOOST_TEST_THROWS(s.at(0), std::out_of_range);
@ -426,7 +427,6 @@ void test_capacity_0_nd()
BOOST_TEST_THROWS(s.assign(v.begin(), v.end()), std::bad_alloc);
BOOST_TEST_THROWS(s.assign(5u, T(0)), std::bad_alloc);
BOOST_TEST_THROWS(s.assign(5u, T(0)), std::bad_alloc);
typedef static_vector<T, 0> static_vector_0_t;
BOOST_TEST_THROWS(static_vector_0_t s2(v.begin(), v.end()), std::bad_alloc);
BOOST_TEST_THROWS(static_vector_0_t s1(5u, T(0)), std::bad_alloc);
}
@ -435,7 +435,8 @@ template <typename T, size_t N>
void test_exceptions_nd()
{
static_vector<T, N> v(N, T(0));
static_vector<T, N/2> s(N/2, T(0));
typedef static_vector<T, N/2> static_vector_n_half_t;
static_vector_n_half_t s(N/2, T(0));
BOOST_TEST_THROWS(s.resize(N, T(0)), std::bad_alloc);
BOOST_TEST_THROWS(s.push_back(T(0)), std::bad_alloc);
@ -444,7 +445,6 @@ void test_exceptions_nd()
BOOST_TEST_THROWS(s.insert(s.end(), v.begin(), v.end()), std::bad_alloc);
BOOST_TEST_THROWS(s.assign(v.begin(), v.end()), std::bad_alloc);
BOOST_TEST_THROWS(s.assign(N, T(0)), std::bad_alloc);
typedef static_vector<T, N/2> static_vector_n_half_t;
BOOST_TEST_THROWS(static_vector_n_half_t s2(v.begin(), v.end()), std::bad_alloc);
BOOST_TEST_THROWS(static_vector_n_half_t s1(N/2+1, T(0)), std::bad_alloc);
}
@ -459,16 +459,16 @@ void test_swap_and_move_nd()
for (size_t i = 0 ; i < N ; ++i )
{
v1.push_back(T(i));
v2.push_back(T(i));
v3.push_back(T(i));
v4.push_back(T(i));
v1.push_back(T((int)i));
v2.push_back(T((int)i));
v3.push_back(T((int)i));
v4.push_back(T((int)i));
}
for (size_t i = 0 ; i < N/2 ; ++i )
{
s1.push_back(T(100 + i));
s2.push_back(T(100 + i));
s4.push_back(T(100 + i));
s1.push_back(T(100 + (int)i));
s2.push_back(T(100 + (int)i));
s4.push_back(T(100 + (int)i));
}
s1.swap(v1);
@ -486,15 +486,15 @@ void test_swap_and_move_nd()
BOOST_TEST(s4.size() == N);
for (size_t i = 0 ; i < N/2 ; ++i )
{
BOOST_TEST(v1[i] == T(100 + i));
BOOST_TEST(v4[i] == T(100 + i));
BOOST_TEST(v1[i] == T(100 + (int)i));
BOOST_TEST(v4[i] == T(100 + (int)i));
}
for (size_t i = 0 ; i < N ; ++i )
{
BOOST_TEST(s1[i] == T(i));
BOOST_TEST(s2[i] == T(i));
BOOST_TEST(s3[i] == T(i));
BOOST_TEST(s4[i] == T(i));
BOOST_TEST(s1[i] == T((int)i));
BOOST_TEST(s2[i] == T((int)i));
BOOST_TEST(s3[i] == T((int)i));
BOOST_TEST(s4[i] == T((int)i));
}
}
{
@ -503,14 +503,14 @@ void test_swap_and_move_nd()
for (size_t i = 0 ; i < N/2 ; ++i )
{
v1.push_back(T(i));
v2.push_back(T(i));
v3.push_back(T(i));
v1.push_back(T((int)i));
v2.push_back(T((int)i));
v3.push_back(T((int)i));
}
for (size_t i = 0 ; i < N/3 ; ++i )
{
s1.push_back(T(100 + i));
s2.push_back(T(100 + i));
s1.push_back(T(100 + (int)i));
s2.push_back(T(100 + (int)i));
}
s1.swap(v1);
@ -528,13 +528,13 @@ void test_swap_and_move_nd()
//BOOST_TEST(v3.size() == 0);
BOOST_TEST(s4.size() == N/2);
for (size_t i = 0 ; i < N/3 ; ++i )
BOOST_TEST(v1[i] == T(100 + i));
BOOST_TEST(v1[i] == T(100 + (int)i));
for (size_t i = 0 ; i < N/2 ; ++i )
{
BOOST_TEST(s1[i] == T(i));
BOOST_TEST(s2[i] == T(i));
BOOST_TEST(s3[i] == T(i));
BOOST_TEST(s4[i] == T(i));
BOOST_TEST(s1[i] == T((int)i));
BOOST_TEST(s2[i] == T((int)i));
BOOST_TEST(s3[i] == T((int)i));
BOOST_TEST(s4[i] == T((int)i));
}
}
{
@ -574,7 +574,7 @@ void test_emplace_2p()
for (int i = 0 ; i < int(N) ; ++i )
v.emplace_back(i, 100 + i);
BOOST_TEST(v.size() == N);
BOOST_TEST_THROWS(v.emplace_back(N, 100 + N), std::bad_alloc);
BOOST_TEST_THROWS(v.emplace_back((int)N, 100 + (int)N), std::bad_alloc);
BOOST_TEST(v.size() == N);
for (int i = 0 ; i < int(N) ; ++i )
BOOST_TEST(v[i] == T(i, 100 + i));
@ -681,98 +681,84 @@ int main(int, char* [])
test_ctor_ndc<value_ndc, 10>();
test_ctor_ndc<counting_value, 10>();
BOOST_TEST(counting_value::count() == 0);
test_ctor_ndc<shptr_value, 10>();
test_ctor_ndc<movable_and_copyable_int, 10>();
test_ctor_nc<int, 10>(5);
test_ctor_nc<value_nc, 10>(5);
test_ctor_nc<counting_value, 10>(5);
BOOST_TEST(counting_value::count() == 0);
test_ctor_nc<shptr_value, 10>(5);
test_ctor_nc<movable_and_copyable_int, 10>(5);
test_ctor_nd<int, 10>(5, 1);
test_ctor_nd<value_nd, 10>(5, value_nd(1));
test_ctor_nd<counting_value, 10>(5, counting_value(1));
BOOST_TEST(counting_value::count() == 0);
test_ctor_nd<shptr_value, 10>(5, shptr_value(1));
test_ctor_nd<movable_and_copyable_int, 10>(5, produce_movable_and_copyable_int());
test_resize_nc<int, 10>(5);
test_resize_nc<value_nc, 10>(5);
test_resize_nc<counting_value, 10>(5);
BOOST_TEST(counting_value::count() == 0);
test_resize_nc<shptr_value, 10>(5);
test_resize_nc<movable_and_copyable_int, 10>(5);
test_resize_nd<int, 10>(5, 1);
test_resize_nd<value_nd, 10>(5, value_nd(1));
test_resize_nd<counting_value, 10>(5, counting_value(1));
BOOST_TEST(counting_value::count() == 0);
test_resize_nd<shptr_value, 10>(5, shptr_value(1));
test_resize_nd<movable_and_copyable_int, 10>(5, produce_movable_and_copyable_int());
test_push_back_nd<int, 10>();
test_push_back_nd<value_nd, 10>();
test_push_back_nd<counting_value, 10>();
BOOST_TEST(counting_value::count() == 0);
test_push_back_nd<shptr_value, 10>();
test_push_back_nd<movable_and_copyable_int, 10>();
test_pop_back_nd<int, 10>();
test_pop_back_nd<value_nd, 10>();
test_pop_back_nd<counting_value, 10>();
BOOST_TEST(counting_value::count() == 0);
test_pop_back_nd<shptr_value, 10>();
test_pop_back_nd<movable_and_copyable_int, 10>();
test_copy_and_assign_nd<int, 10>(1);
test_copy_and_assign_nd<value_nd, 10>(value_nd(1));
test_copy_and_assign_nd<counting_value, 10>(counting_value(1));
BOOST_TEST(counting_value::count() == 0);
test_copy_and_assign_nd<shptr_value, 10>(shptr_value(1));
test_copy_and_assign_nd<movable_and_copyable_int, 10>(produce_movable_and_copyable_int());
test_iterators_nd<int, 10>();
test_iterators_nd<value_nd, 10>();
test_iterators_nd<counting_value, 10>();
BOOST_TEST(counting_value::count() == 0);
test_iterators_nd<shptr_value, 10>();
test_iterators_nd<movable_and_copyable_int, 10>();
test_erase_nd<int, 10>();
test_erase_nd<value_nd, 10>();
test_erase_nd<counting_value, 10>();
BOOST_TEST(counting_value::count() == 0);
test_erase_nd<shptr_value, 10>();
test_erase_nd<movable_and_copyable_int, 10>();
test_insert_nd<int, 10>(50);
test_insert_nd<value_nd, 10>(value_nd(50));
test_insert_nd<counting_value, 10>(counting_value(50));
BOOST_TEST(counting_value::count() == 0);
test_insert_nd<shptr_value, 10>(shptr_value(50));
test_insert_nd<movable_and_copyable_int, 10>(produce_movable_and_copyable_int());
test_capacity_0_nd<int>();
test_capacity_0_nd<value_nd>();
test_capacity_0_nd<counting_value>();
BOOST_TEST(counting_value::count() == 0);
test_capacity_0_nd<shptr_value>();
test_capacity_0_nd<movable_and_copyable_int>();
test_exceptions_nd<int, 10>();
test_exceptions_nd<value_nd, 10>();
test_exceptions_nd<counting_value, 10>();
BOOST_TEST(counting_value::count() == 0);
test_exceptions_nd<shptr_value, 10>();
test_exceptions_nd<movable_and_copyable_int, 10>();
test_swap_and_move_nd<int, 10>();
test_swap_and_move_nd<value_nd, 10>();
test_swap_and_move_nd<counting_value, 10>();
BOOST_TEST(counting_value::count() == 0);
test_swap_and_move_nd<shptr_value, 10>();
test_swap_and_move_nd<movable_and_copyable_int, 10>();
test_emplace_0p<counting_value, 10>();
@ -785,7 +771,6 @@ int main(int, char* [])
test_sv_elem<value_nd, 10>(value_nd(50));
test_sv_elem<counting_value, 10>(counting_value(50));
BOOST_TEST(counting_value::count() == 0);
test_sv_elem<shptr_value, 10>(shptr_value(50));
test_sv_elem<movable_and_copyable_int, 10>(movable_and_copyable_int(50));
BOOST_TEST(default_init_test() == true);

View File

@ -13,8 +13,6 @@
#include <boost/container/static_vector.hpp>
#define BOOST_SP_DISABLE_THREADS
#include <boost/shared_ptr.hpp>
#include "movable_int.hpp"
using namespace boost::container;
@ -91,18 +89,4 @@ struct has_nothrow_move<counting_value>
}
class shptr_value
{
typedef boost::shared_ptr<int> Ptr;
public:
explicit shptr_value(int a = 0) : m_ptr(new int(a)) {}
shptr_value & operator=(int a)
{ m_ptr.reset(new int(a)); return *this; }
bool operator==(shptr_value const& v) const { return *m_ptr == *(v.m_ptr); }
bool operator<(shptr_value const& v) const { return *m_ptr < *(v.m_ptr); }
private:
boost::shared_ptr<int> m_ptr;
};
#endif // BOOST_CONTAINER_TEST_STATIC_VECTOR_TEST_HPP

View File

@ -13,6 +13,7 @@
#define BOOST_CONTAINER_TEST_TEST_ELEM_HPP
#include <boost/utility/compare_pointees.hpp>
#include <cstdlib>
namespace boost {
namespace container {
@ -51,7 +52,11 @@ struct test_elem_throw
if (counter == 0)
{
--counter;
#ifndef BOOST_NO_EXCEPTIONS
throw test_exception();
#else
std::abort();
#endif
}
}
}

View File

@ -17,6 +17,7 @@ using namespace boost::container;
template<class Unsigned, class VectorType>
void test_stored_size_type_impl()
{
#ifndef BOOST_NO_EXCEPTIONS
VectorType v;
typedef typename VectorType::size_type size_type;
typedef typename VectorType::value_type value_type;
@ -29,6 +30,7 @@ void test_stored_size_type_impl()
BOOST_TEST_THROWS(v.emplace(v.begin(), value_type(1)),std::exception);
BOOST_TEST_THROWS(v.reserve(max+1), std::exception);
BOOST_TEST_THROWS(VectorType v2(max+1), std::exception);
#endif
}
template<class Unsigned>