From: bangerth Date: Wed, 19 Nov 2008 21:13:26 +0000 (+0000) Subject: Add a class types_are_equal to allow a couple of template tricks. X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=75426b4066b5cb89edb20437d0f2ffd148455b15;p=dealii-svn.git Add a class types_are_equal to allow a couple of template tricks. git-svn-id: https://svn.dealii.org/trunk@17649 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 ea0ecff42e..3043d667e0 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, 2006 by the deal.II authors +// Copyright (C) 2003, 2004, 2005, 2006, 2008 by the deal.II authors // // This file is subject to QPL and may not be distributed // without copyright and license information. Please refer @@ -210,6 +210,43 @@ namespace internal } + +/** + * A type that can be used to determine whether two types are equal. + * It allows to write code like + * @code + * template + * void Vector::some_operation () { + * if (types_are_equal::value == true) + * call_some_blas_function_for_doubles; + * else + * do_it_by_hand; + * } + * @endcode + * + * This construct is made possible through the existence of a partial + * specialization of the class for template arguments that are equal. + */ +template +struct types_are_equal +{ + static const bool value = false; +}; + + +/** + * Partial specialization of the general template for the case that + * both template arguments are equal. See the documentation of the + * general template for more information. + */ +template +struct types_are_equal +{ + static const bool value = true; +}; + + + // --------------- inline functions ----------------- diff --git a/deal.II/doc/news/changes.h b/deal.II/doc/news/changes.h index b0a813ec1a..bba9ca3ffd 100644 --- a/deal.II/doc/news/changes.h +++ b/deal.II/doc/news/changes.h @@ -245,6 +245,16 @@ inconvenience this causes.

base

    +
  1. +

    + New: The new class types_are_equal allows to write some templates more + efficient by allowing to figure out whether certain template types are, + for example, equal to double or float (in which case we can use + BLAS functions, or could do something else special). +
    + (WB 2008/10/31) +

    +
  2. New: The Utilities::reverse_permutation and Utilities::invert_permutation