Boost logo

Boost :

Subject: [boost] [icl] insert_iterator and elements
From: Jeff Flinn (jeffrey.flinn_at_[hidden])
Date: 2014-12-22 16:50:28

interval_set has overloaded insert methods for both intervals and
elements. Is there a reason there insert iterator lacks this ability.

The line in the code below *itr = 4; fails to compile.

This could be made to compile by:

- adding an implicit constructor 'interval( const element& )' for the
underlying (discrete) intervals, initializing to [element, element+1),
or [element, element].

- adding an overloaded operator=( const element& )

- adding an element_insert_iterator class

I've encountered 2 domains now where I need to construct an
interval_set<int> from a range of ints. The most natural ways to
accomplish this (for me) are:

boost::copy( ints, inserter(int_interval_set) );


boost::copy_range<int_interval_set>( ints );

Of course I can transform the incoming ints, but this seems a common
enough usage pattern for the library to provide. Especially since the
lack of this facility is asymmetric to the insert overloads of interval_set.

#include <iostream>


#include <boost/icl/interval_set.hpp>
#include <boost/range/algorithm/copy.hpp>

int main()
        typedef boost::icl::interval_set<int> IdSet;
        typedef IdSet::interval_type IdInterval;
        IdSet ids;
        boost::icl::insert_iterator<IdSet> itr(ids, ids.end());
        *itr = IdInterval(1,2);
        //*itr = 4; //compile error no viable operator =
        boost::copy(ids, std::ostream_iterator<IdInterval>(std::cout));

        std::cout << "\n";

        return 0;

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