Reference documentation for deal.II version 9.2.0
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
template_constraints.h
Go to the documentation of this file.
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2003 - 2020 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 
23 
24 #include <complex>
25 #include <iterator>
26 #include <utility>
27 
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 {
64 };
65 
66 
67 
74 template <class Type, class... Types>
76 {
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>
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>
123 
124 
200 template <typename 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 
343 template <typename T, typename U>
344 struct DEAL_II_DEPRECATED types_are_equal : std::is_same<T, U>
345 {};
346 
347 
348 
349 namespace internal
350 {
363  template <typename T, typename U>
365  {
366  using type = decltype(std::declval<T>() * std::declval<U>());
367  };
368 
369 } // namespace internal
370 
371 
372 
421 template <typename T, typename U>
423 {
424  using type =
426  typename std::decay<U>::type>::type;
427 };
428 
429 namespace internal
430 {
431  // Annoyingly, there is no std::complex<T>::operator*(U) for scalars U
432  // other than T (not even in C++11, or C++14). We provide our own overloads
433  // in base/complex_overloads.h, but in order for them to work, we have to
434  // manually specify all products we want to allow:
435 
436  template <typename T>
437  struct ProductTypeImpl<std::complex<T>, std::complex<T>>
438  {
439  using type = std::complex<T>;
440  };
441 
442  template <typename T, typename U>
443  struct ProductTypeImpl<std::complex<T>, std::complex<U>>
444  {
445  using type = std::complex<typename ProductType<T, U>::type>;
446  };
447 
448  template <typename U>
449  struct ProductTypeImpl<double, std::complex<U>>
450  {
451  using type = std::complex<typename ProductType<double, U>::type>;
452  };
453 
454  template <typename T>
455  struct ProductTypeImpl<std::complex<T>, double>
456  {
457  using type = std::complex<typename ProductType<T, double>::type>;
458  };
459 
460  template <typename U>
461  struct ProductTypeImpl<float, std::complex<U>>
462  {
463  using type = std::complex<typename ProductType<float, U>::type>;
464  };
465 
466  template <typename T>
467  struct ProductTypeImpl<std::complex<T>, float>
468  {
469  using type = std::complex<typename ProductType<T, float>::type>;
470  };
471 
472 } // namespace internal
473 
474 
475 
533 template <typename T>
535 
536 
537 template <>
539 {
540  using type = double;
541 };
542 
543 template <>
544 struct EnableIfScalar<float>
545 {
546  using type = float;
547 };
548 
549 template <>
550 struct EnableIfScalar<long double>
551 {
552  using type = long double;
553 };
554 
555 template <>
557 {
558  using type = int;
559 };
560 
561 template <>
562 struct EnableIfScalar<unsigned int>
563 {
564  using type = unsigned int;
565 };
566 
567 template <typename T>
568 struct EnableIfScalar<std::complex<T>>
569 {
570  using type = std::complex<T>;
571 };
572 
573 
575 
576 #endif
identity::type
T type
Definition: template_constraints.h:270
internal::ProductTypeImpl< double, std::complex< U > >::type
std::complex< typename ProductType< double, U >::type > type
Definition: template_constraints.h:451
internal::ProductTypeImpl< std::complex< T >, std::complex< U > >::type
std::complex< typename ProductType< T, U >::type > type
Definition: template_constraints.h:445
is_base_of_all
Definition: template_constraints.h:60
PointerComparison::equal
static bool equal(const T *p1, const T *p2)
Definition: template_constraints.h:301
EnableIfScalar< std::complex< T > >::type
std::complex< T > type
Definition: template_constraints.h:570
has_begin_and_end
Definition: template_constraints.h:101
LAPACKSupport::U
static const char U
Definition: lapack_support.h:167
internal::ProductTypeImpl< std::complex< T >, double >::type
std::complex< typename ProductType< T, double >::type > type
Definition: template_constraints.h:457
ProductType::type
typename internal::ProductTypeImpl< typename std::decay< T >::type, typename std::decay< U >::type >::type type
Definition: template_constraints.h:426
EnableIfScalar< long double >::type
long double type
Definition: template_constraints.h:552
identity
Definition: template_constraints.h:268
ProductType
Definition: template_constraints.h:422
LAPACKSupport::T
static const char T
Definition: lapack_support.h:163
constraint_and_return_value< true, T >::type
T type
Definition: template_constraints.h:203
internal::ProductTypeImpl< std::complex< T >, std::complex< T > >::type
std::complex< T > type
Definition: template_constraints.h:439
double
TrilinosWrappers::internal::begin
VectorType::value_type * begin(VectorType &V)
Definition: trilinos_sparse_matrix.cc:51
EnableIfScalar< float >::type
float type
Definition: template_constraints.h:546
PointerComparison::equal
static bool equal(const T *, const U *)
Definition: template_constraints.h:315
DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:358
TrilinosWrappers::internal::end
VectorType::value_type * end(VectorType &V)
Definition: trilinos_sparse_matrix.cc:65
DEAL_II_DEPRECATED
#define DEAL_II_DEPRECATED
Definition: config.h:98
constraint_and_return_value
Definition: template_constraints.h:122
internal::ProductTypeImpl< std::complex< T >, float >::type
std::complex< typename ProductType< T, float >::type > type
Definition: template_constraints.h:469
enable_if_all
Definition: template_constraints.h:89
complex_overloads.h
unsigned int
value
static const bool value
Definition: dof_tools_constraints.cc:433
internal::ProductTypeImpl< float, std::complex< U > >::type
std::complex< typename ProductType< float, U >::type > type
Definition: template_constraints.h:463
has_begin_and_end::test
static std::false_type test(...)
types_are_equal
Definition: template_constraints.h:344
has_begin_and_end::value
static const bool value
Definition: template_constraints.h:116
PointerComparison
Definition: template_constraints.h:293
all_same_as
Definition: template_constraints.h:75
config.h
all_same_as::value
static constexpr bool value
Definition: template_constraints.h:77
EnableIfScalar
Definition: template_constraints.h:534
internal::TemplateConstraints::all_true::value
static constexpr bool value
Definition: template_constraints.h:46
is_base_of_all::value
static constexpr bool value
Definition: template_constraints.h:62
internal
Definition: aligned_vector.h:369
DEAL_II_NAMESPACE_CLOSE
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:359
internal::TemplateConstraints::all_true
Definition: template_constraints.h:44
has_begin_and_end::type
decltype(test< T >(0)) type
Definition: template_constraints.h:114
internal::ProductTypeImpl
Definition: template_constraints.h:364
internal::TemplateConstraints::BoolStorage
Definition: template_constraints.h:36
internal::ProductTypeImpl::type
decltype(std::declval< T >() *std::declval< U >()) type
Definition: template_constraints.h:366
int