Merge changes for 1.54

[SVN r84342]
This commit is contained in:
Ion Gaztañaga
2013-05-18 10:52:46 +00:00
49 changed files with 6016 additions and 733 deletions

34
bench/Jamfile.v2 Normal file
View File

@@ -0,0 +1,34 @@
# Boost Container Library Test Jamfile
# (C) Copyright Ion Gaztanaga 2009.
# Use, modification and distribution are subject to the
# Boost Software License, Version 1.0. (See accompanying file
# LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
# Adapted from John Maddock's TR1 Jamfile.v2
# Copyright John Maddock 2005.
# Use, modification and distribution are subject to the
# Boost Software License, Version 1.0. (See accompanying file
# LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
# this rule enumerates through all the sources and invokes
# the run rule for each source, the result is a list of all
# the run rules, which we can pass on to the test_suite rule:
rule test_all
{
local all_rules = ;
for local fileb in [ glob *.cpp ]
{
all_rules += [ run $(fileb) /boost/timer//boost_timer /boost/system//boost_system /boost/thread//boost_thread
: # additional args
: # test-files
: # requirements
] ;
}
return $(all_rules) ;
}
test-suite container_test : [ test_all r ] ;

View File

@@ -0,0 +1,146 @@
// benchmark based on: http://cpp-next.com/archive/2010/10/howards-stl-move-semantics-benchmark/
//
// @file bench_static_vector.cpp
// @date Aug 14, 2011
// @author Andrew Hundt <ATHundt@gmail.com>
//
// (C) 2011-2012 Andrew Hundt <ATHundt@gmail.com>
// (C) 2013 Ion Gaztanaga
//
// 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)
//
// @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 "../test/movable_int.hpp"
#include <vector>
#include <iostream>
#include <boost/timer/timer.hpp>
#include <set>
#include <algorithm>
#include <exception>
using boost::timer::cpu_timer;
using boost::timer::cpu_times;
using boost::timer::nanosecond_type;
#ifdef NDEBUG
static const std::size_t N = 1000;
#else
static const std::size_t N = 100;
#endif
//#define BENCH_SIMPLE_CONSTRUCTION
//#define BENCH_TRIVIAL_TYPE
#ifdef BENCH_TRIVIAL_TYPE
typedef std::size_t basic_type_t;
#else
typedef boost::container::test::copyable_int basic_type_t;
#endif
template<typename T>
T &get_set(std::size_t)
{
#ifdef BENCH_SIMPLE_CONSTRUCTION
T &t = *new T(N);
for (std::size_t i = 0; i < N; ++i)
t[i] = basic_type_t(std::rand());
#else
T &t = *new T;
t.reserve(N);
for (std::size_t i = 0; i < N; ++i)
t.push_back(basic_type_t(std::rand()));
#endif
return t;
}
template<typename T>
T &generate()
{
T &v = *new T;
v.reserve(N);
for (std::size_t i = 0; i < N; ++i){
typename T::reference r = get_set<typename T::value_type>(i);
v.push_back(boost::move(r));
delete &r;
}
return v;
}
template<typename T>
cpu_times time_it()
{
cpu_timer sortTime,rotateTime,destructionTime;
sortTime.stop();rotateTime.stop();destructionTime.stop();
cpu_timer totalTime, constructTime;
std::srand (0);
for(std::size_t i = 0; i< N; ++i){
constructTime.resume();
{
T &v = generate<T>();
constructTime.stop();
sortTime.resume();
std::sort(v.begin(), v.end());
sortTime.stop();
rotateTime.resume();
std::rotate(v.begin(), v.begin() + v.size()/2, v.end());
rotateTime.stop();
destructionTime.resume();
delete &v;
}
destructionTime.stop();
}
totalTime.stop();
std::cout << " construction took " << boost::timer::format(constructTime.elapsed());
std::cout << " sort took " << boost::timer::format(sortTime.elapsed());
std::cout << " rotate took " << boost::timer::format(rotateTime.elapsed());
std::cout << " destruction took " << boost::timer::format(destructionTime.elapsed());
std::cout << " Total time = " << boost::timer::format(totalTime.elapsed()) << std::endl;
return totalTime.elapsed();
}
void compare_times(cpu_times time_numerator, cpu_times time_denominator){
std::cout
<< "\n wall = " << ((double)time_numerator.wall/(double)time_denominator.wall)
<< "\n user = " << ((double)time_numerator.user/(double)time_denominator.user)
<< "\n system = " << ((double)time_numerator.system/(double)time_denominator.system)
<< "\n (user+system) = " << ((double)(time_numerator.system+time_numerator.user)/(double)(time_denominator.system+time_denominator.user)) << "\n\n";
}
int main()
{
try {
std::cout << "N = " << N << "\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::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 << "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/std::vector total time comparison:";
compare_times(time_varray,time_standard_vector);
}catch(std::exception e){
std::cout << e.what();
}
return 1;
}

2274
bench/detail/varray.hpp Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,60 @@
// Boost.Container varray
//
// Copyright (c) 2012-2013 Andrew Hundt.
// Copyright (c) 2012-2013 Adam Wulkiewicz, Lodz, Poland.
//
// Use, modification and distribution is subject to the Boost Software License,
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_CONTAINER_VARRAY_CONCEPT_HPP
#define BOOST_CONTAINER_VARRAY_CONCEPT_HPP
#include <boost/concept_check.hpp>
namespace boost { namespace container { namespace container_detail { namespace concept {
/**
* VArrayStrategyConcept
*
* \brief Checks strategy for varray<Value,Capacity,Strategy>, which has similarities to std::Allocator
* \ingroup varray
*/
template<typename Strategy>
struct VArrayStrategy {
#ifndef DOXYGEN_NO_CONCEPT_MEMBERS
// typedefs are the same as in std::Allocator
typedef typename Strategy::value_type value_type;
typedef typename Strategy::size_type size_type;
typedef typename Strategy::difference_type difference_type;
typedef typename Strategy::pointer pointer;
typedef typename Strategy::const_pointer const_pointer;
typedef typename Strategy::reference reference;
typedef typename Strategy::const_reference const_reference;
struct check_methods
{
static void apply()
{
Strategy const* str = 0;
// must implement allocate_failed
str->allocate_failed();
boost::ignore_unused_variable_warning(str);
}
};
public :
BOOST_CONCEPT_USAGE(VArrayStrategy)
{
check_methods::apply();
}
#endif
};
}}}} // namespace boost::container::container_detail::concept
#endif //BOOST_CONTAINER_VARRAY_CONCEPT_HPP

View File

@@ -0,0 +1,712 @@
// Boost.Container
//
// varray details
//
// Copyright (c) 2012-2013 Adam Wulkiewicz, Lodz, Poland.
// Copyright (c) 2011-2013 Andrew Hundt.
//
// Use, modification and distribution is subject to the Boost Software License,
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_CONTAINER_DETAIL_VARRAY_UTIL_HPP
#define BOOST_CONTAINER_DETAIL_VARRAY_UTIL_HPP
#include <cstddef>
#include <cstring>
#include <memory>
#include <limits>
#include <boost/mpl/if.hpp>
#include <boost/mpl/and.hpp>
#include <boost/mpl/or.hpp>
#include <boost/mpl/int.hpp>
#include <boost/type_traits/is_same.hpp>
#include <boost/type_traits/remove_const.hpp>
#include <boost/type_traits/remove_reference.hpp>
#include <boost/type_traits/has_trivial_assign.hpp>
#include <boost/type_traits/has_trivial_copy.hpp>
#include <boost/type_traits/has_trivial_constructor.hpp>
#include <boost/type_traits/has_trivial_destructor.hpp>
//#include <boost/type_traits/has_nothrow_constructor.hpp>
//#include <boost/type_traits/has_nothrow_copy.hpp>
//#include <boost/type_traits/has_nothrow_assign.hpp>
//#include <boost/type_traits/has_nothrow_destructor.hpp>
#include <boost/detail/no_exceptions_support.hpp>
#include <boost/config.hpp>
#include <boost/move/move.hpp>
#include <boost/utility/addressof.hpp>
#include <boost/iterator/iterator_traits.hpp>
// TODO - move vectors iterators optimization to the other, optional file instead of checking defines?
#if defined(BOOST_CONTAINER_VARRAY_ENABLE_VECTORS_OPTIMIZATION) && !defined(BOOST_NO_EXCEPTIONS)
#include <vector>
#include <boost/container/vector.hpp>
#endif // BOOST_CONTAINER_VARRAY_ENABLE_ITERATORS_OPTIMIZATION && !BOOST_NO_EXCEPTIONS
namespace boost { namespace container { namespace varray_detail {
template <typename I>
struct are_elements_contiguous : boost::is_pointer<I>
{};
#if defined(BOOST_CONTAINER_VARRAY_ENABLE_VECTORS_OPTIMIZATION) && !defined(BOOST_NO_EXCEPTIONS)
template <typename Pointer>
struct are_elements_contiguous<
boost::container::container_detail::vector_const_iterator<Pointer>
> : boost::true_type
{};
template <typename Pointer>
struct are_elements_contiguous<
boost::container::container_detail::vector_iterator<Pointer>
> : boost::true_type
{};
#if defined(BOOST_DINKUMWARE_STDLIB)
template <typename T>
struct are_elements_contiguous<
std::_Vector_const_iterator<T>
> : boost::true_type
{};
template <typename T>
struct are_elements_contiguous<
std::_Vector_iterator<T>
> : boost::true_type
{};
#elif defined(BOOST_GNU_STDLIB)
template <typename P, typename T, typename A>
struct are_elements_contiguous<
__gnu_cxx::__normal_iterator<P, std::vector<T, A> >
> : boost::true_type
{};
#elif defined(_LIBCPP_VERSION)
// TODO - test it first
//template <typename P>
//struct are_elements_contiguous<
// __wrap_iter<P>
//> : boost::true_type
//{};
#else // OTHER_STDLIB
// TODO - add other iterators implementations
#endif // STDLIB
#endif // BOOST_CONTAINER_VARRAY_ENABLE_VECTORS_OPTIMIZATION && !BOOST_NO_EXCEPTIONS
}}} // namespace boost::container::varray_detail
namespace boost { namespace container { namespace varray_detail {
template <typename I, typename O>
struct are_corresponding :
::boost::mpl::and_<
::boost::is_same<
::boost::remove_const<
typename ::boost::iterator_value<I>::type
>,
::boost::remove_const<
typename ::boost::iterator_value<O>::type
>
>,
are_elements_contiguous<I>,
are_elements_contiguous<O>
>
{};
template <typename I, typename V>
struct is_corresponding_value :
::boost::is_same<
::boost::remove_const<
typename ::boost::iterator_value<I>::type
>,
::boost::remove_const<V>
>
{};
// destroy(I, I)
template <typename I>
void destroy_dispatch(I /*first*/, I /*last*/,
boost::true_type const& /*has_trivial_destructor*/)
{}
template <typename I>
void destroy_dispatch(I first, I last,
boost::false_type const& /*has_trivial_destructor*/)
{
typedef typename boost::iterator_value<I>::type value_type;
for ( ; first != last ; ++first )
first->~value_type();
}
template <typename I>
void destroy(I first, I last)
{
typedef typename boost::iterator_value<I>::type value_type;
destroy_dispatch(first, last, has_trivial_destructor<value_type>());
}
// destroy(I)
template <typename I>
void destroy_dispatch(I /*pos*/,
boost::true_type const& /*has_trivial_destructor*/)
{}
template <typename I>
void destroy_dispatch(I pos,
boost::false_type const& /*has_trivial_destructor*/)
{
typedef typename boost::iterator_value<I>::type value_type;
pos->~value_type();
}
template <typename I>
void destroy(I pos)
{
typedef typename boost::iterator_value<I>::type value_type;
destroy_dispatch(pos, has_trivial_destructor<value_type>());
}
// copy(I, I, O)
template <typename I, typename O>
inline O copy_dispatch(I first, I last, O dst,
boost::mpl::bool_<true> const& /*use_memmove*/)
{
typedef typename boost::iterator_value<I>::type value_type;
typename boost::iterator_difference<I>::type d = std::distance(first, last);
::memmove(boost::addressof(*dst), boost::addressof(*first), sizeof(value_type) * d);
return dst + d;
}
template <typename I, typename O>
inline O copy_dispatch(I first, I last, O dst,
boost::mpl::bool_<false> const& /*use_memmove*/)
{
return std::copy(first, last, dst); // may throw
}
template <typename I, typename O>
inline O copy(I first, I last, O dst)
{
typedef typename
::boost::mpl::and_<
are_corresponding<I, O>,
::boost::has_trivial_assign<
typename ::boost::iterator_value<O>::type
>
>::type
use_memmove;
return copy_dispatch(first, last, dst, use_memmove()); // may throw
}
// uninitialized_copy(I, I, O)
template <typename I, typename O>
inline
O uninitialized_copy_dispatch(I first, I last, O dst,
boost::mpl::bool_<true> const& /*use_memcpy*/)
{
typedef typename boost::iterator_value<I>::type value_type;
typename boost::iterator_difference<I>::type d = std::distance(first, last);
::memcpy(boost::addressof(*dst), boost::addressof(*first), sizeof(value_type) * d);
return dst + d;
}
template <typename I, typename F>
inline
F uninitialized_copy_dispatch(I first, I last, F dst,
boost::mpl::bool_<false> const& /*use_memcpy*/)
{
return std::uninitialized_copy(first, last, dst); // may throw
}
template <typename I, typename F>
inline
F uninitialized_copy(I first, I last, F dst)
{
typedef typename
::boost::mpl::and_<
are_corresponding<I, F>,
::boost::has_trivial_copy<
typename ::boost::iterator_value<F>::type
>
>::type
use_memcpy;
return uninitialized_copy_dispatch(first, last, dst, use_memcpy()); // may throw
}
// uninitialized_move(I, I, O)
template <typename I, typename O>
inline
O uninitialized_move_dispatch(I first, I last, O dst,
boost::mpl::bool_<true> const& /*use_memcpy*/)
{
typedef typename boost::iterator_value<I>::type value_type;
typename boost::iterator_difference<I>::type d = std::distance(first, last);
::memcpy(boost::addressof(*dst), boost::addressof(*first), sizeof(value_type) * d);
return dst + d;
}
template <typename I, typename O>
inline
O uninitialized_move_dispatch(I first, I last, O dst,
boost::mpl::bool_<false> const& /*use_memcpy*/)
{
//return boost::uninitialized_move(first, last, dst); // may throw
O o = dst;
BOOST_TRY
{
typedef typename std::iterator_traits<O>::value_type value_type;
for (; first != last; ++first, ++o )
new (boost::addressof(*o)) value_type(boost::move(*first));
}
BOOST_CATCH(...)
{
destroy(dst, o);
BOOST_RETHROW;
}
BOOST_CATCH_END
return dst;
}
template <typename I, typename O>
inline
O uninitialized_move(I first, I last, O dst)
{
typedef typename
::boost::mpl::and_<
are_corresponding<I, O>,
::boost::has_trivial_copy<
typename ::boost::iterator_value<O>::type
>
>::type
use_memcpy;
return uninitialized_move_dispatch(first, last, dst, use_memcpy()); // may throw
}
// TODO - move uses memmove - implement 2nd version using memcpy?
// move(I, I, O)
template <typename I, typename O>
inline
O move_dispatch(I first, I last, O dst,
boost::mpl::bool_<true> const& /*use_memmove*/)
{
typedef typename boost::iterator_value<I>::type value_type;
typename boost::iterator_difference<I>::type d = std::distance(first, last);
::memmove(boost::addressof(*dst), boost::addressof(*first), sizeof(value_type) * d);
return dst + d;
}
template <typename I, typename O>
inline
O move_dispatch(I first, I last, O dst,
boost::mpl::bool_<false> const& /*use_memmove*/)
{
return boost::move(first, last, dst); // may throw
}
template <typename I, typename O>
inline
O move(I first, I last, O dst)
{
typedef typename
::boost::mpl::and_<
are_corresponding<I, O>,
::boost::has_trivial_assign<
typename ::boost::iterator_value<O>::type
>
>::type
use_memmove;
return move_dispatch(first, last, dst, use_memmove()); // may throw
}
// move_backward(BDI, BDI, BDO)
template <typename BDI, typename BDO>
inline
BDO move_backward_dispatch(BDI first, BDI last, BDO dst,
boost::mpl::bool_<true> const& /*use_memmove*/)
{
typedef typename boost::iterator_value<BDI>::type value_type;
typename boost::iterator_difference<BDI>::type d = std::distance(first, last);
BDO foo(dst - d);
::memmove(boost::addressof(*foo), boost::addressof(*first), sizeof(value_type) * d);
return foo;
}
template <typename BDI, typename BDO>
inline
BDO move_backward_dispatch(BDI first, BDI last, BDO dst,
boost::mpl::bool_<false> const& /*use_memmove*/)
{
return boost::move_backward(first, last, dst); // may throw
}
template <typename BDI, typename BDO>
inline
BDO move_backward(BDI first, BDI last, BDO dst)
{
typedef typename
::boost::mpl::and_<
are_corresponding<BDI, BDO>,
::boost::has_trivial_assign<
typename ::boost::iterator_value<BDO>::type
>
>::type
use_memmove;
return move_backward_dispatch(first, last, dst, use_memmove()); // may throw
}
template <typename T>
struct has_nothrow_move : public
::boost::mpl::or_<
boost::mpl::bool_<
::boost::has_nothrow_move<
typename ::boost::remove_const<T>::type
>::value
>,
boost::mpl::bool_<
::boost::has_nothrow_move<T>::value
>
>
{};
// uninitialized_move_if_noexcept(I, I, O)
template <typename I, typename O>
inline
O uninitialized_move_if_noexcept_dispatch(I first, I last, O dst, boost::mpl::bool_<true> const& /*use_move*/)
{ return uninitialized_move(first, last, dst); }
template <typename I, typename O>
inline
O uninitialized_move_if_noexcept_dispatch(I first, I last, O dst, boost::mpl::bool_<false> const& /*use_move*/)
{ return uninitialized_copy(first, last, dst); }
template <typename I, typename O>
inline
O uninitialized_move_if_noexcept(I first, I last, O dst)
{
typedef typename has_nothrow_move<
typename ::boost::iterator_value<O>::type
>::type use_move;
return uninitialized_move_if_noexcept_dispatch(first, last, dst, use_move()); // may throw
}
// move_if_noexcept(I, I, O)
template <typename I, typename O>
inline
O move_if_noexcept_dispatch(I first, I last, O dst, boost::mpl::bool_<true> const& /*use_move*/)
{ return move(first, last, dst); }
template <typename I, typename O>
inline
O move_if_noexcept_dispatch(I first, I last, O dst, boost::mpl::bool_<false> const& /*use_move*/)
{ return copy(first, last, dst); }
template <typename I, typename O>
inline
O move_if_noexcept(I first, I last, O dst)
{
typedef typename has_nothrow_move<
typename ::boost::iterator_value<O>::type
>::type use_move;
return move_if_noexcept_dispatch(first, last, dst, use_move()); // may throw
}
// uninitialized_fill(I, I)
template <typename I>
inline
void uninitialized_fill_dispatch(I first, I last,
boost::true_type const& /*has_trivial_constructor*/,
boost::true_type const& /*disable_trivial_init*/)
{}
template <typename I>
inline
void uninitialized_fill_dispatch(I first, I last,
boost::true_type const& /*has_trivial_constructor*/,
boost::false_type const& /*disable_trivial_init*/)
{
typedef typename boost::iterator_value<I>::type value_type;
for ( ; first != last ; ++first )
new (boost::addressof(*first)) value_type();
}
template <typename I, typename DisableTrivialInit>
inline
void uninitialized_fill_dispatch(I first, I last,
boost::false_type const& /*has_trivial_constructor*/,
DisableTrivialInit const& /*not_used*/)
{
typedef typename boost::iterator_value<I>::type value_type;
I it = first;
BOOST_TRY
{
for ( ; it != last ; ++it )
new (boost::addressof(*it)) value_type(); // may throw
}
BOOST_CATCH(...)
{
destroy(first, it);
BOOST_RETHROW;
}
BOOST_CATCH_END
}
template <typename I, typename DisableTrivialInit>
inline
void uninitialized_fill(I first, I last, DisableTrivialInit const& disable_trivial_init)
{
typedef typename boost::iterator_value<I>::type value_type;
uninitialized_fill_dispatch(first, last, boost::has_trivial_constructor<value_type>(), disable_trivial_init); // may throw
}
// construct(I)
template <typename I>
inline
void construct_dispatch(boost::mpl::bool_<true> const& /*dont_init*/, I pos)
{}
template <typename I>
inline
void construct_dispatch(boost::mpl::bool_<false> const& /*dont_init*/, I pos)
{
typedef typename ::boost::iterator_value<I>::type value_type;
new (static_cast<void*>(::boost::addressof(*pos))) value_type(); // may throw
}
template <typename DisableTrivialInit, typename I>
inline
void construct(DisableTrivialInit const&, I pos)
{
typedef typename ::boost::iterator_value<I>::type value_type;
typedef typename ::boost::mpl::and_<
boost::has_trivial_constructor<value_type>,
DisableTrivialInit
>::type dont_init;
construct_dispatch(dont_init(), pos); // may throw
}
// construct(I, V)
template <typename I, typename V>
inline
void construct_dispatch(I pos, V const& v,
boost::mpl::bool_<true> const& /*use_memcpy*/)
{
::memcpy(boost::addressof(*pos), boost::addressof(v), sizeof(V));
}
template <typename I, typename P>
inline
void construct_dispatch(I pos, P const& p,
boost::mpl::bool_<false> const& /*use_memcpy*/)
{
typedef typename boost::iterator_value<I>::type V;
new (static_cast<void*>(boost::addressof(*pos))) V(p); // may throw
}
template <typename DisableTrivialInit, typename I, typename P>
inline
void construct(DisableTrivialInit const&,
I pos, P const& p)
{
typedef typename
::boost::mpl::and_<
is_corresponding_value<I, P>,
::boost::has_trivial_copy<P>
>::type
use_memcpy;
construct_dispatch(pos, p, use_memcpy()); // may throw
}
// Needed by push_back(V &&)
template <typename DisableTrivialInit, typename I, typename P>
inline
void construct(DisableTrivialInit const&, I pos, BOOST_RV_REF(P) p)
{
typedef typename
::boost::mpl::and_<
is_corresponding_value<I, P>,
::boost::has_trivial_copy<P>
>::type
use_memcpy;
typedef typename boost::iterator_value<I>::type V;
new (static_cast<void*>(boost::addressof(*pos))) V(::boost::move(p)); // may throw
}
// Needed by emplace_back() and emplace()
#if !defined(BOOST_CONTAINER_VARRAY_DISABLE_EMPLACE)
#if !defined(BOOST_NO_VARIADIC_TEMPLATES)
template <typename DisableTrivialInit, typename I, class ...Args>
inline
void construct(DisableTrivialInit const&,
I pos,
BOOST_FWD_REF(Args) ...args)
{
typedef typename boost::iterator_value<I>::type V;
new (static_cast<void*>(boost::addressof(*pos))) V(::boost::forward<Args>(args)...); // may throw
}
#else // !BOOST_NO_VARIADIC_TEMPLATES
// BOOST_NO_RVALUE_REFERENCES -> P0 const& p0
// !BOOST_NO_RVALUE_REFERENCES -> P0 && p0
// which means that version with one parameter may take V const& v
#define BOOST_PP_LOCAL_MACRO(n) \
template <typename DisableTrivialInit, typename I, typename P BOOST_PP_ENUM_TRAILING_PARAMS(n, typename P) > \
inline \
void construct(DisableTrivialInit const&, \
I pos, \
BOOST_CONTAINER_PP_PARAM(P, p) \
BOOST_PP_ENUM_TRAILING(n, BOOST_CONTAINER_PP_PARAM_LIST, _)) \
{ \
typedef typename boost::iterator_value<I>::type V; \
new \
(static_cast<void*>(boost::addressof(*pos))) \
V(p, BOOST_PP_ENUM(n, BOOST_CONTAINER_PP_PARAM_FORWARD, _)); /*may throw*/ \
} \
//
#define BOOST_PP_LOCAL_LIMITS (1, BOOST_CONTAINER_MAX_CONSTRUCTOR_PARAMETERS)
#include BOOST_PP_LOCAL_ITERATE()
#endif // !BOOST_NO_VARIADIC_TEMPLATES
#endif // !BOOST_CONTAINER_VARRAY_DISABLE_EMPLACE
// assign(I, V)
template <typename I, typename V>
inline
void assign_dispatch(I pos, V const& v,
boost::mpl::bool_<true> const& /*use_memcpy*/)
{
::memcpy(boost::addressof(*pos), boost::addressof(v), sizeof(V));
}
template <typename I, typename V>
inline
void assign_dispatch(I pos, V const& v,
boost::mpl::bool_<false> const& /*use_memcpy*/)
{
*pos = v; // may throw
}
template <typename I, typename V>
inline
void assign(I pos, V const& v)
{
typedef typename
::boost::mpl::and_<
is_corresponding_value<I, V>,
::boost::has_trivial_assign<V>
>::type
use_memcpy;
assign_dispatch(pos, v, use_memcpy()); // may throw
}
template <typename I, typename V>
inline
void assign(I pos, BOOST_RV_REF(V) v)
{
*pos = boost::move(v); // may throw
}
// uninitialized_copy_s
template <typename I, typename F>
inline std::size_t uninitialized_copy_s(I first, I last, F dest, std::size_t max_count)
{
std::size_t count = 0;
F it = dest;
BOOST_TRY
{
for ( ; first != last ; ++it, ++first, ++count )
{
if ( max_count <= count )
return (std::numeric_limits<std::size_t>::max)();
// dummy 0 as DisableTrivialInit
construct(0, it, *first); // may throw
}
}
BOOST_CATCH(...)
{
destroy(dest, it);
BOOST_RETHROW;
}
BOOST_CATCH_END
return count;
}
// scoped_destructor
template<class T>
class scoped_destructor
{
public:
scoped_destructor(T * ptr) : m_ptr(ptr) {}
~scoped_destructor()
{
if(m_ptr)
destroy(m_ptr);
}
void release() { m_ptr = 0; }
private:
T * m_ptr;
};
}}} // namespace boost::container::varray_detail
#endif // BOOST_CONTAINER_DETAIL_VARRAY_UTIL_HPP

994
bench/varray.hpp Normal file
View File

@@ -0,0 +1,994 @@
// Boost.Container varray
//
// Copyright (c) 2012-2013 Adam Wulkiewicz, Lodz, Poland.
// Copyright (c) 2011-2013 Andrew Hundt.
//
// Use, modification and distribution is subject to the Boost Software License,
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_CONTAINER_VARRAY_HPP
#define BOOST_CONTAINER_VARRAY_HPP
#if (defined _MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif
#include <boost/container/detail/config_begin.hpp>
#include "detail/varray.hpp"
namespace boost { namespace container {
/**
* @defgroup varray_non_member varray non-member functions
*/
/**
* @brief A variable-size array container with fixed capacity.
*
* varray is a sequence container like boost::container::vector with contiguous storage that can
* change in size, along with the static allocation, low overhead, and fixed capacity of boost::array.
*
* A varray is a sequence that supports random access to elements, constant time insertion and
* removal of elements at the end, and linear time insertion and removal of elements at the beginning or
* in the middle. The number of elements in a varray may vary dynamically up to a fixed capacity
* because elements are stored within the object itself similarly to an array. However, objects are
* initialized as they are inserted into varray unlike C arrays or std::array which must construct
* all elements on instantiation. The behavior of varray enables the use of statically allocated
* elements in cases with complex object lifetime requirements that would otherwise not be trivially
* possible.
*
* @par Error Handling
* Insertion beyond the capacity and out of bounds errors result in undefined behavior.
* The reason for this is because unlike vectors, varray does not perform allocation.
*
* @tparam Value The type of element that will be stored.
* @tparam Capacity The maximum number of elements varray can store, fixed at compile time.
*/
template <typename Value, std::size_t Capacity>
class varray
: public container_detail::varray<Value, Capacity>
{
typedef container_detail::varray<Value, Capacity> base_t;
BOOST_COPYABLE_AND_MOVABLE(varray)
public:
//! @brief The type of elements stored in the container.
typedef typename base_t::value_type value_type;
//! @brief The unsigned integral type used by the container.
typedef typename base_t::size_type size_type;
//! @brief The pointers difference type.
typedef typename base_t::difference_type difference_type;
//! @brief The pointer type.
typedef typename base_t::pointer pointer;
//! @brief The const pointer type.
typedef typename base_t::const_pointer const_pointer;
//! @brief The value reference type.
typedef typename base_t::reference reference;
//! @brief The value const reference type.
typedef typename base_t::const_reference const_reference;
//! @brief The iterator type.
typedef typename base_t::iterator iterator;
//! @brief The const iterator type.
typedef typename base_t::const_iterator const_iterator;
//! @brief The reverse iterator type.
typedef typename base_t::reverse_iterator reverse_iterator;
//! @brief The const reverse iterator.
typedef typename base_t::const_reverse_iterator const_reverse_iterator;
//! @brief Constructs an empty varray.
//!
//! @par Throws
//! Nothing.
//!
//! @par Complexity
//! Constant O(1).
varray()
: base_t()
{}
//! @pre <tt>count <= capacity()</tt>
//!
//! @brief Constructs a varray containing count default constructed Values.
//!
//! @param count The number of values which will be contained in the container.
//!
//! @par Throws
//! If Value's default constructor throws.
//!
//! @par Complexity
//! Linear O(N).
explicit varray(size_type count)
: base_t(count)
{}
//! @pre <tt>count <= capacity()</tt>
//!
//! @brief Constructs a varray containing count copies of value.
//!
//! @param count The number of copies of a values that will be contained in the container.
//! @param value The value which will be used to copy construct values.
//!
//! @par Throws
//! If Value's copy constructor throws.
//!
//! @par Complexity
//! Linear O(N).
varray(size_type count, value_type const& value)
: base_t(count, value)
{}
//! @pre
//! @li <tt>distance(first, last) <= capacity()</tt>
//! @li Iterator must meet the \c ForwardTraversalIterator concept.
//!
//! @brief Constructs a varray containing copy of a range <tt>[first, last)</tt>.
//!
//! @param first The iterator to the first element in range.
//! @param last The iterator to the one after the last element in range.
//!
//! @par Throws
//! If Value's constructor taking a dereferenced Iterator throws.
//!
//! @par Complexity
//! Linear O(N).
template <typename Iterator>
varray(Iterator first, Iterator last)
: base_t(first, last)
{}
//! @brief Constructs a copy of other varray.
//!
//! @param other The varray which content will be copied to this one.
//!
//! @par Throws
//! If Value's copy constructor throws.
//!
//! @par Complexity
//! Linear O(N).
varray(varray const& other)
: base_t(other)
{}
//! @pre <tt>other.size() <= capacity()</tt>.
//!
//! @brief Constructs a copy of other varray.
//!
//! @param other The varray which content will be copied to this one.
//!
//! @par Throws
//! If Value's copy constructor throws.
//!
//! @par Complexity
//! Linear O(N).
template <std::size_t C>
varray(varray<value_type, C> const& other) : base_t(other) {}
//! @brief Copy assigns Values stored in the other varray to this one.
//!
//! @param other The varray which content will be copied to this one.
//!
//! @par Throws
//! If Value's copy constructor or copy assignment throws.
//!
//! @par Complexity
//! Linear O(N).
varray & operator=(BOOST_COPY_ASSIGN_REF(varray) other)
{
base_t::operator=(static_cast<base_t const&>(other));
return *this;
}
//! @pre <tt>other.size() <= capacity()</tt>
//!
//! @brief Copy assigns Values stored in the other varray to this one.
//!
//! @param other The varray which content will be copied to this one.
//!
//! @par Throws
//! If Value's copy constructor or copy assignment throws.
//!
//! @par Complexity
//! Linear O(N).
template <std::size_t C>
// TEMPORARY WORKAROUND
#if defined(BOOST_NO_RVALUE_REFERENCES)
varray & operator=(::boost::rv< varray<value_type, C> > const& other)
#else
varray & operator=(varray<value_type, C> const& other)
#endif
{
base_t::operator=(static_cast<varray<value_type, C> const&>(other));
return *this;
}
//! @brief Move constructor. Moves Values stored in the other varray to this one.
//!
//! @param other The varray which content will be moved to this one.
//!
//! @par Throws
//! @li If \c boost::has_nothrow_move<Value>::value is \c true and Value's move constructor throws.
//! @li If \c boost::has_nothrow_move<Value>::value is \c false and Value's copy constructor throws.
//!
//! @par Complexity
//! Linear O(N).
varray(BOOST_RV_REF(varray) other)
: base_t(boost::move(static_cast<base_t&>(other)))
{}
//! @pre <tt>other.size() <= capacity()</tt>
//!
//! @brief Move constructor. Moves Values stored in the other varray to this one.
//!
//! @param other The varray which content will be moved to this one.
//!
//! @par Throws
//! @li If \c boost::has_nothrow_move<Value>::value is \c true and Value's move constructor throws.
//! @li If \c boost::has_nothrow_move<Value>::value is \c false and Value's copy constructor throws.
//!
//! @par Complexity
//! Linear O(N).
template <std::size_t C>
varray(BOOST_RV_REF_2_TEMPL_ARGS(varray, value_type, C) other)
: base_t(boost::move(static_cast<container_detail::varray<value_type, C>&>(other)))
{}
//! @brief Move assignment. Moves Values stored in the other varray to this one.
//!
//! @param other The varray which content will be moved to this one.
//!
//! @par Throws
//! @li If \c boost::has_nothrow_move<Value>::value is \c true and Value's move constructor or move assignment throws.
//! @li If \c boost::has_nothrow_move<Value>::value is \c false and Value's copy constructor or copy assignment throws.
//!
//! @par Complexity
//! Linear O(N).
varray & operator=(BOOST_RV_REF(varray) other)
{
base_t::operator=(boost::move(static_cast<base_t&>(other)));
return *this;
}
//! @pre <tt>other.size() <= capacity()</tt>
//!
//! @brief Move assignment. Moves Values stored in the other varray to this one.
//!
//! @param other The varray which content will be moved to this one.
//!
//! @par Throws
//! @li If \c boost::has_nothrow_move<Value>::value is \c true and Value's move constructor or move assignment throws.
//! @li If \c boost::has_nothrow_move<Value>::value is \c false and Value's copy constructor or copy assignment throws.
//!
//! @par Complexity
//! Linear O(N).
template <std::size_t C>
varray & operator=(BOOST_RV_REF_2_TEMPL_ARGS(varray, value_type, C) other)
{
base_t::operator=(boost::move(static_cast<container_detail::varray<value_type, C>&>(other)));
return *this;
}
#ifdef BOOST_CONTAINER_DOXYGEN_INVOKED
//! @brief Destructor. Destroys Values stored in this container.
//!
//! @par Throws
//! Nothing
//!
//! @par Complexity
//! Linear O(N).
~varray();
//! @brief Swaps contents of the other varray and this one.
//!
//! @param other The varray which content will be swapped with this one's content.
//!
//! @par Throws
//! @li If \c boost::has_nothrow_move<Value>::value is \c true and Value's move constructor or move assignment throws,
//! @li If \c boost::has_nothrow_move<Value>::value is \c false and Value's copy constructor or copy assignment throws,
//!
//! @par Complexity
//! Linear O(N).
void swap(varray & other);
//! @pre <tt>other.size() <= capacity() && size() <= other.capacity()</tt>
//!
//! @brief Swaps contents of the other varray and this one.
//!
//! @param other The varray which content will be swapped with this one's content.
//!
//! @par Throws
//! @li If \c boost::has_nothrow_move<Value>::value is \c true and Value's move constructor or move assignment throws,
//! @li If \c boost::has_nothrow_move<Value>::value is \c false and Value's copy constructor or copy assignment throws,
//!
//! @par Complexity
//! Linear O(N).
template <std::size_t C>
void swap(varray<value_type, C> & other);
//! @pre <tt>count <= capacity()</tt>
//!
//! @brief Inserts or erases elements at the end such that
//! the size becomes count. New elements are default constructed.
//!
//! @param count The number of elements which will be stored in the container.
//!
//! @par Throws
//! If Value's default constructor throws.
//!
//! @par Complexity
//! Linear O(N).
void resize(size_type count);
//! @pre <tt>count <= capacity()</tt>
//!
//! @brief Inserts or erases elements at the end such that
//! the size becomes count. New elements are copy constructed from value.
//!
//! @param count The number of elements which will be stored in the container.
//! @param value The value used to copy construct the new element.
//!
//! @par Throws
//! If Value's copy constructor throws.
//!
//! @par Complexity
//! Linear O(N).
void resize(size_type count, value_type const& value);
//! @pre <tt>count <= capacity()</tt>
//!
//! @brief This call has no effect because the Capacity of this container is constant.
//!
//! @param count The number of elements which the container should be able to contain.
//!
//! @par Throws
//! Nothing.
//!
//! @par Complexity
//! Linear O(N).
void reserve(size_type count);
//! @pre <tt>size() < capacity()</tt>
//!
//! @brief Adds a copy of value at the end.
//!
//! @param value The value used to copy construct the new element.
//!
//! @par Throws
//! If Value's copy constructor throws.
//!
//! @par Complexity
//! Constant O(1).
void push_back(value_type const& value);
//! @pre <tt>size() < capacity()</tt>
//!
//! @brief Moves value to the end.
//!
//! @param value The value to move construct the new element.
//!
//! @par Throws
//! If Value's move constructor throws.
//!
//! @par Complexity
//! Constant O(1).
void push_back(BOOST_RV_REF(value_type) value);
//! @pre <tt>!empty()</tt>
//!
//! @brief Destroys last value and decreases the size.
//!
//! @par Throws
//! Nothing by default.
//!
//! @par Complexity
//! Constant O(1).
void pop_back();
//! @pre
//! @li \c position must be a valid iterator of \c *this in range <tt>[begin(), end()]</tt>.
//! @li <tt>size() < capacity()</tt>
//!
//! @brief Inserts a copy of element at position.
//!
//! @param position The position at which the new value will be inserted.
//! @param value The value used to copy construct the new element.
//!
//! @par Throws
//! @li If Value's copy constructor or copy assignment throws
//! @li If Value's move constructor or move assignment throws.
//!
//! @par Complexity
//! Constant or linear.
iterator insert(iterator position, value_type const& value);
//! @pre
//! @li \c position must be a valid iterator of \c *this in range <tt>[begin(), end()]</tt>.
//! @li <tt>size() < capacity()</tt>
//!
//! @brief Inserts a move-constructed element at position.
//!
//! @param position The position at which the new value will be inserted.
//! @param value The value used to move construct the new element.
//!
//! @par Throws
//! If Value's move constructor or move assignment throws.
//!
//! @par Complexity
//! Constant or linear.
iterator insert(iterator position, BOOST_RV_REF(value_type) value);
//! @pre
//! @li \c position must be a valid iterator of \c *this in range <tt>[begin(), end()]</tt>.
//! @li <tt>size() + count <= capacity()</tt>
//!
//! @brief Inserts a count copies of value at position.
//!
//! @param position The position at which new elements will be inserted.
//! @param count The number of new elements which will be inserted.
//! @param value The value used to copy construct new elements.
//!
//! @par Throws
//! @li If Value's copy constructor or copy assignment throws.
//! @li If Value's move constructor or move assignment throws.
//!
//! @par Complexity
//! Linear O(N).
iterator insert(iterator position, size_type count, value_type const& value);
//! @pre
//! @li \c position must be a valid iterator of \c *this in range <tt>[begin(), end()]</tt>.
//! @li <tt>distance(first, last) <= capacity()</tt>
//! @li \c Iterator must meet the \c ForwardTraversalIterator concept.
//!
//! @brief Inserts a copy of a range <tt>[first, last)</tt> at position.
//!
//! @param position The position at which new elements will be inserted.
//! @param first The iterator to the first element of a range used to construct new elements.
//! @param last The iterator to the one after the last element of a range used to construct new elements.
//!
//! @par Throws
//! @li If Value's constructor and assignment taking a dereferenced \c Iterator.
//! @li If Value's move constructor or move assignment throws.
//!
//! @par Complexity
//! Linear O(N).
template <typename Iterator>
iterator insert(iterator position, Iterator first, Iterator last);
//! @pre \c position must be a valid iterator of \c *this in range <tt>[begin(), end())</tt>
//!
//! @brief Erases Value from position.
//!
//! @param position The position of the element which will be erased from the container.
//!
//! @par Throws
//! If Value's move assignment throws.
//!
//! @par Complexity
//! Linear O(N).
iterator erase(iterator position);
//! @pre
//! @li \c first and \c last must define a valid range
//! @li iterators must be in range <tt>[begin(), end()]</tt>
//!
//! @brief Erases Values from a range <tt>[first, last)</tt>.
//!
//! @param first The position of the first element of a range which will be erased from the container.
//! @param last The position of the one after the last element of a range which will be erased from the container.
//!
//! @par Throws
//! If Value's move assignment throws.
//!
//! @par Complexity
//! Linear O(N).
iterator erase(iterator first, iterator last);
//! @pre <tt>distance(first, last) <= capacity()</tt>
//!
//! @brief Assigns a range <tt>[first, last)</tt> of Values to this container.
//!
//! @param first The iterator to the first element of a range used to construct new content of this container.
//! @param last The iterator to the one after the last element of a range used to construct new content of this container.
//!
//! @par Throws
//! If Value's copy constructor or copy assignment throws,
//!
//! @par Complexity
//! Linear O(N).
template <typename Iterator>
void assign(Iterator first, Iterator last);
//! @pre <tt>count <= capacity()</tt>
//!
//! @brief Assigns a count copies of value to this container.
//!
//! @param count The new number of elements which will be container in the container.
//! @param value The value which will be used to copy construct the new content.
//!
//! @par Throws
//! If Value's copy constructor or copy assignment throws.
//!
//! @par Complexity
//! Linear O(N).
void assign(size_type count, value_type const& value);
//! @pre <tt>size() < capacity()</tt>
//!
//! @brief Inserts a Value constructed with
//! \c std::forward<Args>(args)... in the end of the container.
//!
//! @param args The arguments of the constructor of the new element which will be created at the end of the container.
//!
//! @par Throws
//! If in-place constructor throws or Value's move constructor throws.
//!
//! @par Complexity
//! Constant O(1).
template<class ...Args>
void emplace_back(Args &&...args);
//! @pre
//! @li \c position must be a valid iterator of \c *this in range <tt>[begin(), end()]</tt>
//! @li <tt>size() < capacity()</tt>
//!
//! @brief Inserts a Value constructed with
//! \c std::forward<Args>(args)... before position
//!
//! @param position The position at which new elements will be inserted.
//! @param args The arguments of the constructor of the new element.
//!
//! @par Throws
//! If in-place constructor throws or if Value's move constructor or move assignment throws.
//!
//! @par Complexity
//! Constant or linear.
template<class ...Args>
iterator emplace(iterator position, Args &&...args);
//! @brief Removes all elements from the container.
//!
//! @par Throws
//! Nothing.
//!
//! @par Complexity
//! Constant O(1).
void clear();
//! @pre <tt>i < size()</tt>
//!
//! @brief Returns reference to the i-th element.
//!
//! @param i The element's index.
//!
//! @return reference to the i-th element
//! from the beginning of the container.
//!
//! @par Throws
//! \c std::out_of_range exception by default.
//!
//! @par Complexity
//! Constant O(1).
reference at(size_type i);
//! @pre <tt>i < size()</tt>
//!
//! @brief Returns const reference to the i-th element.
//!
//! @param i The element's index.
//!
//! @return const reference to the i-th element
//! from the beginning of the container.
//!
//! @par Throws
//! \c std::out_of_range exception by default.
//!
//! @par Complexity
//! Constant O(1).
const_reference at(size_type i) const;
//! @pre <tt>i < size()</tt>
//!
//! @brief Returns reference to the i-th element.
//!
//! @param i The element's index.
//!
//! @return reference to the i-th element
//! from the beginning of the container.
//!
//! @par Throws
//! Nothing by default.
//!
//! @par Complexity
//! Constant O(1).
reference operator[](size_type i);
//! @pre <tt>i < size()</tt>
//!
//! @brief Returns const reference to the i-th element.
//!
//! @param i The element's index.
//!
//! @return const reference to the i-th element
//! from the beginning of the container.
//!
//! @par Throws
//! Nothing by default.
//!
//! @par Complexity
//! Constant O(1).
const_reference operator[](size_type i) const;
//! @pre \c !empty()
//!
//! @brief Returns reference to the first element.
//!
//! @return reference to the first element
//! from the beginning of the container.
//!
//! @par Throws
//! Nothing by default.
//!
//! @par Complexity
//! Constant O(1).
reference front();
//! @pre \c !empty()
//!
//! @brief Returns const reference to the first element.
//!
//! @return const reference to the first element
//! from the beginning of the container.
//!
//! @par Throws
//! Nothing by default.
//!
//! @par Complexity
//! Constant O(1).
const_reference front() const;
//! @pre \c !empty()
//!
//! @brief Returns reference to the last element.
//!
//! @return reference to the last element
//! from the beginning of the container.
//!
//! @par Throws
//! Nothing by default.
//!
//! @par Complexity
//! Constant O(1).
reference back();
//! @pre \c !empty()
//!
//! @brief Returns const reference to the first element.
//!
//! @return const reference to the last element
//! from the beginning of the container.
//!
//! @par Throws
//! Nothing by default.
//!
//! @par Complexity
//! Constant O(1).
const_reference back() const;
//! @brief Pointer such that <tt>[data(), data() + size())</tt> is a valid range.
//! For a non-empty vector <tt>data() == &front()</tt>.
//!
//! @par Throws
//! Nothing.
//!
//! @par Complexity
//! Constant O(1).
Value * data();
//! @brief Const pointer such that <tt>[data(), data() + size())</tt> is a valid range.
//! For a non-empty vector <tt>data() == &front()</tt>.
//!
//! @par Throws
//! Nothing.
//!
//! @par Complexity
//! Constant O(1).
const Value * data() const;
//! @brief Returns iterator to the first element.
//!
//! @return iterator to the first element contained in the vector.
//!
//! @par Throws
//! Nothing.
//!
//! @par Complexity
//! Constant O(1).
iterator begin();
//! @brief Returns const iterator to the first element.
//!
//! @return const_iterator to the first element contained in the vector.
//!
//! @par Throws
//! Nothing.
//!
//! @par Complexity
//! Constant O(1).
const_iterator begin() const;
//! @brief Returns const iterator to the first element.
//!
//! @return const_iterator to the first element contained in the vector.
//!
//! @par Throws
//! Nothing.
//!
//! @par Complexity
//! Constant O(1).
const_iterator cbegin() const;
//! @brief Returns iterator to the one after the last element.
//!
//! @return iterator pointing to the one after the last element contained in the vector.
//!
//! @par Throws
//! Nothing.
//!
//! @par Complexity
//! Constant O(1).
iterator end();
//! @brief Returns const iterator to the one after the last element.
//!
//! @return const_iterator pointing to the one after the last element contained in the vector.
//!
//! @par Throws
//! Nothing.
//!
//! @par Complexity
//! Constant O(1).
const_iterator end() const;
//! @brief Returns const iterator to the one after the last element.
//!
//! @return const_iterator pointing to the one after the last element contained in the vector.
//!
//! @par Throws
//! Nothing.
//!
//! @par Complexity
//! Constant O(1).
const_iterator cend() const;
//! @brief Returns reverse iterator to the first element of the reversed container.
//!
//! @return reverse_iterator pointing to the beginning
//! of the reversed varray.
//!
//! @par Throws
//! Nothing.
//!
//! @par Complexity
//! Constant O(1).
reverse_iterator rbegin();
//! @brief Returns const reverse iterator to the first element of the reversed container.
//!
//! @return const_reverse_iterator pointing to the beginning
//! of the reversed varray.
//!
//! @par Throws
//! Nothing.
//!
//! @par Complexity
//! Constant O(1).
const_reverse_iterator rbegin() const;
//! @brief Returns const reverse iterator to the first element of the reversed container.
//!
//! @return const_reverse_iterator pointing to the beginning
//! of the reversed varray.
//!
//! @par Throws
//! Nothing.
//!
//! @par Complexity
//! Constant O(1).
const_reverse_iterator crbegin() const;
//! @brief Returns reverse iterator to the one after the last element of the reversed container.
//!
//! @return reverse_iterator pointing to the one after the last element
//! of the reversed varray.
//!
//! @par Throws
//! Nothing.
//!
//! @par Complexity
//! Constant O(1).
reverse_iterator rend();
//! @brief Returns const reverse iterator to the one after the last element of the reversed container.
//!
//! @return const_reverse_iterator pointing to the one after the last element
//! of the reversed varray.
//!
//! @par Throws
//! Nothing.
//!
//! @par Complexity
//! Constant O(1).
const_reverse_iterator rend() const;
//! @brief Returns const reverse iterator to the one after the last element of the reversed container.
//!
//! @return const_reverse_iterator pointing to the one after the last element
//! of the reversed varray.
//!
//! @par Throws
//! Nothing.
//!
//! @par Complexity
//! Constant O(1).
const_reverse_iterator crend() const;
//! @brief Returns container's capacity.
//!
//! @return container's capacity.
//!
//! @par Throws
//! Nothing.
//!
//! @par Complexity
//! Constant O(1).
static size_type capacity();
//! @brief Returns container's capacity.
//!
//! @return container's capacity.
//!
//! @par Throws
//! Nothing.
//!
//! @par Complexity
//! Constant O(1).
static size_type max_size();
//! @brief Returns the number of stored elements.
//!
//! @return Number of elements contained in the container.
//!
//! @par Throws
//! Nothing.
//!
//! @par Complexity
//! Constant O(1).
size_type size() const;
//! @brief Queries if the container contains elements.
//!
//! @return true if the number of elements contained in the
//! container is equal to 0.
//!
//! @par Throws
//! Nothing.
//!
//! @par Complexity
//! Constant O(1).
bool empty() const;
#endif // BOOST_CONTAINER_DOXYGEN_INVOKED
};
#ifdef BOOST_CONTAINER_DOXYGEN_INVOKED
//! @brief Checks if contents of two varrays are equal.
//!
//! @ingroup varray_non_member
//!
//! @param x The first varray.
//! @param y The second varray.
//!
//! @return \c true if containers have the same size and elements in both containers are equal.
//!
//! @par Complexity
//! Linear O(N).
template<typename V, std::size_t C1, std::size_t C2>
bool operator== (varray<V, C1> const& x, varray<V, C2> const& y);
//! @brief Checks if contents of two varrays are not equal.
//!
//! @ingroup varray_non_member
//!
//! @param x The first varray.
//! @param y The second varray.
//!
//! @return \c true if containers have different size or elements in both containers are not equal.
//!
//! @par Complexity
//! Linear O(N).
template<typename V, std::size_t C1, std::size_t C2>
bool operator!= (varray<V, C1> const& x, varray<V, C2> const& y);
//! @brief Lexicographically compares varrays.
//!
//! @ingroup varray_non_member
//!
//! @param x The first varray.
//! @param y The second varray.
//!
//! @return \c true if x compares lexicographically less than y.
//!
//! @par Complexity
//! Linear O(N).
template<typename V, std::size_t C1, std::size_t C2>
bool operator< (varray<V, C1> const& x, varray<V, C2> const& y);
//! @brief Lexicographically compares varrays.
//!
//! @ingroup varray_non_member
//!
//! @param x The first varray.
//! @param y The second varray.
//!
//! @return \c true if y compares lexicographically less than x.
//!
//! @par Complexity
//! Linear O(N).
template<typename V, std::size_t C1, std::size_t C2>
bool operator> (varray<V, C1> const& x, varray<V, C2> const& y);
//! @brief Lexicographically compares varrays.
//!
//! @ingroup varray_non_member
//!
//! @param x The first varray.
//! @param y The second varray.
//!
//! @return \c true if y don't compare lexicographically less than x.
//!
//! @par Complexity
//! Linear O(N).
template<typename V, std::size_t C1, std::size_t C2>
bool operator<= (varray<V, C1> const& x, varray<V, C2> const& y);
//! @brief Lexicographically compares varrays.
//!
//! @ingroup varray_non_member
//!
//! @param x The first varray.
//! @param y The second varray.
//!
//! @return \c true if x don't compare lexicographically less than y.
//!
//! @par Complexity
//! Linear O(N).
template<typename V, std::size_t C1, std::size_t C2>
bool operator>= (varray<V, C1> const& x, varray<V, C2> const& y);
//! @brief Swaps contents of two varrays.
//!
//! This function calls varray::swap().
//!
//! @ingroup varray_non_member
//!
//! @param x The first varray.
//! @param y The second varray.
//!
//! @par Complexity
//! Linear O(N).
template<typename V, std::size_t C1, std::size_t C2>
inline void swap(varray<V, C1> & x, varray<V, C2> & y);
#endif // BOOST_CONTAINER_DOXYGEN_INVOKED
}} // namespace boost::container
#include <boost/container/detail/config_end.hpp>
#endif // BOOST_CONTAINER_VARRAY_HPP

View File

@@ -50,6 +50,8 @@ boostbook standalone
:
<format>html:<xsl:param>boost.root=../../../..
<format>html:<xsl:param>boost.libraries=../../../../libs/libraries.htm
<format>html:<xsl:param>img.src.path=../../../../doc/html/
<format>xhtml:<xsl:param>img.src.path=../../../../doc/html/
<xsl:param>generate.section.toc.level=3
<xsl:param>chunk.first.sections=1
<format>pdf:<xsl:param>img.src.path=$(images_location)/

View File

@@ -189,6 +189,49 @@ Finally, we can just compile, link, and run!
[endsect]
[section:exception_handling Boost.Container and C++ exceptions]
In some environments, such as game development or embedded systems, C++ exceptions are disabled or a customized error handling is needed.
According to document [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2271.html N2271 EASTL -- Electronic Arts Standard Template Library]
exceptions can be disabled for several reasons:
* ["['Exception handling incurs some kind of cost in all compiler implementations, including those that avoid
the cost during normal execution. However, in some cases this cost may arguably offset the cost of the code that it is replacing.]]
* ["['Exception handling is often agreed to be a superior solution for handling a large range of function return values. However,
avoiding the creation of functions that need large ranges of return values is superior to using exception handling to handle such values.]]
* ["['Using exception handling correctly can be difficult in the case of complex software.]]
* ["['The execution of throw and catch can be significantly expensive with some implementations.]]
* ["['Exception handling violates the don't-pay-for-what-you-don't-use design of C++, as it incurs overhead in any non-leaf function that
has destructible stack objects regardless of whether they use exception handling.]]
* ["['The approach that game software usually takes is to avoid the need for exception handling where possible; avoid the possibility
of circumstances that may lead to exceptions. For example, verify up front that there is enough memory for a subsystem to do its job
instead of trying to deal with the problem via exception handling or any other means after it occurs.]]
* ["['However, some game libraries may nevertheless benefit from the use of exception handling. It's best, however,
if such libraries keep the exception handling internal lest they force their usage of exception handling on the rest of the application.]]
In order to support environments without C++ exception support or environments with special error handling needs,
[*Boost.Container] changes error signalling behaviour when `BOOST_CONTAINER_USER_DEFINED_THROW_CALLBACKS` or `BOOST_NO_EXCEPTIONS`
is defined. The former shall be defined by the user and the latter can be either defined by the user or implicitly defined by [*Boost.Confg]
when the compiler has been invoked with the appropriate flag (like `-fno-exceptions` in GCC).
When dealing with user-defined classes, (e.g. when constructing user-defined classes):
* If `BOOST_NO_EXCEPTIONS` is defined, the library avoids using `try`/`catch`/`throw` statements. The class writer must handle and
propagate error situations internally as no error will be propagated through [*Boost.Container].
* If `BOOST_NO_EXCEPTIONS` is *not* defined, the library propagates exceptions offering the exception guarantees detailed in the documentation.
When the library needs to throw an exception (such as `out_of_range` when an incorrect index is used in `vector::at`)], the library calls
a throw callback declared in `<boost/container/throw_exception.hpp>`:
* If `BOOST_CONTAINER_USER_DEFINED_THROW_CALLBACKS` is defined, then the programmer must provide its own definition for all
`throw_xxx` functions. Those functions can't return, they must throw an exception or call `std::exit` or `std::abort`.
* Else if `BOOST_NO_EXCEPTIONS` is defined, a `BOOST_ASSERT_MSG` assertion is triggered
(see [@http://www.boost.org/libs/utility/assert.html Boost.Assert] for more information).
If this assertion returns, then `std::abort` is called.
* Else, an appropriate standard library exception is thrown (like `std::out_of_range`).
[endsect]
[section:non_standard_containers Non-standard containers]
[section:stable_vector ['stable_vector]]
@@ -210,7 +253,7 @@ can a stable design approach the behavior of `vector` (random access iterators,
insertion/deletion, minimal memory overhead, etc.)?
The following image describes the layout of a possible data structure upon which to base the design of a stable vector:
[$images/stable_vector.png [width 50%] [align center] ]
[$../../libs/container/doc/html/images/stable_vector.png [width 50%] [align center] ]
Each element is stored in its own separate node. All the nodes are referenced from a contiguous array of pointers, but
also every node contains an "up" pointer referring back to the associated array cell. This up pointer is the key element
@@ -569,6 +612,8 @@ use [*Boost.Container]? There are several reasons for that:
usually implies a no-throw guarantee (if predicate's or allocator's default constructor doesn't throw).
* Small string optimization for [classref boost::container::basic_string basic_string].
* New extensions beyond the standard based on user feedback to improve code performance.
* You need a portable implementation that works when compiling without exceptions support or
you need to customize the error handling when a container needs to signall an exceptional error.
[endsect]
@@ -614,6 +659,17 @@ use [*Boost.Container]? There are several reasons for that:
[section:release_notes Release Notes]
[section:release_notes_boost_1_54_00 Boost 1.54 Release]
* Speed improvements in `vector` constructors/copy/move/swap, dispatching to memcpy when possible.
* Support for `BOOST_NO_EXCEPTIONS` [@https://svn.boost.org/trac/boost/ticket/7227 #7227].
* Fixed bugs [@https://svn.boost.org/trac/boost/ticket/7921 #7921],
[@https://svn.boost.org/trac/boost/ticket/7969 #7969],
[@https://svn.boost.org/trac/boost/ticket/8118 #8118],
[@https://svn.boost.org/trac/boost/ticket/8294 #8294].
[endsect]
[section:release_notes_boost_1_53_00 Boost 1.53 Release]
* Fixed bug [@https://svn.boost.org/trac/boost/ticket/7650 #7650].

View File

@@ -1,537 +0,0 @@
/*=============================================================================
Copyright (c) 2004 Joel de Guzman
Use, modification and distribution is subject to the Boost Software
License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
=============================================================================*/
/*=============================================================================
Body defaults
=============================================================================*/
body
{
margin: 1em;
font-family: sans-serif;
}
/*=============================================================================
Paragraphs
=============================================================================*/
p
{
text-align: left;
font-size: 10pt;
line-height: 1.15;
}
/*=============================================================================
Program listings
=============================================================================*/
/* Code on paragraphs */
p tt.computeroutput
{
font-size: 10pt;
}
pre.synopsis
{
font-size: 10pt;
margin: 1pc 4% 0pc 4%;
padding: 0.5pc 0.5pc 0.5pc 0.5pc;
}
.programlisting,
.screen
{
font-size: 10pt;
display: block;
margin: 1pc 4% 0pc 4%;
padding: 0.5pc 0.5pc 0.5pc 0.5pc;
}
/*=============================================================================
Headings
=============================================================================*/
h1, h2, h3, h4, h5, h6
{
text-align: left;
margin: 1em 0em 0.5em 0em;
font-weight: bold;
}
h1 { font: 140% }
h2 { font: bold 140% }
h3 { font: bold 130% }
h4 { font: bold 120% }
h5 { font: italic 110% }
h6 { font: italic 100% }
/* Top page titles */
title,
h1.title,
h2.title
h3.title,
h4.title,
h5.title,
h6.title,
.refentrytitle
{
font-weight: bold;
margin-bottom: 1pc;
}
h1.title { font-size: 140% }
h2.title { font-size: 140% }
h3.title { font-size: 130% }
h4.title { font-size: 120% }
h5.title { font-size: 110% }
h6.title { font-size: 100% }
.section h1
{
margin: 0em 0em 0.5em 0em;
font-size: 140%;
}
.section h2 { font-size: 140% }
.section h3 { font-size: 130% }
.section h4 { font-size: 120% }
.section h5 { font-size: 110% }
.section h6 { font-size: 100% }
/* Code on titles */
h1 tt.computeroutput { font-size: 140% }
h2 tt.computeroutput { font-size: 140% }
h3 tt.computeroutput { font-size: 130% }
h4 tt.computeroutput { font-size: 120% }
h5 tt.computeroutput { font-size: 110% }
h6 tt.computeroutput { font-size: 100% }
/*=============================================================================
Author
=============================================================================*/
h3.author
{
font-size: 100%
}
/*=============================================================================
Lists
=============================================================================*/
li
{
font-size: 10pt;
line-height: 1.3;
}
/* Unordered lists */
ul
{
text-align: left;
}
/* Ordered lists */
ol
{
text-align: left;
}
/*=============================================================================
Links
=============================================================================*/
a
{
text-decoration: none; /* no underline */
}
a:hover
{
text-decoration: underline;
}
/*=============================================================================
Spirit style navigation
=============================================================================*/
.spirit-nav
{
text-align: right;
}
.spirit-nav a
{
color: white;
padding-left: 0.5em;
}
.spirit-nav img
{
border-width: 0px;
}
/*=============================================================================
Table of contents
=============================================================================*/
.toc
{
margin: 1pc 4% 0pc 4%;
padding: 0.1pc 1pc 0.1pc 1pc;
font-size: 10pt;
line-height: 1.15;
}
.toc-main
{
width: 600;
text-align: center;
margin: 1pc 1pc 1pc 10%;
padding: 2pc 1pc 3pc 1pc;
line-height: 0.1;
}
.boost-toc
{
float: right;
padding: 0.5pc;
}
/*=============================================================================
Tables
=============================================================================*/
.table-title,
div.table p.title
{
margin-left: 4%;
padding-right: 0.5em;
padding-left: 0.5em;
}
.informaltable table,
.table table
{
width: 92%;
margin-left: 4%;
margin-right: 4%;
}
div.informaltable table,
div.table table
{
padding: 4px;
}
/* Table Cells */
div.informaltable table tr td,
div.table table tr td
{
padding: 0.5em;
text-align: left;
}
div.informaltable table tr th,
div.table table tr th
{
padding: 0.5em 0.5em 0.5em 0.5em;
border: 1pt solid white;
font-size: 120%;
}
/*=============================================================================
Blurbs
=============================================================================*/
div.note,
div.tip,
div.important,
div.caution,
div.warning,
p.blurb
{
font-size: 10pt;
line-height: 1.2;
display: block;
margin: 1pc 4% 0pc 4%;
padding: 0.5pc 0.5pc 0.5pc 0.5pc;
}
p.blurb img
{
padding: 1pt;
}
/*=============================================================================
Variable Lists
=============================================================================*/
span.term
{
font-weight: bold;
font-size: 10pt;
}
div.variablelist table tbody tr td
{
text-align: left;
vertical-align: top;
padding: 0em 2em 0em 0em;
font-size: 10pt;
}
div.variablelist table tbody tr td p
{
margin: 0em 0em 0.5em 0em;
}
/* Make the terms in definition lists bold */
div.variablelist dl dt
{
font-weight: bold;
font-size: 10pt;
}
div.variablelist dl dd
{
margin: 1em 0em 1em 2em;
font-size: 10pt;
}
/*=============================================================================
Misc
=============================================================================*/
/* Title of books and articles in bibliographies */
span.title
{
font-style: italic;
}
span.underline
{
text-decoration: underline;
}
span.strikethrough
{
text-decoration: line-through;
}
/* Copyright, Legal Notice */
div div.legalnotice p
{
font-size: 8pt;
text-align: left
}
/*=============================================================================
Colors
=============================================================================*/
@media screen
{
/* Links */
a
{
color: #0C7445;
}
a:visited
{
color: #663974;
}
h1 a, h2 a, h3 a, h4 a, h5 a, h6 a,
h1 a:hover, h2 a:hover, h3 a:hover, h4 a:hover, h5 a:hover, h6 a:hover,
h1 a:visited, h2 a:visited, h3 a:visited, h4 a:visited, h5 a:visited, h6 a:visited
{
text-decoration: none; /* no underline */
color: #000000;
}
/* Syntax Highlighting */
.keyword { color: #0000AA; }
.identifier { color: #000000; }
.special { color: #707070; }
.preprocessor { color: #402080; }
.char { color: teal; }
.comment { color: #800000; }
.string { color: teal; }
.number { color: teal; }
.white_bkd { background-color: #E8FBE9; }
.dk_grey_bkd { background-color: #A0DAAC; }
/* Copyright, Legal Notice */
.copyright
{
color: #666666;
font-size: small;
}
div div.legalnotice p
{
color: #666666;
}
/* Program listing */
pre.synopsis
{
border: 1px solid #DCDCDC;
border-bottom: 3px solid #9D9D9D;
border-right: 3px solid #9D9D9D;
background-color: #FAFFFB;
}
.programlisting,
.screen
{
border: 1px solid #DCDCDC;
border-bottom: 3px solid #9D9D9D;
border-right: 3px solid #9D9D9D;
background-color: #FAFFFB;
}
/* Blurbs */
div.note,
div.tip,
div.important,
div.caution,
div.warning,
p.blurb
{
border: 1px solid #DCDCDC;
border-bottom: 3px solid #9D9D9D;
border-right: 3px solid #9D9D9D;
background-color: #FAFFFB;
}
/* Table of contents */
.toc
{
border: 1px solid #DCDCDC;
border-bottom: 3px solid #9D9D9D;
border-right: 3px solid #9D9D9D;
background-color: #FAFFFB;
}
/* Table of contents */
.toc-main
{
border: 1px solid #DCDCDC;
border-bottom: 3px solid #9D9D9D;
border-right: 3px solid #9D9D9D;
background-color: #FAFFFB;
}
/* Tables */
div.informaltable table tr td,
div.table table tr td
{
border: 1px solid #DCDCDC;
background-color: #FAFFFB;
}
div.informaltable table tr th,
div.table table tr th
{
background-color: #E3F9E4;
border: 1px solid #DCDCDC;
}
/* Misc */
span.highlight
{
color: #00A000;
}
}
@media print
{
/* Links */
a
{
color: black;
}
a:visited
{
color: black;
}
.spirit-nav
{
display: none;
}
/* Program listing */
pre.synopsis
{
border: 1px solid gray;
background-color: #FAFFFB;
}
.programlisting,
.screen
{
border: 1px solid gray;
background-color: #FAFFFB;
}
/* Table of contents */
.toc
{
border: 1px solid #DCDCDC;
border-bottom: 3px solid #9D9D9D;
border-right: 3px solid #9D9D9D;
background-color: #FAFFFB;
}
/* Table of contents */
.toc-main
{
border: 1px solid #DCDCDC;
border-bottom: 3px solid #9D9D9D;
border-right: 3px solid #9D9D9D;
background-color: #FAFFFB;
}
.informaltable table,
.table table
{
border: 1px solid #DCDCDC;
border-bottom: 3px solid #9D9D9D;
border-right: 3px solid #9D9D9D;
border-collapse: collapse;
background-color: #FAFFFB;
}
/* Tables */
div.informaltable table tr td,
div.table table tr td
{
border: 1px solid #DCDCDC;
background-color: #FAFFFB;
}
div.informaltable table tr th,
div.table table tr th
{
border: 1px solid #DCDCDC;
background-color: #FAFFFB;
}
/* Misc */
span.highlight
{
font-weight: bold;
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 374 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 358 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 722 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 336 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 490 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 334 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 449 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 318 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 259 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 264 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 370 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

View File

@@ -1,12 +0,0 @@
/*=============================================================================
Copyright (c) 2004 Joel de Guzman
Use, modification and distribution is subject to the Boost Software
License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
=============================================================================*/
PRE.synopsis {
background-color: #e0ffff;
border: thin solid blue;
padding: 1em
}

View File

@@ -0,0 +1,134 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="7.10"
Name="bench_static_vector"
ProjectGUID="{55E1C1C3-84FE-26A9-4A2E-D7901C32BA02}"
Keyword="Win32Proj">
<Platforms>
<Platform
Name="Win32"/>
</Platforms>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="../../Bin/Win32/Debug"
IntermediateDirectory="Debug/bench_static_vector"
ConfigurationType="1"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="../../../.."
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;BOOST_DATE_TIME_NO_LIB"
MinimalRebuild="TRUE"
ExceptionHandling="TRUE"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
TreatWChar_tAsBuiltInType="TRUE"
ForceConformanceInForLoopScope="FALSE"
UsePrecompiledHeader="0"
WarningLevel="4"
Detect64BitPortabilityProblems="TRUE"
DebugInformationFormat="3"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="winmm.lib"
OutputFile="$(OutDir)/bench_static_vector_d.exe"
LinkIncremental="1"
AdditionalLibraryDirectories="../../../../stage/lib"
GenerateDebugInformation="TRUE"
ProgramDatabaseFile="$(OutDir)/bench_static_vector.pdb"
SubSystem="1"
TargetMachine="1"
FixedBaseAddress="1"/>
<Tool
Name="VCMIDLTool"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="../../Bin/Win32/Release"
IntermediateDirectory="Release/bench_static_vector"
ConfigurationType="1"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories="../../../.."
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;BOOST_DATE_TIME_NO_LIB"
RuntimeLibrary="2"
TreatWChar_tAsBuiltInType="TRUE"
ForceConformanceInForLoopScope="FALSE"
UsePrecompiledHeader="0"
WarningLevel="4"
Detect64BitPortabilityProblems="TRUE"
DebugInformationFormat="0"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="winmm.lib"
OutputFile="$(OutDir)/bench_static_vector.exe"
LinkIncremental="1"
AdditionalLibraryDirectories="../../../../stage/lib"
GenerateDebugInformation="TRUE"
SubSystem="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{437B79CF-06A6-C58A-4312-37D42A302ADF}">
<File
RelativePath="..\..\bench\bench_static_vector.cpp">
</File>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

View File

@@ -55,6 +55,18 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "hash_table_test", "hash_tab
ProjectSection(ProjectDependencies) = postProject
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "throw_exception_test", "throw_exception_test.vcproj", "{5A8D91E0-FA57-284F-84FE-D3A6BA792002}"
ProjectSection(ProjectDependencies) = postProject
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "static_vector_test", "static_vector_test.vcproj", "{58E1C1C3-096A-84FE-4FA2-D6BA79201C02}"
ProjectSection(ProjectDependencies) = postProject
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "bench_static_vector", "bench_static_vector.vcproj", "{58E1C1C3-096A-84FE-4FA2-D6BA79201C02}"
ProjectSection(ProjectDependencies) = postProject
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfiguration) = preSolution
Debug = Debug
@@ -119,6 +131,18 @@ Global
{58CCE183-6092-48FE-A4F7-BA0D3A792606}.Debug.Build.0 = Debug|Win32
{58CCE183-6092-48FE-A4F7-BA0D3A792606}.Release.ActiveCfg = Release|Win32
{58CCE183-6092-48FE-A4F7-BA0D3A792606}.Release.Build.0 = Release|Win32
{5A8D91E0-FA57-284F-84FE-D3A6BA792002}.Debug.ActiveCfg = Debug|Win32
{5A8D91E0-FA57-284F-84FE-D3A6BA792002}.Debug.Build.0 = Debug|Win32
{5A8D91E0-FA57-284F-84FE-D3A6BA792002}.Release.ActiveCfg = Release|Win32
{5A8D91E0-FA57-284F-84FE-D3A6BA792002}.Release.Build.0 = Release|Win32
{58E1C1C3-096A-84FE-4FA2-D6BA79201C02}.Debug.ActiveCfg = Debug|Win32
{58E1C1C3-096A-84FE-4FA2-D6BA79201C02}.Debug.Build.0 = Debug|Win32
{58E1C1C3-096A-84F0-4FA2-D6BA79201C02}.Release.ActiveCfg = Release|Win32
{58E1C1C3-096A-84F0-4FA2-D6BA79201C02}.Release.Build.0 = Release|Win32
{58E1C1C3-096A-84F1-4FA2-D6BA79201C02}.Debug.ActiveCfg = Debug|Win32
{58E1C1C3-096A-84F1-4FA2-D6BA79201C02}.Debug.Build.0 = Debug|Win32
{58E1C1C3-096A-84F2-4FA2-D6BA79201C02}.Release.ActiveCfg = Release|Win32
{58E1C1C3-096A-84F2-4FA2-D6BA79201C02}.Release.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
EndGlobalSection

View File

@@ -95,96 +95,15 @@
<References>
</References>
<Files>
<Filter
Name="doc"
Filter="">
<File
RelativePath="..\..\doc\container.qbk">
</File>
<File
RelativePath="..\..\doc\index.idx">
</File>
<File
RelativePath="..\..\doc\Jamfile.v2">
</File>
</Filter>
<Filter
Name="example"
Filter="">
<File
RelativePath="..\..\example\doc_emplace.cpp">
</File>
<File
RelativePath="..\..\example\doc_move_containers.cpp">
</File>
<File
RelativePath="..\..\example\doc_recursive_containers.cpp">
</File>
<File
RelativePath="..\..\example\doc_type_erasure.cpp">
</File>
<File
RelativePath="..\..\example\Jamfile.v2">
</File>
</Filter>
<Filter
Name="test"
Filter="">
<File
RelativePath="..\..\test\check_equal_containers.hpp">
</File>
<File
RelativePath="..\..\test\dummy_test_allocator.hpp">
</File>
<File
RelativePath="..\..\test\emplace_test.hpp">
</File>
<File
RelativePath="..\..\test\expand_bwd_test_allocator.hpp">
</File>
<File
RelativePath="..\..\test\expand_bwd_test_template.hpp">
</File>
<File
RelativePath="..\..\test\forward_to_input_iterator.hpp">
</File>
<File
RelativePath="..\..\test\heap_allocator_v1.hpp">
</File>
<File
RelativePath="..\..\test\Jamfile.v2">
</File>
<File
RelativePath="..\..\test\list_test.hpp">
</File>
<File
RelativePath="..\..\test\map_test.hpp">
</File>
<File
RelativePath="..\..\test\movable_int.hpp">
</File>
<File
RelativePath="..\..\test\print_container.hpp">
</File>
<File
RelativePath="..\..\test\propagate_allocator_test.hpp">
</File>
<File
RelativePath="..\..\test\set_test.hpp">
</File>
<File
RelativePath="..\..\test\util.hpp">
</File>
<File
RelativePath="..\..\test\vector_test.hpp">
</File>
</Filter>
<Filter
Name="container"
Filter="">
<File
RelativePath="..\..\..\..\boost\container\allocator_traits.hpp">
</File>
<File
RelativePath="..\..\..\..\boost\container\container_exceptions.hpp">
</File>
<File
RelativePath="..\..\..\..\boost\container\container_fwd.hpp">
</File>
@@ -218,9 +137,15 @@
<File
RelativePath="..\..\..\..\boost\container\stable_vector.hpp">
</File>
<File
RelativePath="..\..\..\..\boost\container\static_vector.hpp">
</File>
<File
RelativePath="..\..\..\..\boost\container\string.hpp">
</File>
<File
RelativePath="..\..\..\..\boost\container\throw_exception.hpp">
</File>
<File
RelativePath="..\to-do.txt">
</File>
@@ -260,6 +185,9 @@
<File
RelativePath="..\..\..\..\boost\container\detail\function_detector.hpp">
</File>
<File
RelativePath="..\..\..\..\boost\container\detail\hash_table.hpp">
</File>
<File
RelativePath="..\..\..\..\boost\container\detail\iterators.hpp">
</File>
@@ -316,6 +244,116 @@
</File>
</Filter>
</Filter>
<Filter
Name="doc"
Filter="">
<File
RelativePath="..\..\doc\container.qbk">
</File>
<File
RelativePath="..\..\doc\index.idx">
</File>
<File
RelativePath="..\..\doc\Jamfile.v2">
</File>
</Filter>
<Filter
Name="example"
Filter="">
<File
RelativePath="..\..\example\doc_emplace.cpp">
</File>
<File
RelativePath="..\..\example\doc_move_containers.cpp">
</File>
<File
RelativePath="..\..\example\doc_recursive_containers.cpp">
</File>
<File
RelativePath="..\..\example\doc_type_erasure.cpp">
</File>
<File
RelativePath="..\..\example\Jamfile.v2">
</File>
</Filter>
<Filter
Name="test"
Filter="">
<File
RelativePath="..\..\test\check_equal_containers.hpp">
</File>
<File
RelativePath="..\..\test\dummy_test_allocator.hpp">
</File>
<File
RelativePath="..\..\test\emplace_test.hpp">
</File>
<File
RelativePath="..\..\test\expand_bwd_test_allocator.hpp">
</File>
<File
RelativePath="..\..\test\expand_bwd_test_template.hpp">
</File>
<File
RelativePath="..\..\test\forward_to_input_iterator.hpp">
</File>
<File
RelativePath="..\..\test\heap_allocator_v1.hpp">
</File>
<File
RelativePath="..\..\test\insert_test.hpp">
</File>
<File
RelativePath="..\..\test\Jamfile.v2">
</File>
<File
RelativePath="..\..\test\list_test.hpp">
</File>
<File
RelativePath="..\..\test\map_test.hpp">
</File>
<File
RelativePath="..\..\test\movable_int.hpp">
</File>
<File
RelativePath="..\..\test\print_container.hpp">
</File>
<File
RelativePath="..\..\test\propagate_allocator_test.hpp">
</File>
<File
RelativePath="..\..\test\set_test.hpp">
</File>
<File
RelativePath="..\..\test\static_vector_test.hpp">
</File>
<File
RelativePath="..\..\test\util.hpp">
</File>
<File
RelativePath="..\..\test\vector_test.hpp">
</File>
</Filter>
<Filter
Name="bench"
Filter="">
<File
RelativePath="..\..\bench\varray.hpp">
</File>
<Filter
Name="detail"
Filter="">
<File
RelativePath="..\..\bench\detail\varray.hpp">
</File>
<File
RelativePath="..\..\bench\detail\varray_concept.hpp">
</File>
<File
RelativePath="..\..\bench\detail\varray_util.hpp">
</File>
</Filter>
</Filter>
</Files>
<Globals>
</Globals>

View File

@@ -0,0 +1,139 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="7.10"
Name="static_vector_test"
ProjectGUID="{58E1C1C3-096A-84FE-4FA2-D6BA79201C02}"
Keyword="Win32Proj">
<Platforms>
<Platform
Name="Win32"/>
</Platforms>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="../../Bin/Win32/Debug"
IntermediateDirectory="Debug/static_vector_test"
ConfigurationType="1"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="../../../.."
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;BOOST_DATE_TIME_NO_LIB"
MinimalRebuild="TRUE"
ExceptionHandling="TRUE"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
TreatWChar_tAsBuiltInType="TRUE"
ForceConformanceInForLoopScope="FALSE"
UsePrecompiledHeader="0"
WarningLevel="4"
Detect64BitPortabilityProblems="TRUE"
DebugInformationFormat="3"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="winmm.lib"
OutputFile="$(OutDir)/static_vector_test_d.exe"
LinkIncremental="1"
AdditionalLibraryDirectories="../../../../stage/lib"
GenerateDebugInformation="TRUE"
ProgramDatabaseFile="$(OutDir)/static_vector_test.pdb"
SubSystem="1"
TargetMachine="1"
FixedBaseAddress="1"/>
<Tool
Name="VCMIDLTool"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="../../Bin/Win32/Release"
IntermediateDirectory="Release/static_vector_test"
ConfigurationType="1"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories="../../../.."
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;BOOST_DATE_TIME_NO_LIB"
RuntimeLibrary="2"
TreatWChar_tAsBuiltInType="TRUE"
ForceConformanceInForLoopScope="FALSE"
UsePrecompiledHeader="0"
WarningLevel="4"
Detect64BitPortabilityProblems="TRUE"
DebugInformationFormat="0"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="winmm.lib"
OutputFile="$(OutDir)/static_vector_test.exe"
LinkIncremental="1"
AdditionalLibraryDirectories="../../../../stage/lib"
GenerateDebugInformation="TRUE"
SubSystem="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4137B7CF-A066-4312-7AC5-32D732A37AAF}">
<File
RelativePath="..\..\test\static_vector_test.cpp">
</File>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl;inc;xsd"
UniqueIdentifier="{93815995-89BD-b043-5E8B-65FBE52E2AFB}">
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

View File

@@ -0,0 +1,134 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="7.10"
Name="throw_exception_test"
ProjectGUID="{5A8D91E0-FA57-284F-84FE-D3A6BA792002}"
Keyword="Win32Proj">
<Platforms>
<Platform
Name="Win32"/>
</Platforms>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="../../Bin/Win32/Debug"
IntermediateDirectory="Debug/throw_exception_test"
ConfigurationType="1"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="../../../.."
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;BOOST_DATE_TIME_NO_LIB"
MinimalRebuild="TRUE"
ExceptionHandling="TRUE"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
TreatWChar_tAsBuiltInType="TRUE"
ForceConformanceInForLoopScope="FALSE"
UsePrecompiledHeader="0"
WarningLevel="4"
Detect64BitPortabilityProblems="TRUE"
DebugInformationFormat="3"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="winmm.lib"
OutputFile="$(OutDir)/throw_exception_test_d.exe"
LinkIncremental="1"
AdditionalLibraryDirectories="../../../../stage/lib"
GenerateDebugInformation="TRUE"
ProgramDatabaseFile="$(OutDir)/throw_exception_test.pdb"
SubSystem="1"
TargetMachine="1"
FixedBaseAddress="1"/>
<Tool
Name="VCMIDLTool"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="../../Bin/Win32/Release"
IntermediateDirectory="Release/throw_exception_test"
ConfigurationType="1"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories="../../../.."
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;BOOST_DATE_TIME_NO_LIB"
RuntimeLibrary="2"
TreatWChar_tAsBuiltInType="TRUE"
ForceConformanceInForLoopScope="FALSE"
UsePrecompiledHeader="0"
WarningLevel="4"
Detect64BitPortabilityProblems="TRUE"
DebugInformationFormat="0"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="winmm.lib"
OutputFile="$(OutDir)/throw_exception_test.exe"
LinkIncremental="1"
AdditionalLibraryDirectories="../../../../stage/lib"
GenerateDebugInformation="TRUE"
SubSystem="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{A1735C4B-7AC5-3542-C626-3A2AF6C0D762}">
<File
RelativePath="..\..\test\throw_exception_test.cpp">
</File>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

View File

@@ -22,6 +22,7 @@
AdditionalIncludeDirectories="../../../.."
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;BOOST_DATE_TIME_NO_LIB"
MinimalRebuild="TRUE"
ExceptionHandling="TRUE"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
TreatWChar_tAsBuiltInType="TRUE"

View File

@@ -29,6 +29,7 @@
#include "emplace_test.hpp"
#include "propagate_allocator_test.hpp"
#include "vector_test.hpp"
#include <boost/detail/no_exceptions_support.hpp>
using namespace boost::container;
@@ -143,7 +144,7 @@ bool do_test()
typedef deque<IntType> MyCntDeque;
typedef std::deque<int> MyStdDeque;
const int max = 100;
try{
BOOST_TRY{
//Shared memory allocator must be always be initialized
//since it has no default constructor
MyCntDeque *cntdeque = new MyCntDeque;
@@ -206,6 +207,20 @@ bool do_test()
stddeque->insert(stddeque->end(), aux_vect2, aux_vect2 + 50);
if(!test::CheckEqualContainers(cntdeque, stddeque)) return false;
for(int i = 0; i < 50; ++i){
IntType move_me (i);
aux_vect[i] = boost::move(move_me);
}
for(int i = 0; i < 50; ++i){
aux_vect2[i] = i;
}
cntdeque->insert(cntdeque->begin()+cntdeque->size()
,boost::make_move_iterator(&aux_vect[0])
,boost::make_move_iterator(aux_vect + 50));
stddeque->insert(stddeque->begin()+stddeque->size(), aux_vect2, aux_vect2 + 50);
if(!test::CheckEqualContainers(cntdeque, stddeque)) return false;
for(int i = 0, j = static_cast<int>(cntdeque->size()); i < j; ++i){
cntdeque->erase(cntdeque->begin());
stddeque->erase(stddeque->begin());
@@ -268,10 +283,13 @@ bool do_test()
delete cntdeque;
delete stddeque;
}
catch(std::exception &ex){
BOOST_CATCH(std::exception &ex){
#ifndef BOOST_NO_EXCEPTIONS
std::cout << ex.what() << std::endl;
#endif
return false;
}
BOOST_CATCH_END
std::cout << std::endl << "Test OK!" << std::endl;
return true;

View File

@@ -26,11 +26,11 @@
#include <boost/container/detail/mpl.hpp>
#include <boost/container/detail/version_type.hpp>
#include <boost/container/detail/multiallocation_chain.hpp>
#include <boost/container/throw_exception.hpp>
#include <boost/move/utility.hpp>
#include <memory>
#include <algorithm>
#include <cstddef>
#include <stdexcept>
#include <cassert>
//!\file
@@ -314,15 +314,20 @@ class propagation_test_allocator
friend bool operator!=(const propagation_test_allocator &, const propagation_test_allocator &)
{ return false; }
void swap(propagation_test_allocator &r)
{
++this->swaps_; ++r.swaps_;
boost::container::swap_dispatch(this->id_, r.id_);
boost::container::swap_dispatch(this->ctr_copies_, r.ctr_copies_);
boost::container::swap_dispatch(this->ctr_moves_, r.ctr_moves_);
boost::container::swap_dispatch(this->assign_copies_, r.assign_copies_);
boost::container::swap_dispatch(this->assign_moves_, r.assign_moves_);
boost::container::swap_dispatch(this->swaps_, r.swaps_);
}
friend void swap(propagation_test_allocator &l, propagation_test_allocator &r)
{
++l.swaps_; ++r.swaps_;
container_detail::do_swap(l.id_, r.id_);
container_detail::do_swap(l.ctr_copies_, r.ctr_copies_);
container_detail::do_swap(l.ctr_moves_, r.ctr_moves_);
container_detail::do_swap(l.assign_copies_, r.assign_copies_);
container_detail::do_swap(l.assign_moves_, r.assign_moves_);
container_detail::do_swap(l.swaps_, r.swaps_);
l.swap(r);
}
unsigned int id_;

View File

@@ -19,6 +19,7 @@
#include <boost/container/detail/workaround.hpp>
#include <boost/container/container_fwd.hpp>
#include <boost/container/throw_exception.hpp>
#include <boost/container/detail/allocation_type.hpp>
#include <boost/assert.hpp>
#include <boost/container/detail/utilities.hpp>
@@ -26,7 +27,6 @@
#include <memory>
#include <algorithm>
#include <cstddef>
#include <stdexcept>
#include <cassert>
//!\file
@@ -112,9 +112,9 @@ class expand_bwd_test_allocator
friend void swap(self_t &alloc1, self_t &alloc2)
{
container_detail::do_swap(alloc1.mp_buffer, alloc2.mp_buffer);
container_detail::do_swap(alloc1.m_size, alloc2.m_size);
container_detail::do_swap(alloc1.m_offset, alloc2.m_offset);
boost::container::swap_dispatch(alloc1.mp_buffer, alloc2.mp_buffer);
boost::container::swap_dispatch(alloc1.m_size, alloc2.m_size);
boost::container::swap_dispatch(alloc1.m_offset, alloc2.m_offset);
}
//Experimental version 2 expand_bwd_test_allocator functions
@@ -146,8 +146,8 @@ class expand_bwd_test_allocator
return std::pair<pointer, bool>(mp_buffer, true);
}
else{
assert(0);
throw std::bad_alloc();
throw_bad_alloc();
return std::pair<pointer, bool>(mp_buffer, true);
}
}

View File

@@ -135,7 +135,7 @@ bool test_insert_with_expand_bwd()
for(int iteration = 0; iteration < Iterations; ++iteration)
{
value_type *memory = new value_type[MemorySize];
try {
BOOST_TRY {
std::vector<non_volatile_value_type> initial_data;
initial_data.resize(InitialSize[iteration]);
for(int i = 0; i < InitialSize[iteration]; ++i){
@@ -165,10 +165,11 @@ bool test_insert_with_expand_bwd()
return false;
}
}
catch(...){
BOOST_CATCH(...){
delete [](const_cast<non_volatile_value_type*>(memory));
throw;
BOOST_RETHROW;
}
BOOST_CATCH_END
delete [](const_cast<non_volatile_value_type*>(memory));
}
@@ -193,7 +194,7 @@ bool test_assign_with_expand_bwd()
for(int iteration = 0; iteration <Iterations; ++iteration)
{
value_type *memory = new value_type[MemorySize];
try {
BOOST_TRY {
//Create initial data
std::vector<non_volatile_value_type> initial_data;
initial_data.resize(InitialSize[iteration]);
@@ -227,10 +228,11 @@ bool test_assign_with_expand_bwd()
return false;
}
}
catch(...){
BOOST_CATCH(...){
delete [](const_cast<typename boost::remove_volatile<value_type>::type*>(memory));
throw;
BOOST_RETHROW;
}
BOOST_CATCH_END
delete [](const_cast<typename boost::remove_volatile<value_type>::type*>(memory));
}

View File

@@ -116,6 +116,9 @@ template class flat_multiset
, std::allocator<test::movable_and_copyable_int>
>;
//As flat container iterators are typedefs for vector::[const_]iterator,
//no need to explicit instantiate them
}} //boost::container

View File

@@ -28,7 +28,6 @@
#include <memory>
#include <algorithm>
#include <cstddef>
#include <stdexcept>
//!\file
//!Describes an heap_allocator_v1 that allocates portions of fixed size
@@ -134,7 +133,7 @@ class heap_allocator_v1
//!Swap segment manager. Does not throw. If each heap_allocator_v1 is placed in
//!different memory segments, the result is undefined.
friend void swap(self_t &alloc1, self_t &alloc2)
{ detail::do_swap(alloc1.mp_mngr, alloc2.mp_mngr); }
{ boost::container::boost::container::swap_dispatch(alloc1.mp_mngr, alloc2.mp_mngr); }
};
//!Equality test for same type of heap_allocator_v1

74
test/insert_test.hpp Normal file
View File

@@ -0,0 +1,74 @@
#ifndef BOOST_CONTAINER_TEST_INSERT_TEST_HPP
#define BOOST_CONTAINER_TEST_INSERT_TEST_HPP
// Copyright (C) 2013 Cromwell D. Enage
// 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 <deque>
#include <boost/detail/lightweight_test.hpp>
#include "check_equal_containers.hpp"
namespace boost {
namespace container {
namespace test {
template<class SeqContainer>
void
test_insert_range(
std::deque<int> &std_deque
, SeqContainer &seq_container
, std::deque<int> const& input_deque
, std::size_t index
)
{
BOOST_TEST(CheckEqualContainers(&std_deque, &seq_container));
std_deque.insert(
std_deque.begin() + index
, input_deque.begin()
, input_deque.end()
);
seq_container.insert(
seq_container.begin() + index
, input_deque.begin()
, input_deque.end()
);
BOOST_TEST(CheckEqualContainers(&std_deque, &seq_container));
}
template<class SeqContainer>
bool test_range_insertion()
{
int err_count = boost::report_errors();
typedef typename SeqContainer::value_type value_type;
std::deque<int> input_deque;
for (int element = -10; element < 10; ++element)
{
input_deque.push_back(element + 20);
}
for (std::size_t i = 0; i <= input_deque.size(); ++i)
{
std::deque<int> std_deque;
SeqContainer seq_container;
for (int element = -10; element < 10; ++element)
{
std_deque.push_back(element);
seq_container.push_back(value_type(element));
}
test_insert_range(std_deque, seq_container, input_deque, i);
}
return err_count == boost::report_errors();
}
} //namespace test {
} //namespace container {
} //namespace boost {
#endif //#ifndef BOOST_CONTAINER_TEST_INSERT_TEST_HPP

View File

@@ -32,6 +32,15 @@ template class boost::container::list<test::movable_and_copyable_int,
template class boost::container::list<test::movable_and_copyable_int,
std::allocator<test::movable_and_copyable_int> >;
namespace container_detail {
template class list_const_iterator
<int, intrusive_list_type< std::allocator<int> >::container_type::iterator >;
template class list_iterator
<int, intrusive_list_type< std::allocator<int> >::container_type::iterator>;
}
}}
typedef list<int> MyList;

View File

@@ -148,7 +148,7 @@ int list_test (bool copied_allocators_equal = true)
const int max = 100;
typedef list_push_data_function<DoublyLinked> push_data_t;
try{
BOOST_TRY{
MyBoostList *boostlist = new MyBoostList;
MyStdList *stdlist = new MyStdList;
@@ -338,9 +338,10 @@ int list_test (bool copied_allocators_equal = true)
delete boostlist;
delete stdlist;
}
catch(...){
throw;
BOOST_CATCH(...){
BOOST_RETHROW;
}
BOOST_CATCH_END
return 0;
}

View File

@@ -44,7 +44,7 @@ int map_test ()
typedef typename MyStdMap::value_type StdPairType;
const int max = 100;
try{
BOOST_TRY{
MyBoostMap *boostmap = new MyBoostMap;
MyStdMap *stdmap = new MyStdMap;
MyBoostMultiMap *boostmultimap = new MyBoostMultiMap;
@@ -179,14 +179,14 @@ int map_test ()
if(!CheckEqualPairContainers(boostmap, stdmap)) return 1;
if(!CheckEqualPairContainers(boostmultimap, stdmultimap)) return 1;
typename MyBoostMap::iterator it;
typename MyBoostMap::iterator it = boostmap->begin();
typename MyBoostMap::const_iterator cit = it;
(void)cit;
boostmap->erase(boostmap->begin()++);
stdmap->erase(stdmap->begin()++);
boostmultimap->erase(boostmultimap->begin()++);
stdmultimap->erase(stdmultimap->begin()++);
boostmap->erase(boostmap->begin());
stdmap->erase(stdmap->begin());
boostmultimap->erase(boostmultimap->begin());
stdmultimap->erase(stdmultimap->begin());
if(!CheckEqualPairContainers(boostmap, stdmap)) return 1;
if(!CheckEqualPairContainers(boostmultimap, stdmultimap)) return 1;
@@ -467,9 +467,10 @@ int map_test ()
delete boostmultimap;
delete stdmultimap;
}
catch(...){
throw;
BOOST_CATCH(...){
BOOST_RETHROW;
}
BOOST_CATCH_END
return 0;
}
@@ -485,7 +486,7 @@ int map_test_copyable ()
const int max = 100;
try{
BOOST_TRY{
MyBoostMap *boostmap = new MyBoostMap;
MyStdMap *stdmap = new MyStdMap;
MyBoostMultiMap *boostmultimap = new MyBoostMultiMap;
@@ -537,9 +538,10 @@ int map_test_copyable ()
delete stdmultimap;
}
}
catch(...){
throw;
BOOST_CATCH(...){
BOOST_RETHROW;
}
BOOST_CATCH_END
return 0;
}

View File

@@ -53,23 +53,26 @@ class movable_int
movable_int & operator= (int i)
{ this->m_int = i; return *this; }
bool operator ==(const movable_int &mi) const
{ return this->m_int == mi.m_int; }
~movable_int()
{ this->m_int = 0; }
bool operator !=(const movable_int &mi) const
{ return this->m_int != mi.m_int; }
friend bool operator ==(const movable_int &l, const movable_int &r)
{ return l.m_int == r.m_int; }
bool operator <(const movable_int &mi) const
{ return this->m_int < mi.m_int; }
friend bool operator !=(const movable_int &l, const movable_int &r)
{ return l.m_int != r.m_int; }
bool operator <=(const movable_int &mi) const
{ return this->m_int <= mi.m_int; }
friend bool operator <(const movable_int &l, const movable_int &r)
{ return l.m_int < r.m_int; }
bool operator >=(const movable_int &mi) const
{ return this->m_int >= mi.m_int; }
friend bool operator <=(const movable_int &l, const movable_int &r)
{ return l.m_int <= r.m_int; }
bool operator >(const movable_int &mi) const
{ return this->m_int > mi.m_int; }
friend bool operator >=(const movable_int &l, const movable_int &r)
{ return l.m_int >= r.m_int; }
friend bool operator >(const movable_int &l, const movable_int &r)
{ return l.m_int > r.m_int; }
int get_int() const
{ return m_int; }
@@ -84,6 +87,9 @@ class movable_int
int m_int;
};
inline movable_int produce_movable_int()
{ return movable_int(); }
template<class E, class T>
std::basic_ostream<E, T> & operator<<
(std::basic_ostream<E, T> & os, movable_int const & p)
@@ -93,7 +99,6 @@ std::basic_ostream<E, T> & operator<<
return os;
}
template<>
struct is_copyable<movable_int>
{
@@ -121,6 +126,9 @@ class movable_and_copyable_int
: m_int(mmi.m_int)
{ mmi.m_int = 0; }
~movable_and_copyable_int()
{ this->m_int = 0; }
movable_and_copyable_int &operator= (BOOST_COPY_ASSIGN_REF(movable_and_copyable_int) mi)
{ this->m_int = mi.m_int; return *this; }
@@ -130,23 +138,23 @@ class movable_and_copyable_int
movable_and_copyable_int & operator= (int i)
{ this->m_int = i; return *this; }
bool operator ==(const movable_and_copyable_int &mi) const
{ return this->m_int == mi.m_int; }
friend bool operator ==(const movable_and_copyable_int &l, const movable_and_copyable_int &r)
{ return l.m_int == r.m_int; }
bool operator !=(const movable_and_copyable_int &mi) const
{ return this->m_int != mi.m_int; }
friend bool operator !=(const movable_and_copyable_int &l, const movable_and_copyable_int &r)
{ return l.m_int != r.m_int; }
bool operator <(const movable_and_copyable_int &mi) const
{ return this->m_int < mi.m_int; }
friend bool operator <(const movable_and_copyable_int &l, const movable_and_copyable_int &r)
{ return l.m_int < r.m_int; }
bool operator <=(const movable_and_copyable_int &mi) const
{ return this->m_int <= mi.m_int; }
friend bool operator <=(const movable_and_copyable_int &l, const movable_and_copyable_int &r)
{ return l.m_int <= r.m_int; }
bool operator >=(const movable_and_copyable_int &mi) const
{ return this->m_int >= mi.m_int; }
friend bool operator >=(const movable_and_copyable_int &l, const movable_and_copyable_int &r)
{ return l.m_int >= r.m_int; }
bool operator >(const movable_and_copyable_int &mi) const
{ return this->m_int > mi.m_int; }
friend bool operator >(const movable_and_copyable_int &l, const movable_and_copyable_int &r)
{ return l.m_int > r.m_int; }
int get_int() const
{ return m_int; }
@@ -161,6 +169,9 @@ class movable_and_copyable_int
int m_int;
};
inline movable_and_copyable_int produce_movable_and_copyable_int()
{ return movable_and_copyable_int(); }
template<class E, class T>
std::basic_ostream<E, T> & operator<<
(std::basic_ostream<E, T> & os, movable_and_copyable_int const & p)
@@ -194,23 +205,29 @@ class copyable_int
copyable_int & operator= (int i)
{ this->m_int = i; return *this; }
bool operator ==(const copyable_int &mi) const
{ return this->m_int == mi.m_int; }
copyable_int & operator= (const copyable_int &ci)
{ this->m_int = ci.m_int; return *this; }
bool operator !=(const copyable_int &mi) const
{ return this->m_int != mi.m_int; }
~copyable_int()
{ this->m_int = 0; }
bool operator <(const copyable_int &mi) const
{ return this->m_int < mi.m_int; }
friend bool operator ==(const copyable_int &l, const copyable_int &r)
{ return l.m_int == r.m_int; }
bool operator <=(const copyable_int &mi) const
{ return this->m_int <= mi.m_int; }
friend bool operator !=(const copyable_int &l, const copyable_int &r)
{ return l.m_int != r.m_int; }
bool operator >=(const copyable_int &mi) const
{ return this->m_int >= mi.m_int; }
friend bool operator <(const copyable_int &l, const copyable_int &r)
{ return l.m_int < r.m_int; }
bool operator >(const copyable_int &mi) const
{ return this->m_int > mi.m_int; }
friend bool operator <=(const copyable_int &l, const copyable_int &r)
{ return l.m_int <= r.m_int; }
friend bool operator >=(const copyable_int &l, const copyable_int &r)
{ return l.m_int >= r.m_int; }
friend bool operator >(const copyable_int &l, const copyable_int &r)
{ return l.m_int > r.m_int; }
int get_int() const
{ return m_int; }
@@ -225,6 +242,9 @@ class copyable_int
int m_int;
};
inline copyable_int produce_copyable_int()
{ return copyable_int(); }
template<class E, class T>
std::basic_ostream<E, T> & operator<<
(std::basic_ostream<E, T> & os, copyable_int const & p)
@@ -254,6 +274,9 @@ class non_copymovable_int
: m_int(a)
{}
~non_copymovable_int()
{ m_int = 0; }
bool operator ==(const non_copymovable_int &mi) const
{ return this->m_int == mi.m_int; }

View File

@@ -143,20 +143,20 @@ int set_test ()
return 1;
}
typename MyBoostSet::iterator it;
typename MyBoostSet::iterator it = boostset->begin();
typename MyBoostSet::const_iterator cit = it;
(void)cit;
boostset->erase(boostset->begin()++);
stdset->erase(stdset->begin()++);
boostmultiset->erase(boostmultiset->begin()++);
stdmultiset->erase(stdmultiset->begin()++);
boostset->erase(boostset->begin());
stdset->erase(stdset->begin());
boostmultiset->erase(boostmultiset->begin());
stdmultiset->erase(stdmultiset->begin());
if(!CheckEqualContainers(boostset, stdset)){
std::cout << "Error in boostset->erase(boostset->begin()++)" << std::endl;
std::cout << "Error in boostset->erase(boostset->begin())" << std::endl;
return 1;
}
if(!CheckEqualContainers(boostmultiset, stdmultiset)){
std::cout << "Error in boostmultiset->erase(boostmultiset->begin()++)" << std::endl;
std::cout << "Error in boostmultiset->erase(boostmultiset->begin())" << std::endl;
return 1;
}
@@ -443,7 +443,7 @@ int set_test_copyable ()
typedef typename MyBoostSet::value_type IntType;
const int max = 100;
try{
BOOST_TRY{
//Shared memory allocator must be always be initialized
//since it has no default constructor
MyBoostSet *boostset = new MyBoostSet;
@@ -492,9 +492,10 @@ int set_test_copyable ()
delete boostset;
delete boostmultiset;
}
catch(...){
throw;
BOOST_CATCH(...){
BOOST_RETHROW;
}
BOOST_CATCH_END
return 0;
}

View File

@@ -30,6 +30,16 @@ template class boost::container::slist<test::movable_and_copyable_int,
template class boost::container::slist<test::movable_and_copyable_int,
std::allocator<test::movable_and_copyable_int> >;
namespace container_detail {
template class slist_const_iterator
<int, intrusive_slist_type< std::allocator<int> >::container_type::iterator >;
template class slist_iterator
<int, intrusive_slist_type< std::allocator<int> >::container_type::iterator>;
}
}}
typedef slist<int> MyList;

View File

@@ -39,6 +39,13 @@ template class stable_vector<test::movable_and_copyable_int,
template class stable_vector<test::movable_and_copyable_int,
std::allocator<test::movable_and_copyable_int> >;
namespace stable_vector_detail{
template class iterator< int, int &, int *>;
template class iterator< int, const int &, const int *>;
}
}}
class recursive_vector

733
test/static_vector_test.cpp Normal file
View File

@@ -0,0 +1,733 @@
// Boost.Container static_vector
// Unit Test
// Copyright (c) 2012-2013 Adam Wulkiewicz, Lodz, Poland.
// Copyright (c) 2012-2013 Andrew Hundt.
// Use, modification and distribution is subject to the Boost Software License,
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#include <boost/container/detail/config_begin.hpp>
#include <boost/detail/lightweight_test.hpp>
#include <boost/detail/no_exceptions_support.hpp>
// TODO: Disable parts of the unit test that should not run when BOOST_NO_EXCEPTIONS
// if exceptions are enabled there must be a user defined throw_exception function
#ifdef BOOST_NO_EXCEPTIONS
namespace boost {
void throw_exception(std::exception const &){}; // user defined
} // namespace boost
#endif // BOOST_NO_EXCEPTIONS
#include <vector>
#include <list>
#include <boost/container/vector.hpp>
#include <boost/container/stable_vector.hpp>
#include "static_vector_test.hpp"
namespace boost {
namespace container {
//Explicit instantiation to detect compilation errors
template class boost::container::static_vector<int, 10>;
}}
template <typename T, size_t N>
void test_ctor_ndc()
{
static_vector<T, N> s;
BOOST_TEST_EQ(s.size() , 0u);
BOOST_TEST(s.capacity() == N);
BOOST_TEST_THROWS( s.at(0u), std::out_of_range );
}
template <typename T, size_t N>
void test_ctor_nc(size_t n)
{
static_vector<T, N> s(n);
BOOST_TEST(s.size() == n);
BOOST_TEST(s.capacity() == N);
BOOST_TEST_THROWS( s.at(n), std::out_of_range );
if ( 1 < n )
{
T val10(10);
s[0] = val10;
BOOST_TEST(T(10) == s[0]);
BOOST_TEST(T(10) == s.at(0));
T val20(20);
s.at(1) = val20;
BOOST_TEST(T(20) == s[1]);
BOOST_TEST(T(20) == s.at(1));
}
}
template <typename T, size_t N>
void test_ctor_nd(size_t n, T const& v)
{
static_vector<T, N> s(n, v);
BOOST_TEST(s.size() == n);
BOOST_TEST(s.capacity() == N);
BOOST_TEST_THROWS( s.at(n), std::out_of_range );
if ( 1 < n )
{
BOOST_TEST(v == s[0]);
BOOST_TEST(v == s.at(0));
BOOST_TEST(v == s[1]);
BOOST_TEST(v == s.at(1));
s[0] = T(10);
BOOST_TEST(T(10) == s[0]);
BOOST_TEST(T(10) == s.at(0));
s.at(1) = T(20);
BOOST_TEST(T(20) == s[1]);
BOOST_TEST(T(20) == s.at(1));
}
}
template <typename T, size_t N>
void test_resize_nc(size_t n)
{
static_vector<T, N> s;
s.resize(n);
BOOST_TEST(s.size() == n);
BOOST_TEST(s.capacity() == N);
BOOST_TEST_THROWS( s.at(n), std::out_of_range );
if ( 1 < n )
{
T val10(10);
s[0] = val10;
BOOST_TEST(T(10) == s[0]);
BOOST_TEST(T(10) == s.at(0));
T val20(20);
s.at(1) = val20;
BOOST_TEST(T(20) == s[1]);
BOOST_TEST(T(20) == s.at(1));
}
}
template <typename T, size_t N>
void test_resize_nd(size_t n, T const& v)
{
static_vector<T, N> s;
s.resize(n, v);
BOOST_TEST(s.size() == n);
BOOST_TEST(s.capacity() == N);
BOOST_TEST_THROWS( s.at(n), std::out_of_range );
if ( 1 < n )
{
BOOST_TEST(v == s[0]);
BOOST_TEST(v == s.at(0));
BOOST_TEST(v == s[1]);
BOOST_TEST(v == s.at(1));
s[0] = T(10);
BOOST_TEST(T(10) == s[0]);
BOOST_TEST(T(10) == s.at(0));
s.at(1) = T(20);
BOOST_TEST(T(20) == s[1]);
BOOST_TEST(T(20) == s.at(1));
}
}
template <typename T, size_t N>
void test_push_back_nd()
{
static_vector<T, N> s;
BOOST_TEST(s.size() == 0);
BOOST_TEST_THROWS( s.at(0), std::out_of_range );
for ( size_t i = 0 ; i < N ; ++i )
{
T t(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(0) == s.front());
BOOST_TEST(T(i) == *(s.data() + i));
}
}
template <typename T, size_t N>
void test_pop_back_nd()
{
static_vector<T, N> s;
for ( size_t i = 0 ; i < N ; ++i )
{
T t(i);
s.push_back(t);
}
for ( size_t i = N ; i > 1 ; --i )
{
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(0) == s.front());
}
}
template <typename It1, typename It2>
void test_compare_ranges(It1 first1, It1 last1, It2 first2, It2 last2)
{
BOOST_TEST(std::distance(first1, last1) == std::distance(first2, last2));
for ( ; first1 != last1 && first2 != last2 ; ++first1, ++first2 )
BOOST_TEST(*first1 == *first2);
}
template <typename T, size_t N, typename C>
void test_copy_and_assign(C const& c)
{
{
static_vector<T, N> s(c.begin(), c.end());
BOOST_TEST(s.size() == c.size());
test_compare_ranges(s.begin(), s.end(), c.begin(), c.end());
}
{
static_vector<T, N> s;
BOOST_TEST(0 == s.size());
s.assign(c.begin(), c.end());
BOOST_TEST(s.size() == c.size());
test_compare_ranges(s.begin(), s.end(), c.begin(), c.end());
}
}
template <typename T, size_t N>
void test_copy_and_assign_nd(T const& val)
{
static_vector<T, N> s;
std::vector<T> v;
std::list<T> l;
for ( size_t i = 0 ; i < N ; ++i )
{
T t(i);
s.push_back(t);
v.push_back(t);
l.push_back(t);
}
// copy ctor
{
static_vector<T, N> s1(s);
BOOST_TEST(s.size() == s1.size());
test_compare_ranges(s.begin(), s.end(), s1.begin(), s1.end());
}
// copy assignment
{
static_vector<T, N> s1;
BOOST_TEST(0 == s1.size());
s1 = s;
BOOST_TEST(s.size() == s1.size());
test_compare_ranges(s.begin(), s.end(), s1.begin(), s1.end());
}
// ctor(Iter, Iter) and assign(Iter, Iter)
test_copy_and_assign<T, N>(s);
test_copy_and_assign<T, N>(v);
test_copy_and_assign<T, N>(l);
// assign(N, V)
{
static_vector<T, N> s1(s);
test_compare_ranges(s.begin(), s.end(), s1.begin(), s1.end());
std::vector<T> a(N, val);
s1.assign(N, val);
test_compare_ranges(a.begin(), a.end(), s1.begin(), s1.end());
}
stable_vector<T> bsv(s.begin(), s.end());
vector<T> bv(s.begin(), s.end());
test_copy_and_assign<T, N>(bsv);
test_copy_and_assign<T, N>(bv);
}
template <typename T, size_t N>
void test_iterators_nd()
{
static_vector<T, N> s;
std::vector<T> v;
for ( size_t i = 0 ; i < N ; ++i )
{
s.push_back(T(i));
v.push_back(T(i));
}
test_compare_ranges(s.begin(), s.end(), v.begin(), v.end());
test_compare_ranges(s.rbegin(), s.rend(), v.rbegin(), v.rend());
s.assign(v.rbegin(), v.rend());
test_compare_ranges(s.begin(), s.end(), v.rbegin(), v.rend());
test_compare_ranges(s.rbegin(), s.rend(), v.begin(), v.end());
}
template <typename T, size_t N>
void test_erase_nd()
{
static_vector<T, N> s;
typedef typename static_vector<T, N>::iterator It;
for ( size_t i = 0 ; i < N ; ++i )
s.push_back(T(i));
// erase(pos)
{
for ( size_t i = 0 ; i < N ; ++i )
{
static_vector<T, N> s1(s);
It it = s1.erase(s1.begin() + i);
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));
for ( size_t j = i+1 ; j < N ; ++j )
BOOST_TEST(s1[j-1] == T(j));
}
}
// erase(first, last)
{
size_t n = N/3;
for ( size_t i = 0 ; i <= N ; ++i )
{
static_vector<T, N> s1(s);
size_t removed = i + n < N ? n : N - i;
It it = s1.erase(s1.begin() + i, s1.begin() + i + removed);
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));
for ( size_t j = i+n ; j < N ; ++j )
BOOST_TEST(s1[j-n] == T(j));
}
}
}
template <typename T, size_t N, typename SV, typename C>
void test_insert(SV const& s, C const& c)
{
size_t h = N/2;
size_t n = size_t(h/1.5f);
for ( size_t i = 0 ; i <= h ; ++i )
{
static_vector<T, N> s1(s);
typename C::const_iterator it = c.begin();
std::advance(it, n);
typename static_vector<T, N>::iterator
it1 = s1.insert(s1.begin() + i, c.begin(), it);
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));
for ( size_t j = 0 ; j < n ; ++j )
BOOST_TEST(s1[j+i] == T(100 + j));
for ( size_t j = 0 ; j < h-i ; ++j )
BOOST_TEST(s1[j+i+n] == T(j+i));
}
}
template <typename T, size_t N>
void test_insert_nd(T const& val)
{
size_t h = N/2;
static_vector<T, N> s, ss;
std::vector<T> v;
std::list<T> l;
typedef typename static_vector<T, N>::iterator It;
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));
}
// insert(pos, val)
{
for ( size_t i = 0 ; i <= h ; ++i )
{
static_vector<T, N> s1(s);
It it = s1.insert(s1.begin() + i, 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[i] == val);
for ( size_t j = 0 ; j < h-i ; ++j )
BOOST_TEST(s1[j+i+1] == T(j+i));
}
}
// insert(pos, n, val)
{
size_t n = size_t(h/1.5f);
for ( size_t i = 0 ; i <= h ; ++i )
{
static_vector<T, N> s1(s);
It it = s1.insert(s1.begin() + i, n, 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));
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));
}
}
// insert(pos, first, last)
test_insert<T, N>(s, ss);
test_insert<T, N>(s, v);
test_insert<T, N>(s, l);
stable_vector<T> bsv(ss.begin(), ss.end());
vector<T> bv(ss.begin(), ss.end());
test_insert<T, N>(s, bv);
test_insert<T, N>(s, bsv);
}
template <typename T>
void test_capacity_0_nd()
{
static_vector<T, 10> v(5u, T(0));
static_vector<T, 0 > s;
BOOST_TEST(s.size() == 0);
BOOST_TEST(s.capacity() == 0);
BOOST_TEST_THROWS(s.at(0), std::out_of_range);
BOOST_TEST_THROWS(s.resize(5u, T(0)), std::bad_alloc);
BOOST_TEST_THROWS(s.push_back(T(0)), std::bad_alloc);
BOOST_TEST_THROWS(s.insert(s.end(), T(0)), std::bad_alloc);
BOOST_TEST_THROWS(s.insert(s.end(), 5u, T(0)), std::bad_alloc);
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(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);
}
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));
BOOST_TEST_THROWS(s.resize(N, T(0)), std::bad_alloc);
BOOST_TEST_THROWS(s.push_back(T(0)), std::bad_alloc);
BOOST_TEST_THROWS(s.insert(s.end(), T(0)), std::bad_alloc);
BOOST_TEST_THROWS(s.insert(s.end(), N, T(0)), std::bad_alloc);
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, T(0)), std::bad_alloc);
}
template <typename T, size_t N>
void test_swap_and_move_nd()
{
{
static_vector<T, N> v1, v2, v3, v4;
static_vector<T, N> s1, s2;
static_vector<T, N> s4;
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));
}
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.swap(v1);
s2 = boost::move(v2);
static_vector<T, N> s3(boost::move(v3));
s4.swap(v4);
BOOST_TEST(v1.size() == N/2);
BOOST_TEST(s1.size() == N);
//iG moving does not imply emptying source
//BOOST_TEST(v2.size() == 0);
BOOST_TEST(s2.size() == N);
//iG moving does not imply emptying source
//BOOST_TEST(v3.size() == 0);
BOOST_TEST(s3.size() == N);
BOOST_TEST(v4.size() == N/2);
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));
}
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));
}
}
{
static_vector<T, N> v1, v2, v3;
static_vector<T, N/2> s1, s2;
for (size_t i = 0 ; i < N/2 ; ++i )
{
v1.push_back(T(i));
v2.push_back(T(i));
v3.push_back(T(i));
}
for (size_t i = 0 ; i < N/3 ; ++i )
{
s1.push_back(T(100 + i));
s2.push_back(T(100 + i));
}
s1.swap(v1);
s2 = boost::move(v2);
static_vector<T, N/2> s3(boost::move(v3));
BOOST_TEST(v1.size() == N/3);
BOOST_TEST(s1.size() == N/2);
//iG moving does not imply emptying source
//BOOST_TEST(v2.size() == 0);
BOOST_TEST(s2.size() == N/2);
//iG moving does not imply emptying source
//BOOST_TEST(v3.size() == 0);
BOOST_TEST(s3.size() == N/2);
for (size_t i = 0 ; i < N/3 ; ++i )
BOOST_TEST(v1[i] == T(100 + 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));
}
}
{
typedef static_vector<T, N/2> small_vector_t;
static_vector<T, N> v(N, T(0));
small_vector_t s(N/2, T(1));
BOOST_TEST_THROWS(s.swap(v), std::bad_alloc);
v.resize(N, T(0));
BOOST_TEST_THROWS(s = boost::move(v), std::bad_alloc);
v.resize(N, T(0));
BOOST_TEST_THROWS(small_vector_t s2(boost::move(v)), std::bad_alloc);
}
}
template <typename T, size_t N>
void test_emplace_0p()
{
//emplace_back()
{
static_vector<T, N> v;
for (int i = 0 ; i < int(N) ; ++i )
v.emplace_back();
BOOST_TEST(v.size() == N);
BOOST_TEST_THROWS(v.emplace_back(), std::bad_alloc);
}
}
template <typename T, size_t N>
void test_emplace_2p()
{
//emplace_back(pos, int, int)
{
static_vector<T, N> v;
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(v.size() == N);
for (int i = 0 ; i < int(N) ; ++i )
BOOST_TEST(v[i] == T(i, 100 + i));
}
// emplace(pos, int, int)
{
typedef typename static_vector<T, N>::iterator It;
int h = N / 2;
static_vector<T, N> v;
for ( int i = 0 ; i < h ; ++i )
v.emplace_back(i, 100 + i);
for ( int i = 0 ; i <= h ; ++i )
{
static_vector<T, N> vv(v);
It it = vv.emplace(vv.begin() + i, i+100, i+200);
BOOST_TEST(vv.begin() + i == it);
BOOST_TEST(vv.size() == size_t(h+1));
for ( int j = 0 ; j < i ; ++j )
BOOST_TEST(vv[j] == T(j, j+100));
BOOST_TEST(vv[i] == T(i+100, i+200));
for ( int j = 0 ; j < h-i ; ++j )
BOOST_TEST(vv[j+i+1] == T(j+i, j+i+100));
}
}
}
template <typename T, size_t N>
void test_sv_elem(T const& t)
{
typedef static_vector<T, N> V;
static_vector<V, N> v;
v.push_back(V(N/2, t));
V vvv(N/2, t);
v.push_back(boost::move(vvv));
v.insert(v.begin(), V(N/2, t));
v.insert(v.end(), V(N/2, t));
v.emplace_back(N/2, t);
}
int main(int, char* [])
{
using boost::container::test::movable_and_copyable_int;
using boost::container::test::produce_movable_and_copyable_int;
BOOST_TEST(counting_value::count() == 0);
test_ctor_ndc<int, 10>();
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>();
BOOST_TEST(counting_value::count() == 0);
test_emplace_2p<counting_value, 10>();
BOOST_TEST(counting_value::count() == 0);
test_sv_elem<int, 10>(50);
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));
return boost::report_errors();
}
#include <boost/container/detail/config_end.hpp>

View File

@@ -0,0 +1,99 @@
// Boost.Container static_vector
// Unit Test
// Copyright (c) 2012-2013 Adam Wulkiewicz, Lodz, Poland.
// Copyright (c) 2012-2013 Andrew Hundt.
// Use, modification and distribution is subject to the Boost Software License,
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_CONTAINER_TEST_STATIC_VECTOR_TEST_HPP
#define BOOST_CONTAINER_TEST_STATIC_VECTOR_TEST_HPP
#include <boost/container/static_vector.hpp>
#include <boost/shared_ptr.hpp>
#include "movable_int.hpp"
using namespace boost::container;
class value_ndc
{
public:
explicit value_ndc(int a) : aa(a) {}
~value_ndc() {}
bool operator==(value_ndc const& v) const { return aa == v.aa; }
bool operator<(value_ndc const& v) const { return aa < v.aa; }
private:
value_ndc(value_ndc const&) {}
value_ndc & operator=(value_ndc const&) { return *this; }
int aa;
};
class value_nd
{
public:
explicit value_nd(int a) : aa(a) {}
~value_nd() {}
bool operator==(value_nd const& v) const { return aa == v.aa; }
bool operator<(value_nd const& v) const { return aa < v.aa; }
private:
int aa;
};
class value_nc
{
public:
explicit value_nc(int a = 0) : aa(a) {}
~value_nc() {}
bool operator==(value_nc const& v) const { return aa == v.aa; }
bool operator<(value_nc const& v) const { return aa < v.aa; }
private:
value_nc(value_nc const&) {}
value_nc & operator=(value_ndc const&) { return *this; }
int aa;
};
class counting_value
{
BOOST_COPYABLE_AND_MOVABLE(counting_value)
public:
explicit counting_value(int a = 0, int b = 0) : aa(a), bb(b) { ++c(); }
counting_value(counting_value const& v) : aa(v.aa), bb(v.bb) { ++c(); }
counting_value(BOOST_RV_REF(counting_value) p) : aa(p.aa), bb(p.bb) { p.aa = 0; p.bb = 0; ++c(); } // Move constructor
counting_value& operator=(BOOST_RV_REF(counting_value) p) { aa = p.aa; p.aa = 0; bb = p.bb; p.bb = 0; return *this; } // Move assignment
counting_value& operator=(BOOST_COPY_ASSIGN_REF(counting_value) p) { aa = p.aa; bb = p.bb; return *this; } // Copy assignment
~counting_value() { --c(); }
bool operator==(counting_value const& v) const { return aa == v.aa && bb == v.bb; }
bool operator<(counting_value const& v) const { return aa < v.aa || ( aa == v.aa && bb < v.bb ); }
static size_t count() { return c(); }
private:
static size_t & c() { static size_t co = 0; return co; }
int aa, bb;
};
namespace boost {
template <>
struct has_nothrow_move<counting_value>
{
static const bool value = true;
};
}
class shptr_value
{
typedef boost::shared_ptr<int> Ptr;
public:
explicit shptr_value(int a = 0) : m_ptr(new int(a)) {}
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

@@ -0,0 +1,62 @@
//////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2012-2013. Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/container for documentation.
//
//////////////////////////////////////////////////////////////////////////////
#define BOOST_CONTAINER_USER_DEFINED_THROW_CALLBACKS
#include <boost/container/detail/config_begin.hpp>
#include <boost/container/throw_exception.hpp>
#include <boost/detail/lightweight_test.hpp>
using namespace boost::container;
static bool bad_alloc_called = false;
static bool out_of_range_called = false;
static bool length_error_called = false;
static bool logic_error_called = false;
static bool runtime_error_called = false;
//User defined throw implementations
namespace boost {
namespace container {
void throw_bad_alloc()
{ bad_alloc_called = true; }
void throw_out_of_range(const char* str)
{ (void)str; out_of_range_called = true; }
void throw_length_error(const char* str)
{ (void)str; length_error_called = true; }
void throw_logic_error(const char* str)
{ (void)str; logic_error_called = true; }
void throw_runtime_error(const char* str)
{ (void)str; runtime_error_called = true; }
}} //boost::container
int main()
{
//Check user-defined throw callbacks are called
throw_bad_alloc();
BOOST_TEST(bad_alloc_called == true);
throw_out_of_range("dummy");
BOOST_TEST(out_of_range_called == true);
throw_length_error("dummy");
BOOST_TEST(length_error_called == true);
throw_logic_error("dummy");
BOOST_TEST(logic_error_called == true);
throw_runtime_error("dummy");
BOOST_TEST(runtime_error_called == true);
return ::boost::report_errors();
}
#include <boost/container/detail/config_end.hpp>

View File

@@ -39,6 +39,17 @@ template class boost::container::vector<test::movable_and_copyable_int,
template class boost::container::vector<test::movable_and_copyable_int,
std::allocator<test::movable_and_copyable_int> >;
namespace container_detail {
#ifndef BOOST_CONTAINER_VECTOR_ITERATOR_IS_POINTER
template class vector_const_iterator<int*>;
template class vector_iterator<int*>;
#endif //BOOST_CONTAINER_VECTOR_ITERATOR_IS_POINTER
}
}}
int test_expand_bwd()

View File

@@ -30,6 +30,8 @@
#include "input_from_forward_iterator.hpp"
#include <boost/move/utility.hpp>
#include <boost/move/iterator.hpp>
#include <boost/detail/no_exceptions_support.hpp>
#include "insert_test.hpp"
namespace boost{
namespace container {
@@ -79,6 +81,17 @@ bool vector_copyable_only(V1 *boostvector, V2 *stdvector, boost::container::cont
stdvector->push_back(int(3));
if(!test::CheckEqualContainers(boostvector, stdvector)) return false;
}
{
V1 *pv1 = new V1(*boostvector);
V2 *pv2 = new V2(*stdvector);
boostvector->clear();
stdvector->clear();
boostvector->assign(pv1->begin(), pv1->end());
stdvector->assign(pv2->begin(), pv2->end());
if(!test::CheckEqualContainers(boostvector, stdvector)) return 1;
delete pv1;
delete pv2;
}
return true;
}
@@ -90,8 +103,12 @@ int vector_test()
typedef typename MyBoostVector::value_type IntType;
const int max = 100;
if(!test_range_insertion<MyBoostVector>()){
return 1;
}
{
try{
BOOST_TRY{
MyBoostVector *boostvector = new MyBoostVector;
MyStdVector *stdvector = new MyStdVector;
boostvector->resize(100);
@@ -160,38 +177,38 @@ int vector_test()
IntType aux_vect[50];
for(int i = 0; i < 50; ++i){
IntType new_int(-2);
IntType new_int(-i);
aux_vect[i] = boost::move(new_int);
}
int aux_vect2[50];
for(int i = 0; i < 50; ++i){
aux_vect2[i] = -2;
aux_vect2[i] = -i;
}
typename MyBoostVector::size_type old_size = boostvector->size();
typename MyBoostVector::iterator insert_it =
boostvector->insert(boostvector->begin() + old_size
boostvector->insert(boostvector->begin() + old_size/2
,boost::make_move_iterator(&aux_vect[0])
,boost::make_move_iterator(aux_vect + 50));
if(boostvector->begin() + old_size != insert_it) return 1;
stdvector->insert(stdvector->begin() + old_size, aux_vect2, aux_vect2 + 50);
if(boostvector->begin() + old_size/2 != insert_it) return 1;
stdvector->insert(stdvector->begin() + old_size/2, aux_vect2, aux_vect2 + 50);
if(!test::CheckEqualContainers(boostvector, stdvector)) return 1;
for(int i = 0; i < 50; ++i){
IntType new_int(-3);
IntType new_int(-i);
aux_vect[i] = boost::move(new_int);
}
for(int i = 0; i < 50; ++i){
aux_vect2[i] = -3;
aux_vect2[i] = -i;
}
old_size = boostvector->size();
//Now try with input iterators instead
insert_it = boostvector->insert(boostvector->begin() + old_size
insert_it = boostvector->insert(boostvector->begin() + old_size/2
,boost::make_move_iterator(make_input_from_forward_iterator(&aux_vect[0]))
,boost::make_move_iterator(make_input_from_forward_iterator(aux_vect + 50))
);
if(boostvector->begin() + old_size != insert_it) return 1;
stdvector->insert(stdvector->begin() + old_size, aux_vect2, aux_vect2 + 50);
if(boostvector->begin() + old_size/2 != insert_it) return 1;
stdvector->insert(stdvector->begin() + old_size/2, aux_vect2, aux_vect2 + 50);
if(!test::CheckEqualContainers(boostvector, stdvector)) return 1;
}
/* //deque has no reserve
@@ -215,7 +232,12 @@ int vector_test()
stdvector->push_back(int(1));
if(!test::CheckEqualContainers(boostvector, stdvector)) return 1;
}
{ //push_back with enough capacity
{ //test back()
const IntType test_this(1);
if(test_this != boostvector->back()) return 1;
}
{ //pop_back with enough capacity
boostvector->pop_back();
boostvector->pop_back();
stdvector->pop_back();
@@ -292,11 +314,15 @@ int vector_test()
delete stdvector;
delete boostvector;
}
catch(std::exception &ex){
BOOST_CATCH(std::exception &ex){
#ifndef BOOST_NO_EXCEPTIONS
std::cout << ex.what() << std::endl;
#endif
return 1;
}
BOOST_CATCH_END
}
std::cout << std::endl << "Test OK!" << std::endl;
return 0;
}
@@ -308,4 +334,3 @@ int vector_test()
#include <boost/container/detail/config_end.hpp>
#endif //BOOST_CONTAINER_TEST_VECTOR_TEST_HEADER