Repository navigation
Expand file tree
/
Copy pathconstexprid.cpp
More file actions
55 lines (40 loc) · 1.56 KB
/
Copy pathconstexprid.cpp
File metadata and controls
55 lines (40 loc) · 1.56 KB
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
#include <cstdint>
#include <iostream>
template< typename T > class ConstexprId {
static constexpr void dummy( ) { }
public:
static constexpr const void *id = reinterpret_cast< const void * >( dummy );
};
template< typename > class ConstexprFnId{ };
template< typename RET, typename... ARGS > class ConstexprFnId< RET( ARGS... ) > {
static constexpr void dummy( ) { }
public:
static constexpr const void *id = reinterpret_cast< const void * >( dummy );
};
template< typename RET, typename CLASS, typename... ARGS > class ConstexprFnId< RET (CLASS::*)( ARGS... ) > {
static void dummy( ) { }
public:
static constexpr const void *id = reinterpret_cast< const void * >( dummy );
};
template< typename RET, typename CLASS, typename... ARGS > class ConstexprFnId< RET (CLASS::*)( ARGS... ) const > {
static void dummy( ) { }
public:
static constexpr const void *id = reinterpret_cast< const void * >( dummy );
};
template< typename RET, typename CLASS, typename... ARGS > class ConstexprFnId< RET (CLASS::*)( ARGS... ) volatile > {
static void dummy( ) { }
public:
static constexpr const void *id = reinterpret_cast< const void * >( dummy );
};
struct Test {
static void algo( );
void algo2( );
};
void TestFn( ) { }
int main( ) {
std::cout << "Test id: " << ConstexprId< Test >::id;
std::cout << "\nTestFn id: " << ConstexprFnId< decltype( TestFn ) >::id;
std::cout << "\nstatic Test::algo id: " << ConstexprFnId< decltype( Test::algo ) >::id;
std::cout << "\nTest::algo2 id: " << ConstexprFnId< decltype( &Test::algo2 ) >::id << '\n';
return 0;
}