Skip to content

Commit ef966bc

Browse files
authored
Improve weak_proxy (#268)
1 parent fc7e1e4 commit ef966bc

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

proxy.h

+21-21
Original file line numberDiff line numberDiff line change
@@ -1465,9 +1465,16 @@ constexpr proxy<F> make_proxy_shared_impl(Args&&... args) {
14651465
template <facade F> struct observer_facade;
14661466
template <facade F> using proxy_view = proxy<observer_facade<F>>;
14671467

1468+
template <facade F> struct weak_facade;
1469+
template <facade F> using weak_proxy = proxy<weak_facade<F>>;
1470+
14681471
template <class T, class F>
14691472
concept inplace_proxiable_target = proxiable<details::inplace_ptr<T>, F>;
14701473

1474+
template <class T, class F>
1475+
concept proxiable_target = proxiable<
1476+
details::observer_ptr<T&, const T&, T&&, const T&&>, observer_facade<F>>;
1477+
14711478
template <facade F, class T, class... Args>
14721479
constexpr proxy<F> make_proxy_inplace(Args&&... args)
14731480
noexcept(std::is_nothrow_constructible_v<T, Args...>)
@@ -1492,20 +1499,13 @@ constexpr proxy<F> make_proxy_inplace(T&& value)
14921499
std::in_place, std::forward<T>(value)};
14931500
}
14941501

1495-
template <class T, class F>
1496-
concept proxiable_target = proxiable<
1497-
details::observer_ptr<T&, const T&, T&&, const T&&>, observer_facade<F>>;
1498-
14991502
template <facade F, class T>
15001503
constexpr proxy_view<F> make_proxy_view(T& value) noexcept {
15011504
return proxy_view<F>{
15021505
details::observer_ptr<T&, const T&, T&&, const T&&>{value}};
15031506
}
15041507

15051508
#if __STDC_HOSTED__
1506-
template <facade F> struct weak_facade;
1507-
template <facade F> using weak_proxy = proxy<weak_facade<F>>;
1508-
15091509
template <facade F, class T, class Alloc, class... Args>
15101510
constexpr proxy<F> allocate_proxy(const Alloc& alloc, Args&&... args)
15111511
requires(std::is_constructible_v<T, Args...>) {
@@ -2029,11 +2029,12 @@ struct sign {
20292029
template <std::size_t N>
20302030
sign(const char (&str)[N]) -> sign<N>;
20312031

2032-
#if __STDC_HOSTED__
20332032
struct weak_conversion_dispatch : cast_dispatch_base<false, true> {
20342033
template <class P>
20352034
___PRO_STATIC_CALL(auto, const P& self) noexcept
2036-
requires(requires { typename P::weak_type; } &&
2035+
requires(
2036+
requires(const typename P::weak_type& w)
2037+
{ { w.lock() } noexcept -> std::same_as<P>; } &&
20372038
std::is_convertible_v<const P&, typename P::weak_type>)
20382039
{ return typename P::weak_type{self}; }
20392040
};
@@ -2063,6 +2064,7 @@ auto weak_lock_impl(const P& self) noexcept
20632064
{ return nullable_ptr_adapter{self.lock()}; }
20642065
PRO_DEF_FREE_AS_MEM_DISPATCH(weak_mem_lock, weak_lock_impl, lock);
20652066

2067+
#if __STDC_HOSTED__
20662068
template <class CharT> struct format_overload_traits;
20672069
template <>
20682070
struct format_overload_traits<char>
@@ -2263,8 +2265,6 @@ struct basic_facade_builder {
22632265
using support_destruction = basic_facade_builder<
22642266
Cs, Rs, details::make_destructible(C, CL)>;
22652267
#if __STDC_HOSTED__
2266-
using support_weak = add_direct_convention<details::weak_conversion_dispatch,
2267-
facade_aware_overload_t<details::weak_conversion_overload>>;
22682268
using support_format = add_convention<
22692269
details::format_dispatch, details::format_overload_t<char>>;
22702270
using support_wformat = add_convention<
@@ -2289,6 +2289,8 @@ struct basic_facade_builder {
22892289
#endif // __cpp_rtti >= 199711L
22902290
using support_view = add_direct_convention<details::proxy_view_dispatch,
22912291
facade_aware_overload_t<details::proxy_view_overload>>;
2292+
using support_weak = add_direct_convention<details::weak_conversion_dispatch,
2293+
facade_aware_overload_t<details::weak_conversion_overload>>;
22922294
using build = details::facade_impl<Cs, Rs, details::normalize(C)>;
22932295
basic_facade_builder() = delete;
22942296
};
@@ -2300,16 +2302,6 @@ using facade_builder = basic_facade_builder<std::tuple<>, std::tuple<>,
23002302
.relocatability = details::invalid_cl,
23012303
.destructibility = details::invalid_cl}>;
23022304

2303-
#if __STDC_HOSTED__
2304-
template <facade F>
2305-
struct weak_facade {
2306-
using convention_types = std::tuple<details::conv_impl<
2307-
true, details::weak_mem_lock, proxy<F>() const noexcept>>;
2308-
using reflection_types = std::tuple<>;
2309-
static constexpr auto constraints = F::constraints;
2310-
};
2311-
#endif // __STDC_HOSTED__
2312-
23132305
template <facade F>
23142306
struct observer_facade
23152307
: details::instantiated_t<details::observer_facade_conv_impl,
@@ -2323,6 +2315,14 @@ struct observer_facade
23232315
.destructibility = constraint_level::trivial};
23242316
};
23252317

2318+
template <facade F>
2319+
struct weak_facade {
2320+
using convention_types = std::tuple<details::conv_impl<
2321+
true, details::weak_mem_lock, proxy<F>() const noexcept>>;
2322+
using reflection_types = std::tuple<>;
2323+
static constexpr auto constraints = F::constraints;
2324+
};
2325+
23262326
template <details::sign Sign, bool Rhs = false>
23272327
struct operator_dispatch;
23282328

0 commit comments

Comments
 (0)