Boost logo

Boost :

From: Arno Schödl (aschoedl_at_[hidden])
Date: 2008-08-30 05:26:15

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?


Dr. Arno Schoedl · aschoedl_at_[hidden] 
Technical Director 
think-cell Software GmbH · Invalidenstr. 34 · 10115 Berlin, Germany · phone +49-30-666473-10 · toll-free (US) +1-800-891-8091
Directors: Dr. Markus Hannebauer, Dr. Arno Schoedl · Amtsgericht Charlottenburg, HRB 85229

Boost list run by bdawes at, gregod at, cpdaniel at, john at