stlab
2.4.0
Modern, modular C++ algorithms, data structures, and concurrency primitives
Toggle main menu visibility
Loading...
Searching...
No Matches
traits.hpp
Go to the documentation of this file.
1
/*
2
Copyright 2015 Adobe
3
Distributed under the Boost Software License, Version 1.0.
4
(See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5
*/
6
7
/**************************************************************************************************/
8
9
#ifndef STLAB_CONCURRENCY_TRAITS_HPP
10
#define STLAB_CONCURRENCY_TRAITS_HPP
11
21
22
#include <stlab/config.hpp>
23
24
#include <type_traits>
25
26
/**************************************************************************************************/
27
28
namespace
stlab
{
29
STLAB_VERSION_NAMESPACE_BEGIN()
30
31
36
37
/**************************************************************************************************/
38
39
template <
bool
...>
40
struct
bool_pack
;
41
template <
bool
... v>
42
using all_true = std::is_same<
bool_pack
<true, v...>,
bool_pack
<v..., true>>;
43
44
/**************************************************************************************************/
45
47
template <template <typename> class test, typename T>
48
struct
smart_test
: test<T> {};
49
50
template
<
typename
T>
51
using
smart_is_copy_constructible =
smart_test<std::is_copy_constructible, T>
;
52
53
template
<
typename
T>
54
constexpr
bool
smart_is_copy_constructible_v = smart_is_copy_constructible<T>::value;
55
56
/**************************************************************************************************/
57
58
template
<
typename
T>
59
using
enable_if_copyable = std::enable_if_t<smart_is_copy_constructible_v<T>>;
60
61
template
<
typename
T>
62
using
enable_if_not_copyable = std::enable_if_t<!smart_is_copy_constructible_v<T>>;
63
64
/**************************************************************************************************/
65
66
// the following implements the C++ standard 17 proposal N4502
67
#if __GNUC__ < 5 && !defined __clang__
68
// http://stackoverflow.com/a/28967049/1353549
69
template
<
typename
...>
70
struct
voider
{
71
using
type = void;
72
};
73
template
<
typename
... Ts>
74
using
void_t =
typename
voider
<Ts...>::type;
75
#else
76
template
<
typename
...>
77
using
void_t = void;
78
#endif
79
80
struct
nonesuch {
81
nonesuch() =
delete
;
82
~nonesuch() =
delete
;
83
nonesuch(nonesuch
const
&) =
delete
;
84
void
operator=(nonesuch
const
&) =
delete
;
85
};
86
87
// primary template handles all types not supporting the archetypal Op:
88
template
<
class
Default,
class
,
template
<
class
...>
class
Op,
class
... Args>
89
struct
detector
{
90
using
value_t = std::false_type;
91
using
type = Default;
92
};
93
94
// the specialization recognizes and handles only types supporting Op:
95
template
<
class
Default,
template
<
class
...>
class
Op,
class
... Args>
96
struct
detector
<Default, void_t<Op<Args...>>, Op, Args...> {
97
using
value_t = std::true_type;
98
using
type = Op<Args...>;
99
};
100
101
template
<
template
<
class
...>
class
Op,
class
... Args>
102
using
is_detected =
typename
detector
<
nonesuch
, void, Op, Args...>::value_t;
103
104
template
<
template
<
class
...>
class
Op,
class
... Args>
105
constexpr
bool
is_detected_v = is_detected<Op, Args...>::value;
106
107
template
<
template
<
class
...>
class
Op,
class
... Args>
108
using
detected_t =
typename
detector
<
nonesuch
, void, Op, Args...>::type;
109
110
/**************************************************************************************************/
111
113
114
STLAB_VERSION_NAMESPACE_END()
115
116
/**************************************************************************************************/
117
118
}
// namespace stlab
119
120
/**************************************************************************************************/
121
122
#endif
123
124
/**************************************************************************************************/
stlab
Definition
reverse.hpp:28
stlab::bool_pack
Definition
traits.hpp:40
stlab::detector
Definition
traits.hpp:89
stlab::nonesuch
Definition
traits.hpp:80
stlab::smart_test
Trait adapter; specialize for types where std::is_copy_constructible is wrong.
Definition
traits.hpp:48
stlab::voider
Definition
traits.hpp:70
stlab
concurrency
traits.hpp
Generated by
1.18.0