3636#define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_MAX 0
3737#include < boost/intrusive/detail/has_member_function_callable_with.hpp>
3838
39+
40+ // reserve
41+ #define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME reserve
42+ #define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_BEG namespace boost { namespace container { namespace test {
43+ #define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_END }}}
44+ #define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_MIN 1
45+ #define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_MAX 1
46+ #include < boost/intrusive/detail/has_member_function_callable_with.hpp>
47+
48+ // back_reserve
49+ #define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME reserve_back
50+ #define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_BEG namespace boost { namespace container { namespace test {
51+ #define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_END }}}
52+ #define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_MIN 1
53+ #define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_MAX 1
54+ #include < boost/intrusive/detail/has_member_function_callable_with.hpp>
55+
3956// #pragma GCC diagnostic ignored "-Wunused-result"
4057#if defined(BOOST_GCC) && (BOOST_GCC >= 40600)
4158#pragma GCC diagnostic pop
@@ -132,9 +149,19 @@ class MyFatInt
132149 }
133150};
134151
135- template <class C , bool = boost::container::test::
136- has_member_function_callable_with_capacity<C>::value>
137- struct capacity_wrapper
152+ template <class C , bool Capacity = false , bool BackCapacity = false >
153+ struct capacity_wrapper_impl
154+ {
155+ inline static typename C::size_type get_capacity (const C &)
156+ { return 0u ; }
157+
158+ inline static void set_reserve (C &, typename C::size_type )
159+ { }
160+ };
161+
162+
163+ template <class C >
164+ struct capacity_wrapper_impl <C, true , false >
138165{
139166 inline static typename C::size_type get_capacity (const C &c)
140167 { return c.capacity (); }
@@ -143,16 +170,26 @@ struct capacity_wrapper
143170 { c.reserve (cp); }
144171};
145172
146- template <class C >
147- struct capacity_wrapper <C, false >
173+ template <class C , bool Capacity >
174+ struct capacity_wrapper_impl <C, Capacity, true >
148175{
149- inline static typename C::size_type get_capacity (const C &)
150- { return 0u ; }
176+ inline static typename C::size_type get_capacity (const C &c )
177+ { return c. back_capacity () ; }
151178
152- inline static void set_reserve (C &, typename C::size_type )
153- { }
179+ inline static void set_reserve (C &c , typename C::size_type cp )
180+ { c. reserve_back (cp); }
154181};
155182
183+ template <class C >
184+ struct capacity_wrapper
185+ : capacity_wrapper_impl
186+ < C
187+ , bc::test::has_member_function_callable_with_reserve<C, std::size_t >::value
188+ , bc::test::has_member_function_callable_with_reserve_back<C, std::size_t >::value
189+ >
190+ {};
191+
192+
156193const std::size_t RangeSize = 8 ;
157194
158195template <class IntType >
@@ -304,6 +341,8 @@ void vector_test_template(std::size_t num_iterations, std::size_t num_elements,
304341 cpu_timer timer;
305342
306343 const std::size_t max = num_elements/multiplier;
344+ std::size_t capacity = 0u ;
345+
307346 for (std::size_t r = 0 ; r != num_iterations; ++r){
308347 // Unroll the loop to avoid noise from loop code
309348 int i = 0 ;
@@ -330,13 +369,11 @@ void vector_test_template(std::size_t num_iterations, std::size_t num_elements,
330369
331370 if (r > num_iterations/10 )
332371 timer.stop ();
372+ if (r == (num_iterations-1u ))
373+ capacity = cpw_t::get_capacity (c);
333374 c.clear ();
334375 }
335376
336- timer.stop ();
337-
338- std::size_t capacity = cpw_t::get_capacity (c);
339-
340377 nanosecond_type nseconds = timer.elapsed ().wall ;
341378
342379 std::cout << cont_name << " ->" << " ns: "
@@ -379,7 +416,7 @@ void test_vectors_impl()
379416#define RESERVE_ONLY 0
380417#define NORESERVE_ONLY 1
381418
382- #define RESERVE_STRATEGY NORESERVE_ONLY
419+ // #define RESERVE_STRATEGY NORESERVE_ONLY
383420// #define RESERVE_STRATEGY RESERVE_ONLY
384421
385422#ifndef RESERVE_STRATEGY
@@ -407,6 +444,8 @@ void test_vectors_impl()
407444 vector_test_template< bc::devector<IntType, std::allocator<IntType> >, Operation >(numit[i], numele[i], " devector " , bp);
408445 vector_test_template< std::deque<IntType, std::allocator<IntType> >, Operation >(numit[i], numele[i], " std::deque " , bp);
409446 vector_test_template< bc::deque<IntType, std::allocator<IntType> >, Operation >(numit[i], numele[i], " deque " , bp);
447+ vector_test_template< bc::deque<IntType, std::allocator<IntType>,
448+ typename bc::deque_options<bc::reservable<true > >::type >, Operation >(numit[i], numele[i], " deque(reserv) " , bp);
410449 }
411450 std::cout << " ---------------------------------\n ---------------------------------\n " ;
412451 }
0 commit comments