From e2502e5b16c2a685a8b9dcdac7f837bb8a3390fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20M=C3=B6ller?= Date: Fri, 16 Nov 2012 22:05:10 +0100 Subject: [PATCH] Add circulator concepts and a (not useful) test-case. --- .../CGAL/Circulator/Circulator_concepts.h | 95 +++++++++++++++++++ .../Circulator/circulator_concept_checks.cpp | 32 +++++++ 2 files changed, 127 insertions(+) create mode 100644 Circulator/include/CGAL/Circulator/Circulator_concepts.h create mode 100644 Circulator/test/Circulator/circulator_concept_checks.cpp diff --git a/Circulator/include/CGAL/Circulator/Circulator_concepts.h b/Circulator/include/CGAL/Circulator/Circulator_concepts.h new file mode 100644 index 00000000000..99525c52da0 --- /dev/null +++ b/Circulator/include/CGAL/Circulator/Circulator_concepts.h @@ -0,0 +1,95 @@ +#ifndef CGAL_CIRCULATOR_CONCEPTS_H +#define CGAL_CIRCULATOR_CONCEPTS_H + +#include +#include +#include + +#include + +#include + +namespace CGAL { namespace Concepts { + +// N.B.: there is no such concept as Circulator as it is immaterial +template +struct ForwardCirculator + : boost::Assignable, boost::DefaultConstructible + , boost::CopyConstructible +{ + // for some odd reason circulators have no associated traits + typedef typename C::value_type value_type; + typedef typename C::reference reference; + typedef typename C::pointer pointer; + typedef typename C::difference_type difference_type; + // odd name but useful for compatibility + typedef typename C::iterator_category iterator_category; + + // this requirement ought to be a mistake because it breaks + // compatibility with iterators + // typedef typename C::size_type size_type; + + BOOST_CONCEPT_USAGE(ForwardCirculator) + { + BOOST_CONCEPT_ASSERT((boost::SignedInteger)); + BOOST_CONCEPT_ASSERT((boost::Convertible)); + + boost::require_boolean_expr(a == NULL); + boost::require_boolean_expr(a != NULL); + ++a; + a++; + (void)*a; // suppress unused warning, don't check the return type + // to allow for proxies + } +private: + C a; +}; + +template +struct BidirectionalCirculator + : ForwardCirculator +{ + BOOST_CONCEPT_USAGE(BidirectionalCirculator) + { + BOOST_CONCEPT_ASSERT((boost::Convertible)); + --a; + a--; + } +private: + C a; +}; + +template +struct RandomAccessCirculator + : BidirectionalCirculator +{ + BOOST_CONCEPT_USAGE(RandomAccessCirculator) + { + BOOST_CONCEPT_ASSERT((boost::Convertible)); + c += n; // addition + c = c + n; c = n + c; + c -= n; // subtraction + c = c - n; + n = c - b; // difference + (void)c[n]; // operator[] + + c.min_circulator(); // minimum + } +private: + C c, b; + C i; + typename C::difference_type n; +}; + +} // Concept +} // CGAL + + + +#include + + +#endif /* CGAL_CIRCULATOR_CONCEPTS_H */ + + + diff --git a/Circulator/test/Circulator/circulator_concept_checks.cpp b/Circulator/test/Circulator/circulator_concept_checks.cpp new file mode 100644 index 00000000000..69615405e5b --- /dev/null +++ b/Circulator/test/Circulator/circulator_concept_checks.cpp @@ -0,0 +1,32 @@ +#include +#include + +#include + +#include +#include + +int main() +{ + // test Circulator_from_container + typedef CGAL::Circulator_from_container< std::vector > Circulator_from_vec; + typedef CGAL::Circulator_from_container< std::list > Circulator_from_list; + + // neither of the container adaptors passes the checks for tag + // convertibility + + // BOOST_CONCEPT_ASSERT((CGAL::Concepts::RandomAccessCirculator)); + // BOOST_CONCEPT_ASSERT((CGAL::Concepts::BidirectionalCirculator)); + + typedef CGAL::Circulator_from_iterator Circulator_from_intp; + typedef CGAL::Circulator_from_iterator::iterator> Circulator_from_veci; + typedef CGAL::Circulator_from_iterator::iterator> Circulator_from_listi; + + // same as above + // BOOST_CONCEPT_ASSERT((CGAL::Concepts::RandomAccessCirculator)); + // BOOST_CONCEPT_ASSERT((CGAL::Concepts::RandomAccessCirculator)); + // BOOST_CONCEPT_ASSERT((CGAL::Concepts::BidirectionalCirculator)); + + + return 0; +}