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

ConstIteratorAdapter does not satisfy the _is_forward concept of the STL #1437

Open
dcoeurjo opened this issue Oct 8, 2019 · 7 comments
Open

Comments

@dcoeurjo
Copy link
Member

dcoeurjo commented Oct 8, 2019

On the last apple clang compiler, the following code raises a build error

const DTL2::Value maxv2 = * (std::max_element(dtL2.constRange().begin(), dtL2.constRange().end()));

Here you have the error:

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/algorithm:2494:5: error: static_assert failed due to requirement
      '__is_forward_iterator<DGtal::ConstIteratorAdapter<DGtal::HyperRectDomain_Iterator<DGtal::PointVector<2, int, std::__1::array<int, 2> > >, DGtal::DistanceTransformation<DGtal::SpaceND<2, int>,
      DGtal::functors::SimpleThresholdForegroundPredicate<DGtal::ImageContainerBySTLVector<DGtal::HyperRectDomain<DGtal::SpaceND<2, int> >, unsigned int> >, DGtal::ExactPredicateLpSeparableMetric<DGtal::SpaceND<2, int>, 2, long long>,
      DGtal::ImageContainerBySTLVector<DGtal::HyperRectDomain<DGtal::SpaceND<2, int> >, DGtal::PointVector<2, int, std::__1::array<int, 2> > > >, double> >::value' "std::max_element requires a ForwardIterator"
    static_assert(__is_forward_iterator<_ForwardIterator>::value,
    ^             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/algorithm:2512:19: note: in instantiation of function template specialization
      'std::__1::max_element<DGtal::ConstIteratorAdapter<DGtal::HyperRectDomain_Iterator<DGtal::PointVector<2, int, std::__1::array<int, 2> > >, DGtal::DistanceTransformation<DGtal::SpaceND<2, int>,
      DGtal::functors::SimpleThresholdForegroundPredicate<DGtal::ImageContainerBySTLVector<DGtal::HyperRectDomain<DGtal::SpaceND<2, int> >, unsigned int> >, DGtal::ExactPredicateLpSeparableMetric<DGtal::SpaceND<2, int>, 2, long long>,
      DGtal::ImageContainerBySTLVector<DGtal::HyperRectDomain<DGtal::SpaceND<2, int> >, DGtal::PointVector<2, int, std::__1::array<int, 2> > > >, double>, std::__1::__less<double, double> >' requested here
    return _VSTD::max_element(__first, __last,
                  ^
/Users/davidcoeurjolly/Sources/DGtal/examples/geometry/volumes/distance/toricdomainvolumetric.cpp:119:49: note: in instantiation of function template specialization 'std::__1::max_element<DGtal::ConstIteratorAdapter<DGtal::HyperRectDomain_Iterator<DGtal::PointVector<2,
      int, std::__1::array<int, 2> > >, DGtal::DistanceTransformation<DGtal::SpaceND<2, int>, DGtal::functors::SimpleThresholdForegroundPredicate<DGtal::ImageContainerBySTLVector<DGtal::HyperRectDomain<DGtal::SpaceND<2, int> >, unsigned int> >,
      DGtal::ExactPredicateLpSeparableMetric<DGtal::SpaceND<2, int>, 2, long long>, DGtal::ImageContainerBySTLVector<DGtal::HyperRectDomain<DGtal::SpaceND<2, int> >, DGtal::PointVector<2, int, std::__1::array<int, 2> > > >, double> >' requested here
  const DTL2::Value       maxv2       = * (std::max_element(dtL2.constRange().begin(), dtL2.constRange().end()));
                                                ^
1 error generated.
``` 
@kerautret
Copy link
Member

I confirm ;(

@rolanddenis
Copy link
Member

Can one of you test to replace std::max_element by boost::first_max_element that is available in boost/algorithm/minmax_element.hpp?
It is a proposed fix from boostorg/graph#175 even if it will not solve the fact that DGtal::ConstIteratorAdapter is not strictly a forward iterator.

@kerautret
Copy link
Member

thanks @rolanddenis I look it

@kerautret
Copy link
Member

@rolanddenis excellent that fix it 🎉
Did I put in PR the change ?

@kerautret kerautret pinned this issue Apr 9, 2020
@kerautret kerautret unpinned this issue Apr 9, 2020
@kerautret kerautret pinned this issue Apr 9, 2020
@kerautret
Copy link
Member

@rolanddenis
Copy link
Member

Thx, agree for the PR !

BTW I was more thinking in replacing by the boost version only where needed (with smart iterators like ConstIteratorAdaptor), so probably only in:

  • examples/geometry/volumes/distance/toricdomainvolumetric.cpp
  • examples/kernel/examplePointFunctorHolder.cpp
  • examples/tutorial-examples/shapeDTViewer.cpp
  • examples/tutorial-examples/volDTGranulo-template.cpp
  • examples/tutorial-examples/volDTGranulo.cpp

We may also add a note in the ConstIteratorAdapterdocumentation (I don't think there is a way to make it a true forward iterator...)

@kerautret
Copy link
Member

Yes agree I do it thanks

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

3 participants