ConceptsBase.hpp 1.21 KB
Newer Older
1
2
3
#pragma once

#include <type_traits>
4
#include <dune/common/typetraits.hh>
5

Praetorius, Simon's avatar
Praetorius, Simon committed
6
#define AMDIS_CONCAT_IMPL( x, y ) x##y
Praetorius, Simon's avatar
Praetorius, Simon committed
7
#define AMDIS_MACRO_CONCAT( x, y ) AMDIS_CONCAT_IMPL( x, y )
Praetorius, Simon's avatar
Praetorius, Simon committed
8

9
#ifdef DOXYGEN
10
  #define REQUIRES(...)
11
  #define REQUIRES_(...)
12
  #define CONCEPT constexpr
Praetorius, Simon's avatar
Praetorius, Simon committed
13
  #define CHECK_CONCEPT(...)
14
#else
15
16
  #define REQUIRES(...) std::enable_if_t<__VA_ARGS__ , int> = 0
  #define REQUIRES_(...) std::enable_if_t<__VA_ARGS__ , int>
17
  #define CONCEPT constexpr
Praetorius, Simon's avatar
Praetorius, Simon committed
18
  #define CHECK_CONCEPT(...) static __VA_ARGS__ AMDIS_MACRO_CONCAT( _concept_check_, __COUNTER__ )
19
#endif
20

21
22
namespace AMDiS
{
Praetorius, Simon's avatar
Praetorius, Simon committed
23
  using Dune::void_t;
24

25
  namespace Concepts
26
  {
27
    namespace Impl_
28
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
29
      template <class Concept, class = void_t<>>
30
31
32
      struct models
          : std::false_type
      {};
33

34
      template <class Concept, class... Ts>
Praetorius, Simon's avatar
Praetorius, Simon committed
35
      struct models<Concept(Ts...), void_t< decltype(std::declval<Concept>().require(std::declval<Ts>()...)) >>
36
37
          : std::true_type
      {};
38

39
    } // end namespace Impl_
40

41
42

#ifndef DOXYGEN
43
    template <class Concept>
44
    constexpr bool models = Impl_::models<Concept>::value;
45

Praetorius, Simon's avatar
Praetorius, Simon committed
46
47
    template <class Concept>
    using models_t = Impl_::models<Concept>;
48
#endif // DOXYGEN
49

50
  } // end namespace Concepts
51
} // end namespace AMDiS