C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

some remarks to N1870

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language, library and standards
View previous topic :: View next topic  
Author Message
Boris Bralo
Guest





PostPosted: Tue Sep 20, 2005 1:52 pm    Post subject: some remarks to N1870 Reply with quote



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





PostPosted: Sat Oct 01, 2005 5:41 am    Post subject: Re: some remarks to N1870 Reply with quote




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
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language, library and standards All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.