summaryrefslogtreecommitdiff
path: root/boost/iostreams/detail/buffer.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'boost/iostreams/detail/buffer.hpp')
-rw-r--r--boost/iostreams/detail/buffer.hpp28
1 files changed, 26 insertions, 2 deletions
diff --git a/boost/iostreams/detail/buffer.hpp b/boost/iostreams/detail/buffer.hpp
index 72400f04ca..35cb33c700 100644
--- a/boost/iostreams/detail/buffer.hpp
+++ b/boost/iostreams/detail/buffer.hpp
@@ -39,10 +39,16 @@ template< typename Ch,
class basic_buffer {
private:
#ifndef BOOST_NO_STD_ALLOCATOR
+#if defined(BOOST_NO_CXX11_ALLOCATOR)
typedef typename Alloc::template rebind<Ch>::other allocator_type;
#else
+ typedef typename std::allocator_traits<Alloc>::template rebind_alloc<Ch> allocator_type;
+ typedef std::allocator_traits<allocator_type> allocator_traits;
+#endif
+#else
typedef std::allocator<Ch> allocator_type;
#endif
+ static Ch* allocate(std::streamsize buffer_size);
public:
basic_buffer();
basic_buffer(std::streamsize buffer_size);
@@ -145,9 +151,21 @@ template<typename Ch, typename Alloc>
basic_buffer<Ch, Alloc>::basic_buffer() : buf_(0), size_(0) { }
template<typename Ch, typename Alloc>
+inline Ch* basic_buffer<Ch, Alloc>::allocate(std::streamsize buffer_size)
+{
+#if defined(BOOST_NO_CXX11_ALLOCATOR) || defined(BOOST_NO_STD_ALLOCATOR)
+ return static_cast<Ch*>(allocator_type().allocate(
+ static_cast<BOOST_DEDUCED_TYPENAME Alloc::size_type>(buffer_size), 0));
+#else
+ allocator_type alloc;
+ return static_cast<Ch*>(allocator_traits::allocate(alloc,
+ static_cast<BOOST_DEDUCED_TYPENAME allocator_traits::size_type>(buffer_size)));
+#endif
+}
+
+template<typename Ch, typename Alloc>
basic_buffer<Ch, Alloc>::basic_buffer(std::streamsize buffer_size)
- : buf_(static_cast<Ch*>(allocator_type().allocate(
- static_cast<BOOST_DEDUCED_TYPENAME Alloc::size_type>(buffer_size), 0))),
+ : buf_(allocate(buffer_size)),
size_(buffer_size) // Cast for SunPro 5.3.
{ }
@@ -155,8 +173,14 @@ template<typename Ch, typename Alloc>
inline basic_buffer<Ch, Alloc>::~basic_buffer()
{
if (buf_) {
+#if defined(BOOST_NO_CXX11_ALLOCATOR) || defined(BOOST_NO_STD_ALLOCATOR)
allocator_type().deallocate(buf_,
static_cast<BOOST_DEDUCED_TYPENAME Alloc::size_type>(size_));
+#else
+ allocator_type alloc;
+ allocator_traits::deallocate(alloc, buf_,
+ static_cast<BOOST_DEDUCED_TYPENAME allocator_traits::size_type>(size_));
+#endif
}
}