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