 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Boris Bralo Guest
|
Posted: Tue Sep 20, 2005 1:52 pm Post subject: some remarks to N1870 |
|
|
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 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_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 ]
|
|
| Back to top |
|
 |
thorsten.ottosen@dezide.c Guest
|
Posted: Sat Oct 01, 2005 5:41 am Post subject: Re: some remarks to N1870 |
|
|
Boris Bralo skrev:
| Quote: | 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.
| Quote: | 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 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 ]
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|