]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Add a class types_are_equal to allow a couple of template tricks.
authorbangerth <bangerth@0785d39b-7218-0410-832d-ea1e28bc413d>
Wed, 19 Nov 2008 21:13:26 +0000 (21:13 +0000)
committerbangerth <bangerth@0785d39b-7218-0410-832d-ea1e28bc413d>
Wed, 19 Nov 2008 21:13:26 +0000 (21:13 +0000)
git-svn-id: https://svn.dealii.org/trunk@17649 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/base/include/base/template_constraints.h
deal.II/doc/news/changes.h

index ea0ecff42e44d40e49830cce75e76bfb18ec2493..3043d667e052f4fcdcda3fb203971311baf0ad91 100644 (file)
@@ -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 <typename T>
+ *   void Vector<T>::some_operation () {
+ *     if (types_are_equal<T,double>::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 <typename T, typename U>
+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 <typename T>
+struct types_are_equal<T,T>
+{
+    static const bool value = true;
+};
+
+
+
 // --------------- inline functions -----------------
 
 
index b0a813ec1a51780e03dae263ee3fa84b9ba55179..bba9ca3ffd8690effcdc0287a65302f7e251a70b 100644 (file)
@@ -245,6 +245,16 @@ inconvenience this causes.
 <h3>base</h3>
 
 <ol>
+  <li>
+  <p>
+  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).
+  <br> 
+  (WB 2008/10/31)
+  </p>
+
   <li>
   <p>
   New: The Utilities::reverse_permutation and Utilities::invert_permutation

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.