From 1f989622e7db8bea08aa88552d55607634b34de9 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Mon, 9 Feb 2015 10:54:24 +0100 Subject: [PATCH] replace \code with real examples --- .../include/CGAL/Intersection_traits.h | 2 +- .../Intersections_3/intersection_3_1_impl.h | 3 +- Kernel_23/doc/Kernel_23/CGAL/intersections.h | 67 ++++++------------- Kernel_23/doc/Kernel_23/examples.txt | 2 + .../examples/Kernel_23/intersections.cpp | 7 +- .../doc/STL_Extension/CGAL/iterator.h | 10 +-- STL_Extension/include/CGAL/iterator.h | 2 +- 7 files changed, 34 insertions(+), 59 deletions(-) diff --git a/Intersections_2/include/CGAL/Intersection_traits.h b/Intersections_2/include/CGAL/Intersection_traits.h index 677f39ac156..5c7b74ea74f 100644 --- a/Intersections_2/include/CGAL/Intersection_traits.h +++ b/Intersections_2/include/CGAL/Intersection_traits.h @@ -165,7 +165,7 @@ namespace internal { inline CGAL::Object intersection_return() { return CGAL::Object(); } #else - #if defined(CGAL_CFG_NO_CPP0X_RVALUE_REFERENCE) +#if defined(CGAL_CFG_NO_CPP0X_RVALUE_REFERENCE) template inline typename cpp11::result_of::type intersection_return(const T& t) { return typename cpp11::result_of::type(t); } diff --git a/Intersections_3/include/CGAL/Intersections_3/intersection_3_1_impl.h b/Intersections_3/include/CGAL/Intersections_3/intersection_3_1_impl.h index 22bdfc548fd..7a298ef7492 100644 --- a/Intersections_3/include/CGAL/Intersections_3/intersection_3_1_impl.h +++ b/Intersections_3/include/CGAL/Intersections_3/intersection_3_1_impl.h @@ -1564,8 +1564,9 @@ intersection(const typename K::Segment_3 &seg, if (_max == _min) { return intersection_return(Point_3(_ref_point + _dir * _min )); } + return intersection_return( - Segment_3(_ref_point + _dir*_min, _ref_point + _dir*_max)); + Segment_3(_ref_point + _dir*_min, _ref_point + _dir*_max)); } diff --git a/Kernel_23/doc/Kernel_23/CGAL/intersections.h b/Kernel_23/doc/Kernel_23/CGAL/intersections.h index 57014e48480..ea7d1a5f9b7 100644 --- a/Kernel_23/doc/Kernel_23/CGAL/intersections.h +++ b/Kernel_23/doc/Kernel_23/CGAL/intersections.h @@ -127,9 +127,9 @@ depending on the arguments. The following tables give the possible values for `Type1` and `Type2`. -\cgalHeading{2D intersections} +\cgalHeading{2D Intersections} -The return type can be obtained through `cpp11::result_of::%type`. +The return type can be obtained through `CGAL::cpp11::result_of::%type`. It is equivalent to `boost::optional< boost::variant< T... > >`, the last column in the table providing the template parameter pack.
@@ -217,9 +217,9 @@ It is equivalent to `boost::optional< boost::variant< T... > >`, the last column
-\cgalHeading{3D intersections} +\cgalHeading{3D Intersections} -The return type can be obtained through `cpp11::result_of::%type`. +The return type can be obtained through `CGAL::cpp11::result_of::%type`. It is equivalent to `boost::optional< boost::variant< T... > >`, the last column in the table providing the template parameter pack.
@@ -316,57 +316,30 @@ p Point_3, or Segment_3
-\cgalHeading{Example} +\cgalHeading{Examples} -The following example demonstrates the most common use of -`intersection` routines with the 2D and 3D Linear %Kernel. +The following examples demonstrate the most common use of +`intersection()` functions with the 2D and 3D Linear %Kernel. -\code -#include +In the first two examples we intersect a segment and a line. +The result type can be obtained with `CGAL::cpp11::result_of`. It looks simpler +if you use a C++ compiler which supports `auto`, +but you must anyways know that the result type is a `boost::optional >`, in order to unpack the point or segment. -template -struct Intersection_visitor { - typedef void result_type; - void operator()(const Point_2& p) const - { - // handle point - } - void operator()(const Segment_2& s) const - { - // handle segment - } -}; +`boost::optional` comes in +as there might be no intersection. `boost::variant` comes in +as, if there is an intersection, it is either a point or a segment. -template -void foo (const Segment_2& seg, const Line_2& lin) -{ - // with C++11 support - // auto result = intersection(seg, lin); +As explained in the boost manual pages for `boost::variant`, there are two ways to access the variants. The first examples uses `boost::get`. - // without C++11 - cpp11::result_of, Line_2)>::type - result = intersection(seg, lin); +\cgalExample{Kernel_23/intersection_get.cpp} - if (result) { boost::apply_visitor(Intersection_visitor(), *result); } - else { - // no intersection - } +The second example uses`boost::apply_visitor`. - // alternatively: - if (result) { - if (const Segment_2* s = boost::get(&*result)) { - // handle segment - } else { - const Point_2* p = boost::get >(&*result); - // handle point - } - } -} -\endcode +\cgalExample{Kernel_23/intersection_visitor.cpp} - -Another example showing the use of the intersection function as a -plain function call and with `Dispatch_output_iterator` combined with +A third example shows the use of the intersection function as a +plain function call and with `Dispatch_output_iterator`, combined with a standard library algorithm. \cgalExample{Kernel_23/intersections.cpp} diff --git a/Kernel_23/doc/Kernel_23/examples.txt b/Kernel_23/doc/Kernel_23/examples.txt index 5a1d9be9567..6b38afbd27a 100644 --- a/Kernel_23/doc/Kernel_23/examples.txt +++ b/Kernel_23/doc/Kernel_23/examples.txt @@ -7,6 +7,8 @@ \example Kernel_23/MyKernel.cpp \example Filtered_kernel/Filtered_predicate.cpp \example Kernel_23/cartesian_converter.cpp +\example Kernel_23/intersection_get.cpp +\example Kernel_23/intersection_visitor.cpp \example Kernel_23/intersections.cpp \example Kernel_23/points_and_segment.cpp \example Kernel_23/surprising.cpp diff --git a/Kernel_23/examples/Kernel_23/intersections.cpp b/Kernel_23/examples/Kernel_23/intersections.cpp index b439c7e92da..6887cb41c2d 100644 --- a/Kernel_23/examples/Kernel_23/intersections.cpp +++ b/Kernel_23/examples/Kernel_23/intersections.cpp @@ -1,11 +1,10 @@ -#include -#include +#include #include #include #include -typedef CGAL::Simple_cartesian K; +typedef CGAL::Exact_predicates_exact_constructions_kernel K; typedef K::Point_2 Point; typedef K::Segment_2 Segment; @@ -49,7 +48,7 @@ int main() std::vector segments; typedef CGAL::Dispatch_output_iterator< - CGAL::cpp11::tuple, CGAL::cpp0x::tuple< std::back_insert_iterator >, + CGAL::cpp11::tuple, CGAL::cpp11::tuple< std::back_insert_iterator >, std::back_insert_iterator > > > Dispatcher; diff --git a/STL_Extension/doc/STL_Extension/CGAL/iterator.h b/STL_Extension/doc/STL_Extension/CGAL/iterator.h index 50897b5cecf..0314ed476b7 100644 --- a/STL_Extension/doc/STL_Extension/CGAL/iterator.h +++ b/STL_Extension/doc/STL_Extension/CGAL/iterator.h @@ -109,7 +109,7 @@ The class `Dispatch_or_drop_output_iterator` defines an dispatches among those based on the type of the value type which is put in it. Besides defining assignment for all parameters of `V` and for a tuple of type `V`, it is also defined for the types `boost::variant` and -`boost::optional>`, where `T...` +`boost::optional >`, where `T...` must be a subset of the parameters of `V`. Should the `boost::optional` be empty, it will be discarded. @@ -195,12 +195,12 @@ The class `Dispatch_output_iterator` defines an dispatches among those based on the type of the value type which is put in it. Other types are also accepted, and the object is discarded in this case. Besides defining assignment for all -parameters of V and for a tuple of type `V`, it is also defined for the types -`boost::variant`, where `T...` +parameters of `V` and for a tuple of type `V`, it is also defined for the types +`boost::variant` and +`boost::optional >`, where `T...` can be a list of arbitrary types. - It also inherits from `O, which makes it easy to treat like a + It also inherits from `O`, which makes it easy to treat like a tuple. \cgalHeading{Parameters} diff --git a/STL_Extension/include/CGAL/iterator.h b/STL_Extension/include/CGAL/iterator.h index 92d177b7a90..c801a71a324 100644 --- a/STL_Extension/include/CGAL/iterator.h +++ b/STL_Extension/include/CGAL/iterator.h @@ -1271,7 +1271,7 @@ struct Derivator, cpp11::tuple > // OutputIterator which accepts several types in *o++= and dispatches, -// wraps several other outputiterators, and dispatches accordingly. +// wraps several other output iterators, and dispatches accordingly. template < typename V, typename O > class Dispatch_output_iterator;