30 Aug 11:26
Re: lifetime of ranges vs. iterators
Arno Schödl <aschoedl <at> think-cell.com>
2008-08-30 09:26:15 GMT
2008-08-30 09:26:15 GMT
I am following up on Giovanni's idea of storing ranges by value. To minimize the impact on existing code, and
to make the frequent case of wrapping an adaptor range around another container like vector or set easy, we
could shift the burden to specify which ranges should be stored by reference and which by value onto the
ranges themselves.
A template container_reference would designate a reference to the underlying container that holds the
data. The data is assumed to remain valid, but any adaptors around it may go out of scope.
Storage by reference would be default, so everything works as it did so far, but any wrapped ranges may not go
out of scope:
template< class T >
struct container_reference {
typedef T& type;
};
Adaptor ranges could decide to store themselves by value:
template< class RngA, class RngB >
struct container_reference< difference_range<RngA, RngB> > {
typedef T type;
};
Adaptors would use it to store a reference to the underlying data:
template< class RngA, class RngB >
class difference_range {
typename container_reference< RngA >::type m_rngA;
typename container_reference< RngB >::type m_rngB;
difference_range( RngA const& rngA, RngA const& rngB ):
: m_rngA( rngA ), m_rngB( rngB )
{
...
}
};
What do you think?
Arno
--
Dr. Arno Schoedl · aschoedl <at> think-cell.com
Technical Director
think-cell Software GmbH · Invalidenstr. 34 · 10115 Berlin, Germany
http://www.think-cell.com · phone +49-30-666473-10 · toll-free (US) +1-800-891-8091
Directors: Dr. Markus Hannebauer, Dr. Arno Schoedl · Amtsgericht Charlottenburg, HRB 85229
_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
RSS Feed