Topic: some remarks to N1870
Author: thorsten.ottosen@dezide.com
Date: Fri, 30 Sep 2005 23:41:44 CST Raw View
Boris Bralo skrev:
> 1)
> Maybe we should add the method to give ownership of the buffer too:
>
> T* release_buffer()
> Postcondition:
> container.size()==0
it would be worth to consider.
> 2)
> Custom allocator in std::vector will be a problem in both cases.
> However, it can be solved by adding parameter to methods:
>
> template <typename Allocator> set_buffer( T* b, size_t s, Allocator a);
> Postcondition:
> container.buffer()==b,
> container.size()==s,
> container.allocator()==a,
>
>
> For release_buffer:
>
> shared_array<T, DeleterAdapter<T, A> > release_buffer()
> Postcondition:
> container.buffer()==NULL,
> container.size()==0,
this complicates the interface a bit, but I think
the proposed unique_ptr<T[]> might be good here.
Thanks for your feedback
-Thorsten ]
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: boris.bralo@gmail.com (Boris Bralo)
Date: Tue, 20 Sep 2005 13:52:45 GMT Raw View
Hi all,
I've just red N1870
(http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1870.html )
section 2.5 ("Add set_buffer( T*, size_t ) to vector and basic_string")
and I like it since I'm working in the embedded and I need such
functionality.
1)
Maybe we should add the method to give ownership of the buffer too:
T* release_buffer()
Postcondition:
container.size()==0
2)
Custom allocator in std::vector will be a problem in both cases.
However, it can be solved by adding parameter to methods:
template <typename Allocator> set_buffer( T* b, size_t s, Allocator a);
Postcondition:
container.buffer()==b,
container.size()==s,
container.allocator()==a,
For release_buffer:
shared_array<T, DeleterAdapter<T, A> > release_buffer()
Postcondition:
container.buffer()==NULL,
container.size()==0,
DeleterAdapter is shared_array "deleter" that coresponds to container's
allocator, something like:
template <typename T, typename A>
struct DeleterAdapter
{
const A& m_a;
size_t m_size;
DeleterAdapter( const A& a, size_t s)
:m_a(a), m_size(s)
{
}
void operator()(T* p)
{
for(size_t i=0; i<m_size;i++)
m_a.destroy(p+i);
m_a.deallocate(p, m_size);
}
}
Of course, there should be specializations for both allocator and
DeleteAdapter that'll handle most common case ( i.e array allocated with
array new) etc.
Boris
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]