test-map-datatypes.cc 1.91 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <config.h>

#include <type_traits>
#include <dune/vtk/types.hh>


int main()
{
  using namespace Dune;

  // unconstrained mapping of DataTypes to real type t
  Vtk::mapDataTypes(Vtk::DataTypes::UINT32, [](auto t)
  {
    using T = typename decltype(t)::type;
    VTK_ASSERT(Vtk::Map::type<T>() == Vtk::DataTypes::UINT32);
  });

  // constrained mapping of DataTypes to real type t
  Vtk::mapDataTypes<std::is_integral>(Vtk::DataTypes::UINT32, [](auto t)
  {
    using T = typename decltype(t)::type;
    VTK_ASSERT(Vtk::Map::type<T>() == Vtk::DataTypes::UINT32);
    static_assert(std::is_integral_v<T>);
  });

  Vtk::mapDataTypes<std::is_floating_point>(Vtk::DataTypes::FLOAT32, [](auto t)
  {
    using T = typename decltype(t)::type;
    VTK_ASSERT(Vtk::Map::type<T>() == Vtk::DataTypes::FLOAT32);
    static_assert(std::is_floating_point_v<T>);
  });


  // if the DataType does not fulfill the constraint, the function is never invoked
  Vtk::mapDataTypes<std::is_floating_point>(Vtk::DataTypes::UINT32, [](auto t)
  {
    // This function should never be called
    VTK_ASSERT(false);
  });


  // unconstrained mapping with multiple types
  Vtk::mapDataTypes(Vtk::DataTypes::FLOAT32, Vtk::DataTypes::UINT32,
  [](auto f, auto h)
  {
    using F = typename decltype(f)::type;
    using H = typename decltype(h)::type;
    VTK_ASSERT(Vtk::Map::type<F>() == Vtk::DataTypes::FLOAT32);
    VTK_ASSERT(Vtk::Map::type<H>() == Vtk::DataTypes::UINT32);
  });

  // constrained mapping with multiple types
  Vtk::mapDataTypes<std::is_floating_point,std::is_integral>(Vtk::DataTypes::FLOAT32, Vtk::DataTypes::UINT32,
  [](auto f, auto h)
  {
    using F = typename decltype(f)::type;
    using H = typename decltype(h)::type;
    VTK_ASSERT(Vtk::Map::type<F>() == Vtk::DataTypes::FLOAT32);
    VTK_ASSERT(Vtk::Map::type<H>() == Vtk::DataTypes::UINT32);
    static_assert(std::is_floating_point_v<F>);
    static_assert(std::is_integral_v<H>);
  });
}