Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation is incorrect #34

Open
phlummox opened this issue Jul 31, 2021 · 1 comment
Open

Documentation is incorrect #34

phlummox opened this issue Jul 31, 2021 · 1 comment

Comments

@phlummox
Copy link

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 Interval and IntervalTree templates take two parameters, not one - Interval<T> and IntervalTree<T> are not correct. (Presumably it should be something like Interval<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.

@phlummox
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant