ROL
Toggle main menu visibility
Loading...
Searching...
No Matches
example
sacado
Accessor_CPP17.hpp
Go to the documentation of this file.
1
#ifndef ACCESSOR_HPP
2
#define ACCESSOR_HPP
3
4
#include <type_traits>
5
#include <utility>
6
7
// --- C++17 Trait Definitions ---
8
9
// 1. Trait to check if T is a specialization of Accessor (from previous answer)
10
template
<
typename
T>
11
struct
is_accessor_specialization_trait_cpp17
: std::false_type {};
12
template
<
typename
VectorType>
13
struct
is_accessor_specialization_trait_cpp17
<
Accessor
<VectorType>> : std::true_type {};
14
15
// 2. Trait to check for member types
16
template
<
typename
T,
typename
=
void
>
17
struct
has_required_member_types
: std::false_type {};
18
19
template
<
typename
T>
20
21
typename
T::value_type,
22
typename
T::size_type
23
>> : std::true_type {};
24
25
// 3. Trait to check for get_value method (if member types exist)
26
template
<
typename
T,
bool
HasTypes,
typename
=
void
>
// bool HasTypes is a precondition
27
struct
has_correct_get_value_method
: std::false_type {};
28
29
template
<
typename
T>
30
struct
has_correct_get_value_method
<T,
/* HasTypes = */
true,
31
std::void_t<decltype(
32
std::declval<const T&>().get_value(
33
std::declval<const typename T::container_type&>(),
34
std::declval<typename T::size_type>()
35
)
36
)>
37
> : std::is_same<
38
decltype(
39
std::declval<const T&>().get_value(
40
std::declval<const typename T::container_type&>(),
41
std::declval<typename T::size_type>()
42
)
43
),
44
typename T::value_type
45
> {};
46
47
// 4. Trait to check for set_value method (if member types exist)
48
template
<
typename
T,
bool
HasTypes,
typename
=
void
>
// bool HasTypes is a precondition
49
struct
has_correct_set_value_method
: std::false_type {};
50
51
template
<
typename
T>
52
struct
has_correct_set_value_method
<T,
/* HasTypes = */
true,
53
std::void_t<decltype(
54
std::declval<const T&>().set_value(
55
std::declval<typename T::container_type&>(),
// Note: non-const container
56
std::declval<typename T::size_type>(),
57
std::declval<typename T::value_type>()
58
)
59
)>
60
> : std::is_same<
// Check return type is void
61
decltype(
62
std::declval<const T&>().set_value(
63
std::declval<typename T::container_type&>(),
64
std::declval<typename T::size_type>(),
65
std::declval<typename T::value_type>()
66
)
67
),
68
void
69
> {};
70
71
// 5. Combine all checks for C++17
72
template
<
typename
T>
73
struct
is_compliant_accessor_trait
{
74
private
:
75
static
constexpr
bool
is_specialization
=
is_accessor_specialization_trait_cpp17<T>::value
;
76
static
constexpr
bool
has_types
=
has_required_member_types<T>::value
;
77
// Only check methods if it's a specialization AND has the types, to avoid hard errors with declval on non-existent types
78
static
constexpr
bool
has_get
=
has_correct_get_value_method<T, is_specialization && has_types>::value
;
79
static
constexpr
bool
has_set
=
has_correct_set_value_method<T, is_specialization && has_types>::value
;
80
81
public
:
82
static
constexpr
bool
value
=
is_specialization
&&
has_types
&&
has_get
&&
has_set
;
83
};
84
85
86
template
<
typename
T>
87
inline
constexpr
bool
is_compliant_accessor_v
=
is_compliant_accessor_trait<T>::value
;
88
89
#endif
// ACCESSOR_HPP
is_compliant_accessor_v
constexpr bool is_compliant_accessor_v
Definition
Accessor_CPP17.hpp:87
Accessor
Definition
ROL_Sacado_Traits.hpp:42
has_correct_get_value_method
Definition
Accessor_CPP17.hpp:27
has_correct_set_value_method
Definition
Accessor_CPP17.hpp:49
has_required_member_types
Definition
Accessor_CPP17.hpp:17
is_accessor_specialization_trait_cpp17
Definition
Accessor_CPP17.hpp:11
is_compliant_accessor_trait
Definition
Accessor_CPP17.hpp:73
is_compliant_accessor_trait::has_get
static constexpr bool has_get
Definition
Accessor_CPP17.hpp:78
is_compliant_accessor_trait::has_set
static constexpr bool has_set
Definition
Accessor_CPP17.hpp:79
is_compliant_accessor_trait::has_types
static constexpr bool has_types
Definition
Accessor_CPP17.hpp:76
is_compliant_accessor_trait::is_specialization
static constexpr bool is_specialization
Definition
Accessor_CPP17.hpp:75
is_compliant_accessor_trait::value
static constexpr bool value
Definition
Accessor_CPP17.hpp:82
Generated by
1.17.0