I have a polymorphic interface
struct Interface {
Interface(SomeType& other)
: range([=](){ return other.my_range(); }), /*...*/ {}
Interface(SomeOtherType& other)
: range([=](){ return other.some_range(); }), /*...*/ {}
const std::function<Range(void)> range;
/// ...
};
The elements in both ranges are of the same type (e.g. int
), but the types returned by my_range()
and by some_range()
are different, e.g. one can be a filtered counting range
and the other a transformed filtered counting range
. For the interface I need a single Range
type.
I've tried using boost::any_range
but the performance is significantly worse. I would like to avoid having to copy the range elements into a vector
and returning the vector instead.
Are there any alternatives to any_range
and copying?