]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/container/test/static_vector_options_test.cpp
80e88436ea8a874a0abda5b800a465b8adcab32b
1 //////////////////////////////////////////////////////////////////////////////
3 // (C) Copyright Ion Gaztanaga 2004-2013. Distributed under the Boost
4 // Software License, Version 1.0. (See accompanying file
5 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 // See http://www.boost.org/libs/container for documentation.
9 //////////////////////////////////////////////////////////////////////////////
10 #define BOOST_ENABLE_ASSERT_HANDLER
11 #include <boost/container/static_vector.hpp>
12 #include <boost/core/lightweight_test.hpp>
13 #include <boost/core/no_exceptions_support.hpp>
14 #include <new> //for bad_alloc
15 #include <boost/assert.hpp>
17 using namespace boost::container
;
19 //User-defined assertion to test throw_on_overflow
20 struct throw_on_overflow_off
24 void assertion_failed(char const *, char const *, char const *, long)
26 #ifdef BOOST_NO_EXCEPTIONS
29 throw throw_on_overflow_off();
33 void assertion_failed_msg(char const *, char const *, char const *, char const *, long )
35 #ifdef BOOST_NO_EXCEPTIONS
38 throw throw_on_overflow_off();
45 const std::size_t Capacity
= 10u;
46 { //extended alignment
47 const std::size_t extended_alignment
= sizeof(int)*4u;
48 BOOST_STATIC_ASSERT(extended_alignment
> dtl::alignment_of
<int>::value
);
49 #if !defined(BOOST_NO_CXX11_TEMPLATE_ALIASES)
50 using options_t
= static_vector_options_t
< inplace_alignment
<extended_alignment
> >;
52 typedef static_vector_options
53 < inplace_alignment
<extended_alignment
> >::type options_t
;
56 static_vector
<int, Capacity
, options_t
> v
;
57 v
.resize(v
.capacity());
58 BOOST_ASSERT((reinterpret_cast<std::size_t>(&v
[0]) % extended_alignment
) == 0);
61 #if !defined(BOOST_NO_CXX11_TEMPLATE_ALIASES)
62 using options_t
= static_vector_options_t
< inplace_alignment
<0> >;
64 typedef static_vector_options
< inplace_alignment
<0> >::type options_t
;
67 static_vector
<int, Capacity
, options_t
> v
;
68 v
.resize(v
.capacity());
69 BOOST_ASSERT((reinterpret_cast<std::size_t>(&v
[0]) % dtl::alignment_of
<int>::value
) == 0);
73 void test_throw_on_overflow()
75 #if !defined(BOOST_NO_EXCEPTIONS)
76 const std::size_t Capacity
= 10u;
77 { //throw_on_overflow == true, expect bad_alloc
78 #if !defined(BOOST_NO_CXX11_TEMPLATE_ALIASES)
79 using options_t
= static_vector_options_t
< throw_on_overflow
<true> >;
81 typedef static_vector_options
82 < throw_on_overflow
<true> >::type options_t
;
85 static_vector
<int, Capacity
, options_t
> v
;
88 bool expected_type_thrown
= false;
93 BOOST_CATCH(std::bad_alloc
&)
95 expected_type_thrown
= true;
101 BOOST_TEST(expected_type_thrown
== true);
102 BOOST_TEST(v
.capacity() == Capacity
);
104 { //throw_on_overflow == false, test it through BOOST_ASSERT
105 //even in release mode (BOOST_ENABLE_ASSERT_HANDLER), and throwing
106 //a special type in that assertion.
107 #if !defined(BOOST_NO_CXX11_TEMPLATE_ALIASES)
108 using options_t
= static_vector_options_t
< throw_on_overflow
<false> >;
110 typedef static_vector_options
< throw_on_overflow
<false> >::type options_t
;
113 static_vector
<int, Capacity
, options_t
> v
;
116 bool expected_type_thrown
= false;
121 BOOST_CATCH(throw_on_overflow_off
)
123 expected_type_thrown
= true;
129 BOOST_TEST(expected_type_thrown
== true);
130 BOOST_TEST(v
.capacity() == Capacity
);
138 test_throw_on_overflow();
139 return ::boost::report_errors();