|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r82134 - in sandbox/static_vector: boost/container test
From: adam.wulkiewicz_at_[hidden]
Date: 2012-12-20 23:00:41
Author: awulkiew
Date: 2012-12-20 23:00:40 EST (Thu, 20 Dec 2012)
New Revision: 82134
URL: http://svn.boost.org/trac/boost/changeset/82134
Log:
In previous commit:
Added static_vector_traits
Added default_strategy which uses asserts in check_capacity()
Swap version is choosen in traits.
In this commit:
Errors fixed in exceptions test - test bad_alloc_strategy implemented and used
Text files modified:
sandbox/static_vector/boost/container/static_vector.hpp | 8 ++++----
sandbox/static_vector/test/static_vector.cpp | 24 +++++++++++++++++-------
2 files changed, 21 insertions(+), 11 deletions(-)
Modified: sandbox/static_vector/boost/container/static_vector.hpp
==============================================================================
--- sandbox/static_vector/boost/container/static_vector.hpp (original)
+++ sandbox/static_vector/boost/container/static_vector.hpp 2012-12-20 23:00:40 EST (Thu, 20 Dec 2012)
@@ -33,11 +33,13 @@
namespace boost { namespace container {
// Forward declaration
-template <typename Value, std::size_t Capacity, typename StoredSizeType>
+template <typename Value, std::size_t Capacity, typename Strategy>
class static_vector;
namespace static_vector_detail {
+// TODO - remove size_type from here and allow setting it only in traits?
+
template <typename SizeType = std::size_t>
struct default_strategy
{
@@ -47,8 +49,6 @@
static void check_capacity(container::static_vector<V, Capacity, S> const&, std::size_t s)
{
BOOST_ASSERT_MSG(s <= Capacity, "size can't exceed the capacity");
-// if ( Capacity < s )
-// throw std::bad_alloc();
}
template <typename V, std::size_t C, typename S>
@@ -206,7 +206,7 @@
sv::destroy(this->begin(), this->end());
}
- // nothrow
+ // nothrow or basic (depends on traits)
// swap (note: linear complexity)
void swap(static_vector & other)
{
Modified: sandbox/static_vector/test/static_vector.cpp
==============================================================================
--- sandbox/static_vector/test/static_vector.cpp (original)
+++ sandbox/static_vector/test/static_vector.cpp 2012-12-20 23:00:40 EST (Thu, 20 Dec 2012)
@@ -503,12 +503,22 @@
#endif
}
+struct bad_alloc_strategy : public static_vector_detail::default_strategy<>
+{
+ template <typename V, std::size_t Capacity, typename S>
+ static void check_capacity(static_vector<V, Capacity, S> const&, std::size_t s)
+ {
+ if ( Capacity < s )
+ throw std::bad_alloc();
+ }
+};
+
template <typename T>
void test_capacity_0_nd()
{
static_vector<T, 10> v(5u, T(0));
- static_vector<T, 0> s;
+ static_vector<T, 0, bad_alloc_strategy> s;
BOOST_CHECK(s.size() == 0);
BOOST_CHECK(s.capacity() == 0);
BOOST_CHECK_THROW(s.at(0), std::out_of_range);
@@ -520,11 +530,11 @@
BOOST_CHECK_THROW(s.assign(v.begin(), v.end()), std::bad_alloc);
BOOST_CHECK_THROW(s.assign(5u, T(0)), std::bad_alloc);
try{
- static_vector<T, 0> s2(v.begin(), v.end());
+ static_vector<T, 0, bad_alloc_strategy> s2(v.begin(), v.end());
BOOST_CHECK(false);
}catch(std::bad_alloc &){}
try{
- static_vector<T, 0> s1(5u, T(0));
+ static_vector<T, 0, bad_alloc_strategy> s1(5u, T(0));
BOOST_CHECK(false);
}catch(std::bad_alloc &){}
}
@@ -533,7 +543,7 @@
void test_exceptions_nd()
{
static_vector<T, N> v(N, T(0));
- static_vector<T, N/2> s(N/2, T(0));
+ static_vector<T, N/2, bad_alloc_strategy> s(N/2, T(0));
BOOST_CHECK_THROW(s.resize(N, T(0)), std::bad_alloc);
BOOST_CHECK_THROW(s.push_back(T(0)), std::bad_alloc);
@@ -543,11 +553,11 @@
BOOST_CHECK_THROW(s.assign(v.begin(), v.end()), std::bad_alloc);
BOOST_CHECK_THROW(s.assign(N, T(0)), std::bad_alloc);
try{
- static_vector<T, N/2> s2(v.begin(), v.end());
+ static_vector<T, N/2, bad_alloc_strategy> s2(v.begin(), v.end());
BOOST_CHECK(false);
}catch(std::bad_alloc &){}
try{
- static_vector<T, N/2> s1(N, T(0));
+ static_vector<T, N/2, bad_alloc_strategy> s1(N, T(0));
BOOST_CHECK(false);
}catch(std::bad_alloc &){}
}
@@ -593,7 +603,7 @@
}
{
static_vector<T, N> v(N, T(0));
- static_vector<T, N/2> s(N/2, T(1));
+ static_vector<T, N/2, bad_alloc_strategy> s(N/2, T(1));
BOOST_CHECK_THROW(s.swap(v), std::bad_alloc);
}
}
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk