Reference documentation for deal.II version 9.1.0-pre
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.md at
12 // the top level directory of deal.II.
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 
22 #include <deal.II/base/complex_overloads.h>
23 
24 #include <complex>
25 #include <utility>
26 
27 DEAL_II_NAMESPACE_OPEN
28 
29 namespace internal
30 {
31  namespace TemplateConstraints
32  {
33  // helper struct for is_base_of_all and all_same_as
34  template <bool... Values>
35  struct BoolStorage;
36 
37 
42  template <bool... Values>
43  struct all_true
44  {
45  static constexpr bool value =
46  std::is_same<BoolStorage<Values..., true>,
47  BoolStorage<true, Values...>>::value;
48  };
49  } // namespace TemplateConstraints
50 } // namespace internal
51 
58 template <class Base, class... Derived>
60 {
61  static constexpr bool value = internal::TemplateConstraints::all_true<
62  std::is_base_of<Base, Derived>::value...>::value;
63 };
64 
65 
66 
73 template <class Type, class... Types>
75 {
76  static constexpr bool value = internal::TemplateConstraints::all_true<
77  std::is_same<Type, Types>::value...>::value;
78 };
79 
80 
81 
82 /*
83  * A generalization of `std::enable_if` that only works if
84  * <i>all</i> of the given boolean template parameters are
85  * true.
86  */
87 template <bool... Values>
88 struct enable_if_all
89  : std::enable_if<internal::TemplateConstraints::all_true<Values...>::value>
90 {};
91 
92 
93 
94 template <bool, typename>
95 struct constraint_and_return_value;
96 
97 
173 template <typename T>
174 struct DEAL_II_DEPRECATED constraint_and_return_value<true, T>
175 {
176  using type = T;
177 };
178 
179 
180 
240 template <typename T>
241 struct identity
242 {
243  using type = T;
244 };
245 
246 
247 
267 {
272  template <typename T>
273  static bool
274  equal(const T *p1, const T *p2)
275  {
276  return (p1 == p2);
277  }
278 
279 
286  template <typename T, typename U>
287  static bool
288  equal(const T *, const U *)
289  {
290  return false;
291  }
292 };
293 
294 
295 
296 namespace internal
297 {
374  template <int N>
375  struct DEAL_II_DEPRECATED int2type
376  {};
377 
378 
386  template <bool B>
387  struct DEAL_II_DEPRECATED bool2type
388  {};
389 } // namespace internal
390 
391 
392 
413 template <typename T, typename U>
414 struct DEAL_II_DEPRECATED types_are_equal : std::is_same<T, U>
415 {};
416 
417 
418 
419 namespace internal
420 {
433  template <typename T, typename U>
435  {
436  using type = decltype(std::declval<T>() * std::declval<U>());
437  };
438 
439 } // namespace internal
440 
441 
442 
491 template <typename T, typename U>
492 struct ProductType
493 {
494  using type =
496  typename std::decay<U>::type>::type;
497 };
498 
499 namespace internal
500 {
501  // Annoyingly, there is no std::complex<T>::operator*(U) for scalars U
502  // other than T (not even in C++11, or C++14). We provide our own overloads
503  // in base/complex_overloads.h, but in order for them to work, we have to
504  // manually specify all products we want to allow:
505 
506  template <typename T>
507  struct ProductTypeImpl<std::complex<T>, std::complex<T>>
508  {
509  using type = std::complex<T>;
510  };
511 
512  template <typename T, typename U>
513  struct ProductTypeImpl<std::complex<T>, std::complex<U>>
514  {
515  using type = std::complex<typename ProductType<T, U>::type>;
516  };
517 
518  template <typename U>
519  struct ProductTypeImpl<double, std::complex<U>>
520  {
521  using type = std::complex<typename ProductType<double, U>::type>;
522  };
523 
524  template <typename T>
525  struct ProductTypeImpl<std::complex<T>, double>
526  {
527  using type = std::complex<typename ProductType<T, double>::type>;
528  };
529 
530  template <typename U>
531  struct ProductTypeImpl<float, std::complex<U>>
532  {
533  using type = std::complex<typename ProductType<float, U>::type>;
534  };
535 
536  template <typename T>
537  struct ProductTypeImpl<std::complex<T>, float>
538  {
539  using type = std::complex<typename ProductType<T, float>::type>;
540  };
541 
542 } // namespace internal
543 
544 
545 
603 template <typename T>
604 struct EnableIfScalar;
605 
606 
607 template <>
608 struct EnableIfScalar<double>
609 {
610  using type = double;
611 };
612 
613 template <>
614 struct EnableIfScalar<float>
615 {
616  using type = float;
617 };
618 
619 template <>
620 struct EnableIfScalar<long double>
621 {
622  using type = long double;
623 };
624 
625 template <>
626 struct EnableIfScalar<int>
627 {
628  using type = int;
629 };
630 
631 template <>
632 struct EnableIfScalar<unsigned int>
633 {
634  using type = unsigned int;
635 };
636 
637 template <typename T>
638 struct EnableIfScalar<std::complex<T>>
639 {
640  using type = std::complex<T>;
641 };
642 
643 
644 DEAL_II_NAMESPACE_CLOSE
645 
646 #endif
static bool equal(const T *, const U *)
static bool equal(const T *p1, const T *p2)