]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Provide a template variable that can be used to query whether a type is an MPI type.
authorWolfgang Bangerth <bangerth@colostate.edu>
Tue, 1 Mar 2022 21:22:59 +0000 (14:22 -0700)
committerWolfgang Bangerth <bangerth@colostate.edu>
Tue, 1 Mar 2022 21:22:59 +0000 (14:22 -0700)
include/deal.II/base/mpi.h

index 2a42571c7cd44924d6b197cb88db873eb8176043..bf34814a3a1387a22387ceb811ca06182b898188 100644 (file)
 #include <deal.II/base/index_set.h>
 #include <deal.II/base/mpi_tags.h>
 #include <deal.II/base/numbers.h>
+#include <deal.II/base/template_constraints.h>
 
 #include <boost/signals2.hpp>
 
+#include <complex>
 #include <map>
 #include <numeric>
 #include <set>
@@ -139,6 +141,36 @@ namespace Utilities
    */
   namespace MPI
   {
+    /**
+     * A template variable that is `true` if the template argument `T` is a data
+     * type that is natively supported by MPI, and `false` otherwise. This
+     * variable can be used together with `std::enable_if` to selectively allow
+     * template functions only for those data types for which the template type
+     * is supported by MPI. The variable is, in essence, a concept in the sense
+     * of C++20.
+     */
+    template <typename T>
+    constexpr bool is_mpi_type = is_same_as_any_of<T,
+                                                   char,
+                                                   signed short,
+                                                   signed int,
+                                                   signed long,
+                                                   signed long long,
+                                                   signed char,
+                                                   unsigned char,
+                                                   unsigned short,
+                                                   unsigned int,
+                                                   unsigned long int,
+                                                   unsigned long long,
+                                                   float,
+                                                   double,
+                                                   long double,
+                                                   bool,
+                                                   std::complex<float>,
+                                                   std::complex<double>,
+                                                   std::complex<long double>,
+                                                   wchar_t>::value;
+
     /**
      * Return the number of MPI processes there exist in the given
      * @ref GlossMPICommunicator "communicator"

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.