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>
44
45template <typename T>
49
50template <typename T>
51inline constexpr bool is_task_v = detail::IsInstantiationOf<Task, T>::Value; // NOLINT
52
53// Waitable: a reference to a shared future or a non-const reference to a regular future
54template <typename T>
55inline constexpr bool is_waitable_v =
57 (!std::is_const_v<std::remove_reference_t<T>> && is_future_base_v<remove_cvref_t<T>>);
58
59// Waitable with timeout: a non-const reference to a regular future (shared futures cannot be waited with timeout)
60template <typename T>
61inline constexpr bool is_waitable_with_timeout_v =
62 (!std::is_const_v<std::remove_reference_t<T>> && is_future_base_v<remove_cvref_t<T>>);
63
64template <typename T>
66
67template <typename T>
69
70template <typename T>
72
73template <typename T>
75
76template <bool Condition, typename T>
77decltype(auto) move_if(T&& arg) noexcept { // NOLINT
78 if constexpr (Condition) {
79 return std::move(std::forward<T>(arg));
80 } else {
81 return std::forward<T>(arg);
82 }
83}
84
85template <typename T, typename... List>
86inline constexpr auto Count = (std::size_t{std::is_same_v<T, List> ? 1 : 0} + ...);
87
88template <typename T>
89constexpr bool Check() noexcept {
90 static_assert(!std::is_reference_v<T>, "T cannot be V&, just use pointer or std::reference_wrapper");
91 static_assert(!std::is_const_v<T>, "T cannot be const, because it's unnecessary");
92 static_assert(!std::is_volatile_v<T>, "T cannot be volatile, because it's unnecessary");
93 static_assert(!is_result_v<T>, "T cannot be Result, because it's ambiguous");
94 static_assert(!is_future_base_v<T>, "T cannot be Future, because it's ambiguous");
95 static_assert(!is_task_v<T>, "T cannot be Task, because it's ambiguous");
96 static_assert(!std::is_same_v<T, std::exception_ptr>, "T cannot be std::exception_ptr, because it's ambiguous");
97 static_assert(!std::is_same_v<T, Unit>, "T cannot be Unit, because Unit for internal instead of void usage");
98 return true;
99}
100
101} // 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
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 auto Count
constexpr bool Check() noexcept
constexpr bool is_shared_future_base_v
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