KASKADE 7 development version
utilities
member_variable_macro.hh
Go to the documentation of this file.
1
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2
/* */
3
/* This file is part of the library KASKADE 7 */
4
/* https://www.zib.de/research/projects/kaskade7-finite-element-toolbox */
5
/* */
6
/* Copyright (C) 2002-2012 Zuse Institute Berlin */
7
/* */
8
/* KASKADE 7 is distributed under the terms of the ZIB Academic License. */
9
/* see $KASKADE/academic.txt */
10
/* */
11
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
12
/*
13
* member_variable_macro.hh
14
*
15
* Created on: 18.04.2012
16
* Author: Lars Lubkoll
17
*/
18
19
#ifndef MEMBER_VARIABLE_MACRO_HH_
20
#define MEMBER_VARIABLE_MACRO_HH_
21
22
#include <boost/type_traits/is_same.hpp>
23
#include <boost/preprocessor/cat.hpp>
24
25
/*
26
* Creates template function that checks if its template parameter has a member variable called
27
* VARIABLENAME with type VARIABLETYPE. The struct is named NAME.
28
*/
29
#define KASKADE_CREATE_MEMBER_VARIABLE_CHECK(VARIABLE_TYPE, VARIABLE_NAME, NAME) template<class T, bool variableExists> \
30
struct BOOST_PP_CAT(Kaskade_,BOOST_PP_CAT(NAME,_VariableTypeCheck{)) \
31
static bool const value = false; \
32
};\
33
\
34
template<class T> \
35
struct BOOST_PP_CAT(Kaskade_,BOOST_PP_CAT(NAME,_VariableTypeCheck))<T,true>{ \
36
static bool const value = boost::is_same<VARIABLE_TYPE,decltype(T::VARIABLE_NAME)>::value; \
37
};\
38
\
39
template<typename T> \
40
struct NAME { \
41
struct Fallback { \
42
VARIABLE_TYPE VARIABLE_NAME; \
43
}; \
44
\
45
struct Derived : T, Fallback { }; \
46
template<typename C, C> \
47
struct ChT; \
48
\
49
template<typename C> \
50
static std::false_type f(ChT< VARIABLE_TYPE Fallback::*, &C::VARIABLE_NAME >*); \
51
template<typename C> \
52
static std::true_type f(...); \
53
\
54
typedef decltype(f<Derived>(0)) type; \
55
static bool const value = BOOST_PP_CAT(Kaskade_,BOOST_PP_CAT(NAME,_VariableTypeCheck))<T,type::value>::value; \
56
};
57
58
/*
59
* Creates template function that checks if its template parameter has a member variable or function
60
* called VARIABLENAME. The signature/type will not be checked.
61
* The struct is named NAME.
62
*/
63
#define KASKADE_CREATE_MEMBER_NAME_CHECK(VARIABLE_NAME, NAME) template<typename T> \
64
struct NAME { \
65
struct Fallback { \
66
bool VARIABLE_NAME; \
67
}; \
68
\
69
struct Derived : T, Fallback { }; \
70
template<typename C, C> \
71
struct ChT; \
72
\
73
template<typename C> \
74
static std::false_type f(ChT< bool Fallback::*, &C::VARIABLE_NAME >*); \
75
template<typename C> \
76
static std::true_type f(...); \
77
\
78
typedef decltype(f<Derived>(0)) type; \
79
static bool const value = type::value; \
80
};
81
82
#endif
/* MEMBER_VARIABLE_MACRO_HH_ */
Generated on Fri Sep 6 2024 13:13:00 for KASKADE 7 development version by
1.9.4