blob: 6e0e8b561c9fc4d1331753bfe511d8fcc1015daf (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
// { dg-do compile { target c++17 } }
// { dg-skip-if "requires hosted libstdc++ for string" { ! hostedlib } }
#include <memory>
#include <tuple>
#include <string>
struct X : private std::shared_ptr<int>
{
std::string fun_payload;
};
template<int N> std::string& get(X& x)
{
if constexpr(N==0) return x.fun_payload;
}
namespace std {
template<> class tuple_size<X> : public std::integral_constant<int, 1> {};
template<> class tuple_element<0, X> {public: using type = std::string;};
}
struct X2 : private std::shared_ptr<int>
{
int fun_payload;
template <class T> void get();
};
template<int N> int& get(X2& x)
{
if constexpr(N==0) return x.fun_payload;
}
namespace std {
template<> class tuple_size<X2> : public std::integral_constant<int, 1> {};
template<> class tuple_element<0, X2> {public: using type = int;};
}
class X3
{
double fun_payload;
public:
template <int N> double& get()
{
if constexpr(N==0) return fun_payload;
}
};
namespace std {
template<> class tuple_size<X3> : public std::integral_constant<int, 1> {};
template<> class tuple_element<0, X3> {public: using type = double;};
}
int main()
{
X x;
auto& [b1] = x;
X2 x2;
auto& [b2] = x2;
X3 x3;
auto& [b3] = x3;
}
|