]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Provide specializations for ProductType<T,T>. Add a test. 558/head
authorWolfgang Bangerth <bangerth@math.tamu.edu>
Mon, 16 Feb 2015 22:08:28 +0000 (16:08 -0600)
committerWolfgang Bangerth <bangerth@math.tamu.edu>
Mon, 16 Feb 2015 22:08:28 +0000 (16:08 -0600)
include/deal.II/base/template_constraints.h
tests/base/product_type_05.cc [new file with mode: 0644]
tests/base/product_type_05.output [new file with mode: 0644]

index b2aa1fa9c3be366c8042e5674a163f5ab52e2a98..b5b07894edefbb8589668cee0e0786af0a660e5d 100644 (file)
@@ -360,6 +360,12 @@ struct ProductType
 
 #ifndef DEAL_II_WITH_CXX11
 
+template <typename T>
+struct ProductType<T,T>
+{
+  typedef T type;
+};
+
 template <typename T>
 struct ProductType<T,double>
 {
diff --git a/tests/base/product_type_05.cc b/tests/base/product_type_05.cc
new file mode 100644 (file)
index 0000000..caeeb59
--- /dev/null
@@ -0,0 +1,66 @@
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2015 by the deal.II authors
+//
+// This file is part of the deal.II library.
+//
+// The deal.II library is free software; you can use it, redistribute
+// it, and/or modify it under the terms of the GNU Lesser General
+// Public License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+// The full text of the license can be found in the file LICENSE at
+// the top level of the deal.II distribution.
+//
+// ---------------------------------------------------------------------
+
+
+// test that ProductType<double,double> can be resolved. same for
+// ProductType<std::complex<double>,std::complex<double> >
+
+#include "../tests.h"
+#include <iomanip>
+#include <iomanip>
+#include <fstream>
+#include <cmath>
+#include <typeinfo>
+#include <complex>
+
+#include <deal.II/base/template_constraints.h>
+#include <deal.II/base/tensor.h>
+
+
+
+template <typename T, typename U, typename CompareType>
+void check()
+{
+  Assert (typeid(typename ProductType<T,U>::type) == typeid(CompareType),
+         ExcInternalError());
+  Assert (typeid(typename ProductType<T,U>::type) == typeid(T() * U()),
+         ExcInternalError());
+}
+
+
+int main()
+{
+  std::ofstream logfile("output");
+  deallog.attach(logfile);
+  deallog.depth_console(0);
+  deallog.threshold_double(1.e-10);
+
+  check<double,double,double>();
+  deallog << typename ProductType<double,double>::type(2.345)*typename ProductType<double,double>::type(3.456)
+         << ' '
+         << typename ProductType<double,double>::type(2.345*3.456)
+         << std::endl;
+  
+  check<std::complex<double>,std::complex<double>,std::complex<double> >();
+  deallog << (typename ProductType<std::complex<double>,std::complex<double> >::type(2.345, 1.23) *
+             typename ProductType<std::complex<double>,std::complex<double> >::type(3.456, 2.45))
+         << ' '
+         << (typename ProductType<std::complex<double>,std::complex<double> >::type
+             (std::complex<double>(2.345, 1.23) *
+              std::complex<double>(3.456, 2.45)))
+         << std::endl;
+  
+  deallog << "OK" << std::endl;
+}
diff --git a/tests/base/product_type_05.output b/tests/base/product_type_05.output
new file mode 100644 (file)
index 0000000..fe1bac9
--- /dev/null
@@ -0,0 +1,4 @@
+
+DEAL::8.10432 8.10432
+DEAL::(5.09082,9.99613) (5.09082,9.99613)
+DEAL::OK

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.