Reference documentation for deal.II version 8.5.1
template_constraints.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2003 - 2015 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 template <bool, typename> struct constraint_and_return_value;
29 
30 
86 template <typename T> struct constraint_and_return_value<true,T>
87 {
88  typedef T type;
89 };
90 
91 
92 
144 template <typename T>
145 struct identity
146 {
147  typedef T type;
148 };
149 
150 
151 
171 {
176  template <typename T>
177  static bool equal (const T *p1, const T *p2);
178 
185  template <typename T, typename U>
186  static bool equal (const T *, const U *);
187 };
188 
189 
190 
191 namespace internal
192 {
251  template <int N>
252  struct int2type
253  {};
254 
255 
261  template <bool B>
262  struct bool2type
263  {};
264 }
265 
266 
267 
284 template <typename T, typename U>
286 {
287  static const bool value = false;
288 };
289 
290 
296 template <typename T>
297 struct types_are_equal<T,T>
298 {
299  static const bool value = true;
300 };
301 
302 
303 
352 template <typename T, typename U>
353 struct ProductType
354 {
355 #ifdef DEAL_II_WITH_CXX11
356  typedef decltype(std::declval<T>() * std::declval<U>()) type;
357 #endif
358 };
359 
360 #ifndef DEAL_II_WITH_CXX11
361 
362 template <typename T>
363 struct ProductType<T,T>
364 {
365  typedef T type;
366 };
367 
368 template <typename T>
369 struct ProductType<T,bool>
370 {
371  typedef T type;
372 };
373 
374 template <typename T>
375 struct ProductType<bool, T>
376 {
377  typedef T type;
378 };
379 
380 template <>
381 struct ProductType<bool,double>
382 {
383  typedef double type;
384 };
385 
386 template <>
387 struct ProductType<double,bool>
388 {
389  typedef double type;
390 };
391 
392 template <>
393 struct ProductType<double,float>
394 {
395  typedef double type;
396 };
397 
398 template <>
399 struct ProductType<float,double>
400 {
401  typedef double type;
402 };
403 
404 template <>
405 struct ProductType<double,long double>
406 {
407  typedef long double type;
408 };
409 
410 template <>
411 struct ProductType<long double,double>
412 {
413  typedef long double type;
414 };
415 
416 template <>
417 struct ProductType<double,int>
418 {
419  typedef double type;
420 };
421 
422 template <>
423 struct ProductType<int,double>
424 {
425  typedef double type;
426 };
427 
428 template <>
429 struct ProductType<float,int>
430 {
431  typedef float type;
432 };
433 
434 template <>
435 struct ProductType<int,float>
436 {
437  typedef float type;
438 };
439 
440 template <>
441 struct ProductType<double, unsigned int>
442 {
443  typedef double type;
444 };
445 
446 template <>
447 struct ProductType<unsigned int, double>
448 {
449  typedef double type;
450 };
451 
452 template <>
453 struct ProductType<float,unsigned int>
454 {
455  typedef float type;
456 };
457 
458 template <>
459 struct ProductType<unsigned int,float>
460 {
461  typedef float type;
462 };
463 
464 #endif
465 
466 // Annoyingly, there is no std::complex<T>::operator*(U) for scalars U
467 // other than T (not even in C++11, or C++14). We provide our own overloads
468 // in base/complex_overloads.h, but in order for them to work, we have to
469 // manually specify all products we want to allow:
470 
471 template <typename T>
472 struct ProductType<std::complex<T>,std::complex<T> >
473 {
474  typedef std::complex<T> type;
475 };
476 
477 template <typename T, typename U>
478 struct ProductType<std::complex<T>,std::complex<U> >
479 {
480  typedef std::complex<typename ProductType<T,U>::type> type;
481 };
482 
483 template <typename U>
484 struct ProductType<double,std::complex<U> >
485 {
486  typedef std::complex<typename ProductType<double,U>::type> type;
487 };
488 
489 template <typename T>
490 struct ProductType<std::complex<T>,double>
491 {
492  typedef std::complex<typename ProductType<T,double>::type> type;
493 };
494 
495 
496 template <typename U>
497 struct ProductType<float,std::complex<U> >
498 {
499  typedef std::complex<typename ProductType<float,U>::type> type;
500 };
501 
502 template <typename T>
503 struct ProductType<std::complex<T>,float>
504 {
505  typedef std::complex<typename ProductType<T,float>::type> type;
506 };
507 
508 
509 
561 template <typename T>
562 struct EnableIfScalar;
563 
564 
565 template <> struct EnableIfScalar<double>
566 {
567  typedef double type;
568 };
569 
570 
571 template <> struct EnableIfScalar<float>
572 {
573  typedef float type;
574 };
575 
576 
577 template <> struct EnableIfScalar<long double>
578 {
579  typedef long double type;
580 };
581 
582 
583 template <> struct EnableIfScalar<int>
584 {
585  typedef int type;
586 };
587 
588 
589 template <> struct EnableIfScalar<unsigned int>
590 {
591  typedef unsigned int type;
592 };
593 
594 
595 
596 template <typename T> struct EnableIfScalar<std::complex<T> >
597 {
598  typedef std::complex<T> type;
599 };
600 
601 
602 // --------------- inline functions -----------------
603 
604 
605 template <typename T, typename U>
606 inline
607 bool
608 PointerComparison::equal (const T *, const U *)
609 {
610  return false;
611 }
612 
613 
614 
615 template <typename T>
616 inline
617 bool
618 PointerComparison::equal (const T *p1, const T *p2)
619 {
620  return (p1==p2);
621 }
622 
623 
624 DEAL_II_NAMESPACE_CLOSE
625 
626 #endif
STL namespace.
static bool equal(const T *p1, const T *p2)