]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/container/test/static_vector_options_test.cpp
e8965d54f32292cbee09412619046f36362a68ac
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 <new> //for bad_alloc
14 #include <boost/assert.hpp>
15 using namespace boost::container
;
17 //User-defined assertion to test throw_on_overflow
18 struct throw_on_overflow_off
22 void assertion_failed(char const *, char const *, char const *, long)
24 throw throw_on_overflow_off();
27 void assertion_failed_msg(char const *, char const *, char const *, char const *, long )
29 throw throw_on_overflow_off();
35 const std::size_t Capacity
= 10u;
36 { //extended alignment
37 const std::size_t extended_alignment
= sizeof(int)*4u;
38 BOOST_STATIC_ASSERT(extended_alignment
> dtl::alignment_of
<int>::value
);
39 #if !defined(BOOST_NO_CXX11_TEMPLATE_ALIASES)
40 using options_t
= static_vector_options_t
< inplace_alignment
<extended_alignment
> >;
42 typedef static_vector_options
43 < inplace_alignment
<extended_alignment
> >::type options_t
;
46 static_vector
<int, Capacity
, options_t
> v
;
47 v
.resize(v
.capacity());
48 BOOST_ASSERT((reinterpret_cast<std::size_t>(&v
[0]) % extended_alignment
) == 0);
51 #if !defined(BOOST_NO_CXX11_TEMPLATE_ALIASES)
52 using options_t
= static_vector_options_t
< inplace_alignment
<0> >;
54 typedef static_vector_options
< inplace_alignment
<0> >::type options_t
;
57 static_vector
<int, Capacity
, options_t
> v
;
58 v
.resize(v
.capacity());
59 BOOST_ASSERT((reinterpret_cast<std::size_t>(&v
[0]) % dtl::alignment_of
<int>::value
) == 0);
63 void test_throw_on_overflow()
65 #if !defined(BOOST_NO_EXCEPTIONS)
66 const std::size_t Capacity
= 10u;
67 { //throw_on_overflow == true, expect bad_alloc
68 #if !defined(BOOST_NO_CXX11_TEMPLATE_ALIASES)
69 using options_t
= static_vector_options_t
< throw_on_overflow
<true> >;
71 typedef static_vector_options
72 < throw_on_overflow
<true> >::type options_t
;
75 static_vector
<int, Capacity
, options_t
> v
;
78 bool expected_type_thrown
= false;
82 catch(std::bad_alloc
&)
84 expected_type_thrown
= true;
88 BOOST_TEST(expected_type_thrown
== true);
89 BOOST_TEST(v
.capacity() == Capacity
);
91 { //throw_on_overflow == false, test it through BOOST_ASSERT
92 //even in release mode (BOOST_ENABLE_ASSERT_HANDLER), and throwing
93 //a special type in that assertion.
94 #if !defined(BOOST_NO_CXX11_TEMPLATE_ALIASES)
95 using options_t
= static_vector_options_t
< throw_on_overflow
<false> >;
97 typedef static_vector_options
< throw_on_overflow
<false> >::type options_t
;
100 static_vector
<int, Capacity
, options_t
> v
;
103 bool expected_type_thrown
= false;
107 catch(throw_on_overflow_off
)
109 expected_type_thrown
= true;
113 BOOST_TEST(expected_type_thrown
== true);
114 BOOST_TEST(v
.capacity() == Capacity
);
122 test_throw_on_overflow();
123 return ::boost::report_errors();