From b77b27a8adc651584cc6bf2b2a6fd4087c44f80a Mon Sep 17 00:00:00 2001 From: Sylvain Pion Date: Wed, 21 Oct 2009 16:26:00 +0000 Subject: [PATCH] Implement Mariette's review comments. --- .../doc_tex/STL_Extension_ref/Default.tex | 34 ++++++++++--------- .../examples/STL_Extension/Default.cpp | 13 ++++--- 2 files changed, 27 insertions(+), 20 deletions(-) diff --git a/STL_Extension/doc_tex/STL_Extension_ref/Default.tex b/STL_Extension/doc_tex/STL_Extension_ref/Default.tex index 9926f45b9a8..b22f39d0ccd 100644 --- a/STL_Extension/doc_tex/STL_Extension_ref/Default.tex +++ b/STL_Extension/doc_tex/STL_Extension_ref/Default.tex @@ -1,8 +1,8 @@ \begin{ccRefClass}{Default} \ccDefinition -\ccRefName\ is a tag class. It can be used to explicitly state that one wants -to use the default value of a template parameter of a class template. +\ccRefName\ is a tag class. It can be used to state that one wants +to use the default argument of a template parameter of a class template. This can be useful in several cases: (a) when one needs a non-default value for another template parameter coming next (since \CC\ only supports defaults at @@ -12,29 +12,31 @@ error messages and mangled symbol names), (c) when defining the default involves circular dependencies of type instantiations (there, it breaks the cycle in a nice way). -In order for this mechanism to work, the template class needs to do some -special treatment, and its documentation should state whether or not this -possibility is supported. +Using the mechanism is easy~: just plug \ccRefName\ as template argument +in the place where you would like to use the default. You should refer +to the documentation of the template class you are using in order to know +whether this functionality is offered. -Also beware that the type of the template class will not be the same when -instantiating it using \ccRefName\ instead of the real default type, even -though their interface will otherwise be the same. This may have consequences -in some rare cases. +Also beware that the type of the instantiated template class will not be the +same when instantiating it using \ccRefName\ instead of the type of the default +argument, even though their interfaces will otherwise be the same. This may +have consequences in some cases. \ccIsModel \ccc{DefaultConstructible, CopyConstructible} \begin{ccAdvanced} +In order to help the template class writer, \ccRefName\ provides a convenient +way to extract the desired type for a template parameter which may be defaulted +using \ccRefName. It is enough to fetch the type as +\ccc{Default::Get::type}, as in the example program below. + \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 struct Get;} -{A nested template providing a typedef \ccc{type} which equals \ccc{Value} if -\ccc{Argument} is \ccRefName, and \ccc{Argument} otherwise.} +\ccNestedType{template struct Get;} +{A nested template providing a typedef \ccc{type} which equals \ccc{Type} if +\ccc{Parameter} is \ccRefName, and \ccc{Parameter} otherwise.} \end{ccAdvanced} diff --git a/STL_Extension/examples/STL_Extension/Default.cpp b/STL_Extension/examples/STL_Extension/Default.cpp index a5b7d819122..b1335f18830 100644 --- a/STL_Extension/examples/STL_Extension/Default.cpp +++ b/STL_Extension/examples/STL_Extension/Default.cpp @@ -1,14 +1,19 @@ #include -// A will be used as the concrete default type +// A is a concrete type struct A {}; -// B is the template class which has 2 template arguments with defaults -template < typename A1_ = A, // we could also write "= CGAL::Default" here instead - typename A2 = int > +// B is the template class which has 2 template parameters +// with default arguments : A and int. +template < typename A1_ = A, typename A2 = int > struct B { + // Note that it is also possible to use CGAL::Default + // instead of A as the default argument for A1_ above. + + // Extract the desired type for A1 : typedef typename CGAL::Default::Get::type A1; + A1 a1; };