avoid decltype and put back correct types, also test for complience with std algorithms

This commit is contained in:
Dmitry Anisimov 2021-08-03 16:30:18 +02:00
parent ead69a5435
commit 66c20ba18c
3 changed files with 17 additions and 4 deletions

View File

@ -42,6 +42,8 @@ public:
typedef std::random_access_iterator_tag iterator_category;
typedef FT value_type;
typedef int difference_type;
typedef void pointer;
typedef value_type reference;
Cartesian_coordinate_iterator_2()
: var((const P*) nullptr), index(0) {}
@ -53,7 +55,7 @@ public:
: var(v), index(_index) {}
decltype(auto)
reference
operator*() const {
if (const P* const* p = boost::get<const P*>(&var))
return (*p)->cartesian(index);
@ -118,7 +120,7 @@ public:
return index - x.index;
}
decltype(auto)
reference
operator[](difference_type i) const {
return *(*this + i);
}

View File

@ -42,6 +42,8 @@ public:
typedef std::random_access_iterator_tag iterator_category;
typedef FT value_type;
typedef int difference_type;
typedef void pointer;
typedef value_type reference;
Cartesian_coordinate_iterator_3()
: var((const P*) nullptr), index(0) {}
@ -53,7 +55,7 @@ public:
: var(v), index(_index) {}
decltype(auto)
reference
operator*() const {
if (const P* const* p = boost::get<const P*>(&var))
return (*p)->cartesian(index);
@ -118,7 +120,7 @@ public:
return index - x.index;
}
decltype(auto)
reference
operator[](difference_type i) const {
return *(*this + i);
}

View File

@ -1,3 +1,4 @@
#include <algorithm>
#include <CGAL/Search_traits_2.h>
#include <CGAL/Search_traits_3.h>
#include <CGAL/Exact_predicates_exact_constructions_kernel.h>
@ -23,6 +24,10 @@ int main() {
const FT d2 = p2[0] - q2[0];
assert(d2 < FT(0));
const auto plen2 = std::distance(construct_it_2(pp2), construct_it_2(pp2, 0));
const auto qlen2 = std::distance(construct_it_2(qq2), construct_it_2(qq2, 0));
assert(plen2 == 2 && qlen2 == 2);
// Testing 3D.
Traits_3 traits_3;
auto construct_it_3 = traits_3.construct_cartesian_const_iterator_d_object();
@ -33,5 +38,9 @@ int main() {
const FT d3 = q3[2] - p3[2];
assert(d3 > FT(0));
const auto plen3 = std::distance(construct_it_3(pp3), construct_it_3(pp3, 0));
const auto qlen3 = std::distance(construct_it_3(qq3), construct_it_3(qq3, 0));
assert(plen3 == 3 && qlen3 == 3);
return EXIT_SUCCESS;
}