35template <
typename H,
typename =
void>
36struct BuiltinHolderTraits {};
39struct BuiltinHolderTraits<RefPtr<T>> {
40 using element_type = T;
41 static constexpr HolderKind kind = HolderKind::Shared;
42 static T* Get(
const RefPtr<T>& holder) {
return holder.get(); }
46struct BuiltinHolderTraits<std::shared_ptr<T>> {
47 using element_type = T;
48 static constexpr HolderKind kind = HolderKind::Shared;
49 static T* Get(
const std::shared_ptr<T>& holder) {
return holder.get(); }
52template <
typename T,
typename D>
53struct BuiltinHolderTraits<std::unique_ptr<T, D>> {
54 using element_type = T;
55 static constexpr HolderKind kind = HolderKind::Exclusive;
56 static T* Get(
const std::unique_ptr<T, D>& holder) {
return holder.get(); }
60struct BuiltinHolderTraits<WeakPtr<T>> {
61 using element_type = T;
62 static RefPtr<T> Lock(
const WeakPtr<T>& holder) {
return holder.Lock(); }
66struct BuiltinHolderTraits<std::weak_ptr<T>> {
67 using element_type = T;
68 static std::shared_ptr<T> Lock(
const std::weak_ptr<T>& holder) {
return holder.lock(); }
155template <
typename H,
typename =
void>
165concept HolderHasGet =
requires(
const H& holder) { HolderTraits<H>::Get(holder); };
172 if constexpr (HolderHasLock<H>)
173 return HolderTraits<H>::Lock(holder);
175 return HolderTraits<H>::Get(holder);
Root namespace for every public Ultralight type, function, and enumeration.
std::lock_guard< Lock > LockHolder
Definition Lock.h:84
HolderKind
Whether a holder shares ownership of a bound-class instance or owns it alone.
Definition HolderTraits.h:16
@ Exclusive
One holder owns the instance and ownership moves (eg, std::unique_ptr).
Definition HolderTraits.h:26
@ Shared
Copies share ownership (eg, RefPtr), or the instance is never destroyed (js::Eternal).
Definition HolderTraits.h:20
Traits template that lets the library hold objects through custom smart pointers.
Definition HolderTraits.h:156