File: traits.hpp

package info (click to toggle)
python-pyclustering 0.10.1.2-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 11,128 kB
  • sloc: cpp: 38,888; python: 24,311; sh: 384; makefile: 105
file content (126 lines) | stat: -rwxr-xr-x 3,378 bytes parent folder | download | duplicates (2)
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/*!

@authors Andrei Novikov (pyclustering@yandex.ru)
@date 2014-2020
@copyright BSD-3-Clause

*/


#pragma once


#include <string>
#include <type_traits>


namespace pyclustering {

namespace utils {

namespace traits {


/*!

@brief   Utility metafunction that maps a sequence of any types to the type `void`.

*/
template<class...>
using void_t = void;


/*!

@brief   Checks whether `TypeRawString` is a raw-string type. 
@details Provides the member constant value which is equal to `true`, if `TypeRawString` is the 
          type `char *`, `wchar_t *`, including any cv-qualified variants. Otherwise, value is equal to `false`.

@tparam TypeRawString: a type to check.

*/
template <typename TypeRawString>
struct is_raw_string : std::integral_constant<bool,
    std::is_pointer<TypeRawString>::value &&
    (std::is_same<char, typename std::remove_cv<typename std::remove_pointer<TypeRawString>::type>::type>::value ||
    std::is_same<wchar_t, typename std::remove_cv<typename std::remove_pointer<TypeRawString>::type>::type>::value)
> { };


/*!

@brief   Checks whether `TypeRawString` is a string type.
@details Provides the member constant value which is equal to `true`, if `TypeRawString` is the
type `std::string`, `std::wstring`, including any cv-qualified variants. Otherwise, value is equal to `false`.

@tparam TypeString: a type to check.

*/
template <typename TypeString>
struct is_string : std::integral_constant<bool,
    std::is_same<std::string, typename std::remove_cv<TypeString>::type>::value ||
    std::is_same<std::wstring, typename std::remove_cv<TypeString>::type>::value
> { };


/*!

@brief   Checks whether `Type` is a container and its elements type is fundamental.
@details Provides the member constant value which is equal to `true`, if `TypeContainer` is the
          has `value_type`, `size_type`, `const_iterator`, `cbegin()`, `cend()`. Otherwise, value is equal to `false`.

@tparam Type: a type to check.

*/
template <typename, typename = void_t<>>
struct is_container_with_fundamental_content : std::false_type { };


/*!

@brief   Checks whether `Type` is a container and its elements type is fundamental.
@details Provides the member constant value which is equal to `true`, if `TypeContainer` is the
          has `value_type`, `size_type`, `const_iterator`, `cbegin()`, `cend()`. Otherwise, value is equal to `false`.

@tparam Type: a type to check.

*/
template <typename Type>
struct is_container_with_fundamental_content <
    Type, void_t<
        typename Type::value_type,
        typename Type::size_type,
        typename Type::const_iterator,
        decltype(std::declval<Type>().cbegin()),
        decltype(std::declval<Type>().cend())
    >
> : std::is_fundamental<typename Type::value_type> { };


/*!

@brief   Removes pointer, `const`, `volatile` from type `Type` if they have a place in the type.

@tparam Type: a type to update.

*/
template <typename Type>
using remove_cvp = std::remove_cv<typename std::remove_pointer<Type>::type>;


/*!

@brief   Helper type that removes pointer, `const`, `volatile` from type `Type` if they have a place in the type.

@tparam Type: a type to update.

*/
template <typename Type>
using remove_cvp_t = typename remove_cvp<Type>::type;


}

}

}