YACLib
C++ library for concurrent tasks execution
Loading...
Searching...
No Matches
type_traits.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <yaclib/fwd.hpp>
5
6#include <exception>
7#include <type_traits>
8#include <utility>
9
10namespace yaclib {
11
12// Not available in C++17, move to std if C++17 support is ever dropped
13template <typename T>
14using remove_cvref_t = std::remove_cv_t<std::remove_reference_t<T>>;
15
16template <typename... Args>
17using head_t = typename detail::Head<Args...>::Type; // NOLINT
18
19template <typename Func, typename... Arg>
20inline constexpr bool is_invocable_v = detail::IsInvocable<Func, Arg...>::Value; // NOLINT
21
22template <typename Func, typename... Arg>
23using invoke_t = typename detail::Invoke<Func, Arg...>::Type; // NOLINT
24
25template <typename T>
27
28template <typename T>
30
31template <typename T>
33
34template <typename T>
36
37template <typename T>
39
40template <typename T>
44template <typename T>
45inline constexpr bool is_task_v = detail::IsInstantiationOf<Task, T>::Value; // NOLINT
46
47template <typename T>
49
50// Waitable: a reference to a shared future or a non-const reference to a regular future
51template <typename T>
52inline constexpr bool is_waitable_v =
54 (!std::is_const_v<std::remove_reference_t<T>> && is_future_base_v<remove_cvref_t<T>>);
55
56// Waitable with timeout: a non-const reference to a regular future (shared futures cannot be waited with timeout)
57template <typename T>
58inline constexpr bool is_waitable_with_timeout_v =
59 (!std::is_const_v<std::remove_reference_t<T>> && is_future_base_v<remove_cvref_t<T>>);
60
61template <typename T>
63
64template <typename T>
66
67template <typename T>
69
70template <typename T>
72
73template <bool Condition, typename T>
74decltype(auto) move_if(T&& arg) noexcept { // NOLINT
75 if constexpr (Condition) {
76 return std::move(std::forward<T>(arg));
77 } else {
78 return std::forward<T>(arg);
79 }
80}
81
82template <typename T>
83constexpr bool Check() noexcept {
84 static_assert(!std::is_reference_v<T>, "T cannot be V&, just use pointer or std::reference_wrapper");
85 static_assert(!std::is_const_v<T>, "T cannot be const, because it's unnecessary");
86 static_assert(!std::is_volatile_v<T>, "T cannot be volatile, because it's unnecessary");
87 static_assert(!is_result_v<T>, "T cannot be Result, because it's ambiguous");
88 static_assert(!is_future_base_v<T>, "T cannot be Future, because it's ambiguous");
89 static_assert(!is_task_v<T>, "T cannot be Task, because it's ambiguous");
90 static_assert(!std::is_same_v<T, std::exception_ptr>, "T cannot be std::exception_ptr, because it's ambiguous");
91 static_assert(!std::is_same_v<T, Unit>, "T cannot be Unit, because Unit for internal instead of void usage");
92 return true;
93}
94
95} // namespace yaclib
constexpr bool is_waitable_v
typename detail::FutureBaseTypes< T >::Value future_base_value_t
typename detail::SharedFutureTypes< T >::Error shared_future_error_t
constexpr bool is_shared_future_v
typename detail::InstantiationTypes< Task, T >::Error task_error_t
typename detail::Head< Args... >::Type head_t
constexpr bool is_result_v
constexpr bool is_task_v
constexpr bool is_invocable_v
decltype(auto) move_if(T &&arg) noexcept
typename detail::SharedFutureTypes< T >::Value shared_future_value_t
constexpr bool is_future_base_v
typename detail::FutureBaseTypes< T >::Error future_base_error_t
constexpr bool Check() noexcept
Contract< V, E > MakeContract()
Creates related future and promise.
Definition contract.hpp:25
std::remove_cv_t< std::remove_reference_t< T > > remove_cvref_t
typename detail::Invoke< Func, Arg... >::Type invoke_t
constexpr bool is_waitable_with_timeout_v
typename detail::InstantiationTypes< Task, T >::Value task_value_t
typename detail::InstantiationTypes< Result, T >::Value result_value_t
typename detail::InstantiationTypes< Result, T >::Error result_error_t