intervaltree
intervaltree copied to clipboard
Documentation is incorrect
The example in the README:
vector<Interval<T> > intervals;
T a, b, c;
intervals.push_back(Interval<T>(2, 10, a));
intervals.push_back(Interval<T>(3, 4, b));
intervals.push_back(Interval<T>(20, 100, c));
IntervalTree<T> tree;
tree = IntervalTree<T>(intervals);
doesn't compile.
E.g. wrap it in a function as follows, and try compiling:
template<typename T>
void foo() {
vector<Interval<T> > intervals;
T a, b, c;
intervals.push_back(Interval<T>(2, 10, a));
intervals.push_back(Interval<T>(3, 4, b));
intervals.push_back(Interval<T>(20, 100, c));
IntervalTree<T> tree;
tree = IntervalTree<T>(intervals);
}
Problems include:
-
the
IntervalandIntervalTreetemplates take two parameters, not one -Interval<T>andIntervalTree<T>are not correct. (Presumably it should be something likeInterval<size_t, T>etc., like in interval_tree_test.cpp. -
the call to the constructor doesn't compile. If you call
foo<bool>()and compile, you'll get errors along the lines of (summarizing):error: no matching conversion for functional-style cast from 'vector<Interval<size_t, bool> >' (aka 'vector<Interval<unsigned long, bool> >') to 'IntervalTree<size_t, bool>' (aka 'IntervalTree<unsigned long, bool>') // ... ./intervaltree/IntervalTree.h:92:5: note: candidate constructor not viable: no known conversion from 'vector<Interval<size_t, bool> >' (aka 'vector<Interval<unsigned long, bool> >') to 'IntervalTree<unsigned long, bool>::interval_vector &&' (aka 'vector<Interval<unsigned long, bool> > &&') for 1st argument
From the interval_tree_test.cpp test file, it looks like the constructor now takes an initializer list.
As an aside - why would you change the constructor in this way, anyway? It seems considerably less convenient to take an initializer list instead of (say) a pair of begin, end iterators.