mirror of https://github.com/CGAL/cgal
doc+example for CGAL::Default.
This commit is contained in:
parent
f55c8e9a2f
commit
9aff782550
|
|
@ -28,6 +28,8 @@ arguments and for composition, functors for projection and creation and
|
|||
adaptor classes around iterators and circulators. See also circulators in
|
||||
Chapter~\ref{chapterCirculators}. A class storing polymorphic objects
|
||||
is also provided, as well as a class to manage the uncertainty of some values.
|
||||
Finally, a class which helps specifying that the default types in template
|
||||
parameter lists are desired is also provided.
|
||||
|
||||
\section{Doubly-Connected List Managing Items in Place}
|
||||
|
||||
|
|
@ -133,3 +135,11 @@ but it is important that providers of predicates that are meant to be
|
|||
filtered by \ccc{Filtered_predicate}, know about it.
|
||||
|
||||
It can also be used in other contexts as well, as it is a general tool.
|
||||
|
||||
\section{Default types in template arguments lists}
|
||||
|
||||
In \CC, it is possible to specify defaults at the end of a template argument
|
||||
list. Specifying that one wishes to use the default is simply done by omitting
|
||||
it. This is however possible only at the end of the list. \ccc{CGAL::Default}
|
||||
provides a simple mechanism that performs something equivalent anywhere in the
|
||||
sequence.
|
||||
|
|
|
|||
|
|
@ -0,0 +1,45 @@
|
|||
\begin{ccRefClass}{Default}
|
||||
|
||||
\ccDefinition
|
||||
\ccRefName\ is a tag class to be used in a template parameter list, in order to
|
||||
indicate that the default value is to be considered.
|
||||
|
||||
This is shorter and clearer than actually writing the default type, which may
|
||||
sometimes be complicated, and might even change in the future. The \CC\ language
|
||||
only provides a possibility when no following argument needs to be non-defaulted.
|
||||
|
||||
It can also be useful to shorten compiler error messages and mangled symbol names,
|
||||
and also to help define defaults in rare cases that involve circular
|
||||
dependencies, by breaking the cycle in a simple way.
|
||||
|
||||
Note that there is no magic : this only works if the template class where
|
||||
\ccRefName\ is plugged-in takes special care for it, so you should refer to the
|
||||
manual of such classes to know whether this possibility is offered.
|
||||
|
||||
Beware that, of course, the resulting template type parameterized by \ccRefName\ will
|
||||
not formally be the same type as the one parameterized by the actual documented,
|
||||
expanded, default. This may have consequences.
|
||||
|
||||
\ccIsModel
|
||||
\ccc{DefaultConstructible, CopyConstructible}
|
||||
|
||||
\begin{ccAdvanced}
|
||||
|
||||
\ccTypes
|
||||
|
||||
In order to help the template class writer, \ccRefName\ provides a
|
||||
convenient way to extract the desired value for an argument which may be
|
||||
defaulted using \ccRefName.
|
||||
|
||||
\ccNestedType{template <typename Argument, typename Value> struct Get;}
|
||||
{This nested template offers a further nested type \ccc{type} which is either
|
||||
equal to \ccc{Argument} if \ccc{Argument} is not \ccRefName\, or
|
||||
\ccc{Value} otherwise.}
|
||||
|
||||
\end{ccAdvanced}
|
||||
|
||||
\ccHeading{Example code}
|
||||
|
||||
\ccIncludeExampleCode{STL_Extension/Default.cpp}
|
||||
|
||||
\end{ccRefClass}
|
||||
|
|
@ -32,6 +32,7 @@
|
|||
\input{STL_Extension_ref/stl_extension.tex}
|
||||
\input{STL_Extension_ref/Uncertain.tex}
|
||||
\input{STL_Extension_ref/array.tex}
|
||||
\input{STL_Extension_ref/Default.tex}
|
||||
|
||||
%%\cgalColumnLayout
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,18 @@
|
|||
#include <CGAL/Default.h>
|
||||
|
||||
struct A {};
|
||||
|
||||
template < typename A1_ = A, // we could also write CGAL::Default here instead
|
||||
typename A2 = int >
|
||||
struct B
|
||||
{
|
||||
typedef typename CGAL::Default::Get<A1_, A>::type A1;
|
||||
A1 a1;
|
||||
};
|
||||
|
||||
int main ()
|
||||
{
|
||||
B<CGAL::Default, double> b;
|
||||
|
||||
A a = b.a1; // It is really of type A.
|
||||
}
|
||||
Loading…
Reference in New Issue