stlab 2.3.0
Modern, modular C++ algorithms, data structures, and concurrency primitives
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
28namespace stlab {
29STLAB_VERSION_NAMESPACE_BEGIN()
30
31
36
37/**************************************************************************************************/
38
39template <bool...>
40struct bool_pack;
41template <bool... v>
42using all_true = std::is_same<bool_pack<true, v...>, bool_pack<v..., true>>;
43
44/**************************************************************************************************/
45
47template <template <typename> class test, typename T>
48struct smart_test : test<T> {};
49
50template <typename T>
51using smart_is_copy_constructible = smart_test<std::is_copy_constructible, T>;
52
53template <typename T>
54constexpr bool smart_is_copy_constructible_v = smart_is_copy_constructible<T>::value;
55
56/**************************************************************************************************/
57
58template <typename T>
59using enable_if_copyable = std::enable_if_t<smart_is_copy_constructible_v<T>>;
60
61template <typename T>
62using 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
69template <typename...>
70struct voider {
71 using type = void;
72};
73template <typename... Ts>
74using void_t = typename voider<Ts...>::type;
75#else
76template <typename...>
77using void_t = void;
78#endif
79
80struct 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:
88template <class Default, class, template <class...> class Op, class... Args>
89struct detector {
90 using value_t = std::false_type;
91 using type = Default;
92};
93
94// the specialization recognizes and handles only types supporting Op:
95template <class Default, template <class...> class Op, class... Args>
96struct detector<Default, void_t<Op<Args...>>, Op, Args...> {
97 using value_t = std::true_type;
98 using type = Op<Args...>;
99};
100
101template <template <class...> class Op, class... Args>
102using is_detected = typename detector<nonesuch, void, Op, Args...>::value_t;
103
104template <template <class...> class Op, class... Args>
105constexpr bool is_detected_v = is_detected<Op, Args...>::value;
106
107template <template <class...> class Op, class... Args>
108using detected_t = typename detector<nonesuch, void, Op, Args...>::type;
109
110/**************************************************************************************************/
111
113
114STLAB_VERSION_NAMESPACE_END()
115
116/**************************************************************************************************/
117
118} // namespace stlab
119
120/**************************************************************************************************/
121
122#endif
123
124/**************************************************************************************************/
Definition reverse.hpp:28
Definition traits.hpp:40
Definition traits.hpp:89
Definition traits.hpp:80
Trait adapter; specialize for types where std::is_copy_constructible is wrong.
Definition traits.hpp:48
Definition traits.hpp:70