22// Licensed under the MIT License.
33
44#include < gtest/gtest.h>
5+ #include < vector>
56#include " proxy.h"
67
8+ namespace proxy_regression_tests_details {
9+
10+ template <class It , class F >
11+ bool operator ==(const It& it, const pro::proxy<F>& rhs) noexcept
12+ requires (!std::is_same_v<It, pro::proxy<F>>) {
13+ return typeid (It) == proxy_typeid (rhs) && it == proxy_cast<const It&>(rhs);
14+ }
15+
16+ template <class F >
17+ using SelfComparisonOverload = bool (const pro::proxy<F>& rhs) const noexcept ;
18+
19+ template <class T >
20+ struct Iterator : pro::facade_builder
21+ ::support_direct_rtti
22+ ::restrict_layout<4 * sizeof (void *)>
23+ ::add_direct_convention<pro::operator_dispatch<" ++" >, void () noexcept >
24+ ::add_direct_convention<pro::operator_dispatch<" !=" >, pro::facade_aware_overload_t <SelfComparisonOverload>>
25+ ::add_convention<pro::implicit_conversion_dispatch, T&() const noexcept >
26+ ::build {};
27+
28+ PRO_DEF_MEM_DISPATCH (MemBegin, begin);
29+ PRO_DEF_MEM_DISPATCH (MemEnd, end);
30+ template <class T >
31+ struct Range : pro::facade_builder
32+ ::add_convention<MemBegin, pro::proxy<Iterator<T>>()>
33+ ::template add_convention<MemEnd, pro::proxy<Iterator<T>>()>
34+ ::build {};
35+
36+ } // namespace proxy_regression_tests_details
37+
38+ namespace details = proxy_regression_tests_details;
39+
740// https://github.com/microsoft/proxy/issues/213
841TEST (ProxyRegressionTests, TestUnexpectedCompilerWarning) {
942 struct MyTrivialFacade : pro::facade_builder
@@ -17,3 +50,14 @@ TEST(ProxyRegressionTests, TestUnexpectedCompilerWarning) {
1750 (*p)();
1851 EXPECT_EQ (side_effect, 1 );
1952}
53+
54+ // https://github.com/microsoft/proxy/issues/254
55+ TEST (ProxyRegressionTests, TestProxiableSelfDependency) {
56+ std::vector<int > original{1 , 2 , 123 };
57+ std::vector<int > expected;
58+ pro::proxy<details::Range<int >> p = &original;
59+ for (int i : *p) {
60+ expected.push_back (i);
61+ }
62+ EXPECT_EQ (expected, original);
63+ }
0 commit comments