sandbox
Loading...
Searching...
No Matches
to_weak.hpp
1#ifndef LIBSBX_SIGNAL_TO_WEAK_HPP_
2#define LIBSBX_SIGNAL_TO_WEAK_HPP_
3
4#include <memory>
5#include <type_traits>
6
7namespace sbx::signals {
8
9template<typename Type>
10auto to_weak(std::weak_ptr<Type> ptr) -> std::weak_ptr<Type> {
11 return ptr;
12}
13
14template<typename Type>
15auto to_weak(std::shared_ptr<Type> ptr) -> std::weak_ptr<Type> {
16 return ptr;
17}
18
19template<typename Type, typename = void>
20struct is_weak_ptr : std::false_type { };
21
22template<typename Type>
23struct is_weak_ptr<Type, std::void_t<decltype(std::declval<Type>().expired()), decltype(std::declval<Type>().lock()), decltype(std::declval<Type>().reset())>> : std::true_type { };
24
25template<typename Type>
26constexpr auto is_weak_ptr_v = is_weak_ptr<Type>::value;
27
28template<typename Type, typename = void>
29struct is_weak_ptr_compatible : std::false_type { };
30
31template<typename Type>
32struct is_weak_ptr_compatible<Type, std::void_t<decltype(to_weak(std::declval<Type>()))>> : is_weak_ptr<decltype(to_weak(std::declval<Type>()))> { };
33
34template<typename Type>
35constexpr auto is_weak_ptr_compatible_v = is_weak_ptr_compatible<Type>::value;
36
37} // namespace sbx::signals
38
39#endif // LIBSBX_SIGNAL_TO_WEAK_HPP_
Definition: to_weak.hpp:29
Definition: to_weak.hpp:20