Reference documentation for deal.II version 9.1.1
\(\newcommand{\dealcoloneq}{\mathrel{\vcenter{:}}=}\)
template_constraints.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2003 - 2019 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 <iterator>
26 #include <utility>
27 
28 DEAL_II_NAMESPACE_OPEN
29 
30 namespace internal
31 {
32  namespace TemplateConstraints
33  {
34  // helper struct for is_base_of_all and all_same_as
35  template <bool... Values>
36  struct BoolStorage;
37 
38 
43  template <bool... Values>
44  struct all_true
45  {
46  static constexpr bool value =
47  std::is_same<BoolStorage<Values..., true>,
48  BoolStorage<true, Values...>>::value;
49  };
50  } // namespace TemplateConstraints
51 } // namespace internal
52 
59 template <class Base, class... Derived>
61 {
62  static constexpr bool value = internal::TemplateConstraints::all_true<
63  std::is_base_of<Base, Derived>::value...>::value;
64 };
65 
66 
67 
74 template <class Type, class... Types>
76 {
77  static constexpr bool value = internal::TemplateConstraints::all_true<
78  std::is_same<Type, Types>::value...>::value;
79 };
80 
81 
82 
83 /*
84  * A generalization of `std::enable_if` that only works if
85  * <i>all</i> of the given boolean template parameters are
86  * true.
87  */
88 template <bool... Values>
89 struct enable_if_all
90  : std::enable_if<internal::TemplateConstraints::all_true<Values...>::value>
91 {};
92 
93 
94 
100 template <typename T>
102 {
103  template <typename C>
104  static std::false_type
105  test(...);
106 
107  template <typename C>
108  static auto
109  test(int) -> decltype(std::begin(std::declval<C>()),
110  std::end(std::declval<C>()),
111  std::true_type());
112 
113 public:
114  using type = decltype(test<T>(0));
115 
116  static const bool value = type::value;
117 };
118 
119 
120 
121 template <bool, typename>
122 struct constraint_and_return_value;
123 
124 
200 template <typename T>
201 struct DEAL_II_DEPRECATED constraint_and_return_value<true, T>
202 {
203  using type = T;
204 };
205 
206 
207 
267 template <typename T>
268 struct identity
269 {
270  using type = T;
271 };
272 
273 
274 
294 {
299  template <typename T>
300  static bool
301  equal(const T *p1, const T *p2)
302  {
303  return (p1 == p2);
304  }
305 
306 
313  template <typename T, typename U>
314  static bool
315  equal(const T *, const U *)
316  {
317  return false;
318  }
319 };
320 
321 
322 
323 namespace internal
324 {
401  template <int N>
402  struct DEAL_II_DEPRECATED int2type
403  {};
404 
405 
413  template <bool B>
414  struct DEAL_II_DEPRECATED bool2type
415  {};
416 } // namespace internal
417 
418 
419 
440 template <typename T, typename U>
441 struct DEAL_II_DEPRECATED types_are_equal : std::is_same<T, U>
442 {};
443 
444 
445 
446 namespace internal
447 {
460  template <typename T, typename U>
462  {
463  using type = decltype(std::declval<T>() * std::declval<U>());
464  };
465 
466 } // namespace internal
467 
468 
469 
518 template <typename T, typename U>
519 struct ProductType
520 {
521  using type =
523  typename std::decay<U>::type>::type;
524 };
525 
526 namespace internal
527 {
528  // Annoyingly, there is no std::complex<T>::operator*(U) for scalars U
529  // other than T (not even in C++11, or C++14). We provide our own overloads
530  // in base/complex_overloads.h, but in order for them to work, we have to
531  // manually specify all products we want to allow:
532 
533  template <typename T>
534  struct ProductTypeImpl<std::complex<T>, std::complex<T>>
535  {
536  using type = std::complex<T>;
537  };
538 
539  template <typename T, typename U>
540  struct ProductTypeImpl<std::complex<T>, std::complex<U>>
541  {
542  using type = std::complex<typename ProductType<T, U>::type>;
543  };
544 
545  template <typename U>
546  struct ProductTypeImpl<double, std::complex<U>>
547  {
548  using type = std::complex<typename ProductType<double, U>::type>;
549  };
550 
551  template <typename T>
552  struct ProductTypeImpl<std::complex<T>, double>
553  {
554  using type = std::complex<typename ProductType<T, double>::type>;
555  };
556 
557  template <typename U>
558  struct ProductTypeImpl<float, std::complex<U>>
559  {
560  using type = std::complex<typename ProductType<float, U>::type>;
561  };
562 
563  template <typename T>
564  struct ProductTypeImpl<std::complex<T>, float>
565  {
566  using type = std::complex<typename ProductType<T, float>::type>;
567  };
568 
569 } // namespace internal
570 
571 
572 
630 template <typename T>
631 struct EnableIfScalar;
632 
633 
634 template <>
635 struct EnableIfScalar<double>
636 {
637  using type = double;
638 };
639 
640 template <>
641 struct EnableIfScalar<float>
642 {
643  using type = float;
644 };
645 
646 template <>
647 struct EnableIfScalar<long double>
648 {
649  using type = long double;
650 };
651 
652 template <>
653 struct EnableIfScalar<int>
654 {
655  using type = int;
656 };
657 
658 template <>
659 struct EnableIfScalar<unsigned int>
660 {
661  using type = unsigned int;
662 };
663 
664 template <typename T>
665 struct EnableIfScalar<std::complex<T>>
666 {
667  using type = std::complex<T>;
668 };
669 
670 
671 DEAL_II_NAMESPACE_CLOSE
672 
673 #endif
STL namespace.
static bool equal(const T *, const U *)
static bool equal(const T *p1, const T *p2)