3 // Copyright Neil Groves 2010. Use, modification and
4 // distribution is subject to the Boost Software License, Version
5 // 1.0. (See accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
8 // For more information, see http://www.boost.org/libs/range/
10 #ifndef BOOST_RANGE_DETAIL_ANY_ITERATOR_BUFFER_HPP_INCLUDED
11 #define BOOST_RANGE_DETAIL_ANY_ITERATOR_BUFFER_HPP_INCLUDED
13 #include <boost/array.hpp>
14 #include <boost/assert.hpp>
15 #include <boost/static_assert.hpp>
16 #include <boost/noncopyable.hpp>
20 template<std::size_t StackBufferSize>
21 class any_iterator_buffer
24 BOOST_STATIC_ASSERT(( StackBufferSize > 0 ));
31 ~any_iterator_buffer()
36 void* allocate(std::size_t bytes)
38 BOOST_ASSERT( !m_ptr );
39 if (bytes <= StackBufferSize)
40 return m_buffer.data();
42 m_ptr = new char[bytes];
54 // Do not use inheritance from noncopyable because this causes
55 // the concepts to erroneous detect the derived any_iterator
57 any_iterator_buffer(const any_iterator_buffer&);
58 void operator=(const any_iterator_buffer&);
61 boost::array<char, StackBufferSize> m_buffer;
64 class any_iterator_heap_only_buffer
68 any_iterator_heap_only_buffer()
73 ~any_iterator_heap_only_buffer()
78 void* allocate(std::size_t bytes)
80 BOOST_ASSERT( !m_ptr );
81 m_ptr = new char[bytes];
95 template<std::size_t StackBufferSize>
96 class any_iterator_stack_only_buffer
98 BOOST_STATIC_ASSERT(( StackBufferSize > 0 ));
100 void* allocate(std::size_t bytes)
102 BOOST_ASSERT( bytes <= m_buffer.size() );
103 return m_buffer.data();
111 boost::array<char, StackBufferSize> m_buffer;
114 typedef any_iterator_buffer<64> any_iterator_default_buffer;
117 #endif // include guard