From: bangerth Date: Fri, 28 Jul 2006 17:17:15 +0000 (+0000) Subject: Add int2type X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7a83cbd3a0b22b2d9d89591ed612c3ed7cbda14b;p=dealii-svn.git Add int2type git-svn-id: https://svn.dealii.org/trunk@13474 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/base/include/base/template_constraints.h b/deal.II/base/include/base/template_constraints.h index 69977c0f25..0b285a6ed0 100644 --- a/deal.II/base/include/base/template_constraints.h +++ b/deal.II/base/include/base/template_constraints.h @@ -2,7 +2,7 @@ // $Id$ // Version: $Name$ // -// Copyright (C) 2003, 2004, 2005 by the deal.II authors +// Copyright (C) 2003, 2004, 2005, 2006 by the deal.II authors // // This file is subject to QPL and may not be distributed // without copyright and license information. Please refer @@ -143,6 +143,72 @@ struct PointerComparison +namespace internal +{ +/** + * A type that is sometimes used for template tricks. For example, in + * some situations one would like to do this: + * + * @verbatim + * template + * class X { + * // do something on subdim-dimensional sub-objects of the big + * // dim-dimensional thing (for example on vertices/lines/quads of + * // cells): + * template void f(); + * }; + * + * template + * template <> + * void X::f<0> () { ...operate on the vertices of a cell... } + * + * template void f(X &x) { + * x.f (); + * } + * @endverbatim + * + * The problem is: the language doesn't allow us to specialize + * X::f() without specializing the outer class first. One + * of the common tricks is therefore to use something like this: + * + * @verbatim + * template struct int2type {}; + * + * template + * class X { + * // do something on subdim-dimensional sub-objects of the big + * // dim-dimensional thing (for example on vertices/lines/quads of + * // cells): + * void f(int2type<0>); + * void f(int2type<1>); + * void f(int2type<2>); + * void f(int2type<3>); + * }; + * + * template + * void X::f (int2type<0>) { ...operate on the vertices of a cell... } + * + * template + * void X::f (int2type<1>) { ...operate on the lines of a cell... } + * + * template void f(X &x) { + * x.f (int2type()); + * } + * @endverbatim + * + * Note that we have replaced specialization of X::f() by + * overloading, but that from inside the function g(), we + * can still select which of the different X::f() we want + * based on the subdim template argument. + * + * @author Wolfgang Bangerth, 2006 + */ + template + struct int2type + {}; +} + + // --------------- inline functions -----------------