Reference documentation for deal.II version 9.0.0
template_constraints.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2003 - 2018 by the deal.II authors
4 //
5 // This file is part of the deal.II library.
6 //
7 // The deal.II library is free software; you can use it, redistribute
8 // it, and/or modify it under the terms of the GNU Lesser General
9 // Public License as published by the Free Software Foundation; either
10 // version 2.1 of the License, or (at your option) any later version.
11 // The full text of the license can be found in the file LICENSE at
12 // the top level of the deal.II distribution.
13 //
14 // ---------------------------------------------------------------------
15 
16 #ifndef dealii_template_constraints_h
17 #define dealii_template_constraints_h
18 
19 
20 #include <deal.II/base/config.h>
21 #include <deal.II/base/complex_overloads.h>
22 
23 #include <complex>
24 #include <utility>
25 
26 DEAL_II_NAMESPACE_OPEN
27 
28 namespace internal
29 {
30  namespace TemplateConstraints
31  {
32  // helper struct for is_base_of_all and all_same_as
33  template <bool... Values> struct BoolStorage;
34 
35 
40  template <bool... Values>
41  struct all_true
42  {
43  static constexpr bool value =
44  std::is_same<BoolStorage<Values..., true>,
45  BoolStorage<true, Values...>>::value;
46  };
47  }
48 }
49 
56 template <class Base, class... Derived>
58 {
59  static constexpr bool value =
61 };
62 
63 
64 
71 template <class Type, class... Types>
73 {
74  static constexpr bool value =
76 };
77 
78 
79 
80 /*
81  * A generalization of `std::enable_if` that only works if
82  * <i>all</i> of the given boolean template parameters are
83  * true.
84  */
85 template <bool... Values>
86 struct enable_if_all : std::enable_if<internal::TemplateConstraints::all_true<Values...>::value>
87 {};
88 
89 
90 
91 template <bool, typename> struct constraint_and_return_value;
92 
93 
151 template <typename T>
152 struct DEAL_II_DEPRECATED constraint_and_return_value<true,T>
153 {
154  typedef T type;
155 };
156 
157 
158 
210 template <typename T>
211 struct identity
212 {
213  typedef T type;
214 };
215 
216 
217 
237 {
242  template <typename T>
243  static bool equal (const T *p1, const T *p2)
244  {
245  return (p1==p2);
246  }
247 
248 
255  template <typename T, typename U>
256  static bool equal (const T *, const U *)
257  {
258  return false;
259  }
260 
261 };
262 
263 
264 
265 namespace internal
266 {
327  template <int N>
328  struct DEAL_II_DEPRECATED int2type
329  {};
330 
331 
339  template <bool B>
340  struct DEAL_II_DEPRECATED bool2type
341  {};
342 }
343 
344 
345 
365 template <typename T, typename U>
366 struct DEAL_II_DEPRECATED types_are_equal : std::is_same<T,U>
367 {};
368 
369 
370 
371 namespace internal
372 {
373 
386  template <typename T, typename U>
388  {
389  typedef decltype(std::declval<T>() * std::declval<U>()) type;
390  };
391 
392 }
393 
394 
395 
444 template <typename T, typename U>
445 struct ProductType
446 {
447  typedef typename internal::ProductTypeImpl<
448  typename std::decay<T>::type, typename std::decay<U>::type>::type type;
449 };
450 
451 namespace internal
452 {
453 
454  // Annoyingly, there is no std::complex<T>::operator*(U) for scalars U
455  // other than T (not even in C++11, or C++14). We provide our own overloads
456  // in base/complex_overloads.h, but in order for them to work, we have to
457  // manually specify all products we want to allow:
458 
459  template <typename T>
460  struct ProductTypeImpl<std::complex<T>,std::complex<T> >
461  {
462  typedef std::complex<T> type;
463  };
464 
465  template <typename T, typename U>
466  struct ProductTypeImpl<std::complex<T>,std::complex<U> >
467  {
468  typedef std::complex<typename ProductType<T,U>::type> type;
469  };
470 
471  template <typename U>
472  struct ProductTypeImpl<double,std::complex<U> >
473  {
474  typedef std::complex<typename ProductType<double,U>::type> type;
475  };
476 
477  template <typename T>
478  struct ProductTypeImpl<std::complex<T>,double>
479  {
480  typedef std::complex<typename ProductType<T,double>::type> type;
481  };
482 
483  template <typename U>
484  struct ProductTypeImpl<float,std::complex<U> >
485  {
486  typedef std::complex<typename ProductType<float,U>::type> type;
487  };
488 
489  template <typename T>
490  struct ProductTypeImpl<std::complex<T>,float>
491  {
492  typedef std::complex<typename ProductType<T,float>::type> type;
493  };
494 
495 }
496 
497 
498 
550 template <typename T>
551 struct EnableIfScalar;
552 
553 
554 template <> struct EnableIfScalar<double>
555 {
556  typedef double type;
557 };
558 
559 template <> struct EnableIfScalar<float>
560 {
561  typedef float type;
562 };
563 
564 template <> struct EnableIfScalar<long double>
565 {
566  typedef long double type;
567 };
568 
569 template <> struct EnableIfScalar<int>
570 {
571  typedef int type;
572 };
573 
574 template <> struct EnableIfScalar<unsigned int>
575 {
576  typedef unsigned int type;
577 };
578 
579 template <typename T> struct EnableIfScalar<std::complex<T> >
580 {
581  typedef std::complex<T> type;
582 };
583 
584 
585 DEAL_II_NAMESPACE_CLOSE
586 
587 #endif
STL namespace.
static bool equal(const T *, const U *)
static bool equal(const T *p1, const T *p2)