summaryrefslogtreecommitdiff
path: root/boost/multi_index/detail/rnd_index_ptr_array.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'boost/multi_index/detail/rnd_index_ptr_array.hpp')
-rw-r--r--boost/multi_index/detail/rnd_index_ptr_array.hpp57
1 files changed, 29 insertions, 28 deletions
diff --git a/boost/multi_index/detail/rnd_index_ptr_array.hpp b/boost/multi_index/detail/rnd_index_ptr_array.hpp
index c0a2d67cbd..bae1c851b8 100644
--- a/boost/multi_index/detail/rnd_index_ptr_array.hpp
+++ b/boost/multi_index/detail/rnd_index_ptr_array.hpp
@@ -1,4 +1,4 @@
-/* Copyright 2003-2008 Joaquin M Lopez Munoz.
+/* Copyright 2003-2013 Joaquin M Lopez Munoz.
* 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)
@@ -9,7 +9,7 @@
#ifndef BOOST_MULTI_INDEX_DETAIL_RND_INDEX_PTR_ARRAY_HPP
#define BOOST_MULTI_INDEX_DETAIL_RND_INDEX_PTR_ARRAY_HPP
-#if defined(_MSC_VER)&&(_MSC_VER>=1200)
+#if defined(_MSC_VER)
#pragma once
#endif
@@ -17,7 +17,6 @@
#include <algorithm>
#include <boost/detail/allocator_utilities.hpp>
#include <boost/multi_index/detail/auto_space.hpp>
-#include <boost/multi_index/detail/prevent_eti.hpp>
#include <boost/multi_index/detail/rnd_index_node.hpp>
#include <boost/noncopyable.hpp>
#include <cstddef>
@@ -33,29 +32,23 @@ namespace detail{
template<typename Allocator>
class random_access_index_ptr_array:private noncopyable
{
- typedef typename prevent_eti<
- Allocator,
- random_access_index_node_impl<
- typename boost::detail::allocator::rebind_to<
- Allocator,
- char
- >::type
- >
- >::type node_impl_type;
-
-public:
- typedef typename node_impl_type::pointer value_type;
- typedef typename prevent_eti<
- Allocator,
+ typedef random_access_index_node_impl<
typename boost::detail::allocator::rebind_to<
- Allocator,value_type
+ Allocator,
+ char
>::type
- >::type::pointer pointer;
+ > node_impl_type;
+
+public:
+ typedef typename node_impl_type::pointer value_type;
+ typedef typename boost::detail::allocator::rebind_to<
+ Allocator,value_type
+ >::type::pointer pointer;
random_access_index_ptr_array(
- const Allocator& al,value_type end_,std::size_t size):
- size_(size),
- capacity_(size),
+ const Allocator& al,value_type end_,std::size_t sz):
+ size_(sz),
+ capacity_(sz),
spc(al,capacity_+1)
{
*end()=end_;
@@ -74,12 +67,12 @@ public:
void reserve(std::size_t c)
{
- if(c>capacity_){
- auto_space<value_type,Allocator> spc1(spc.get_allocator(),c+1);
- node_impl_type::transfer(begin(),end()+1,spc1.data());
- spc.swap(spc1);
- capacity_=c;
- }
+ if(c>capacity_)set_capacity(c);
+ }
+
+ void shrink_to_fit()
+ {
+ if(capacity_>size_)set_capacity(size_);
}
pointer begin()const{return ptrs();}
@@ -124,6 +117,14 @@ private:
{
return spc.data();
}
+
+ void set_capacity(std::size_t c)
+ {
+ auto_space<value_type,Allocator> spc1(spc.get_allocator(),c+1);
+ node_impl_type::transfer(begin(),end()+1,spc1.data());
+ spc.swap(spc1);
+ capacity_=c;
+ }
};
template<typename Allocator>