| 1 |
// PR c++/96926 |
| 2 |
// { dg-do compile { target c++11 } } |
| 3 |
|
| 4 |
namespace std |
| 5 |
{ |
| 6 |
template<typename _Tp, _Tp __v> |
| 7 |
struct integral_constant |
| 8 |
{ |
| 9 |
static constexpr _Tp value = __v; |
| 10 |
typedef integral_constant<_Tp, __v> type; |
| 11 |
}; |
| 12 |
|
| 13 |
template<typename _Tp, _Tp __v> |
| 14 |
constexpr _Tp integral_constant<_Tp, __v>::value; |
| 15 |
|
| 16 |
typedef integral_constant<bool, true> true_type; |
| 17 |
typedef integral_constant<bool, false> false_type; |
| 18 |
|
| 19 |
template<bool __v> |
| 20 |
using bool_constant = integral_constant<bool, __v>; |
| 21 |
|
| 22 |
template<bool, typename, typename> |
| 23 |
struct conditional; |
| 24 |
|
| 25 |
template<typename...> |
| 26 |
struct __and_; |
| 27 |
|
| 28 |
template<> |
| 29 |
struct __and_<> |
| 30 |
: public true_type |
| 31 |
{ }; |
| 32 |
|
| 33 |
template<typename _B1> |
| 34 |
struct __and_<_B1> |
| 35 |
: public _B1 |
| 36 |
{ }; |
| 37 |
|
| 38 |
template<typename _B1, typename _B2> |
| 39 |
struct __and_<_B1, _B2> |
| 40 |
: public conditional<_B1::value, _B2, _B1>::type |
| 41 |
{ }; |
| 42 |
|
| 43 |
template<typename _B1, typename _B2, typename _B3, typename... _Bn> |
| 44 |
struct __and_<_B1, _B2, _B3, _Bn...> |
| 45 |
: public conditional<_B1::value, __and_<_B2, _B3, _Bn...>, _B1>::type |
| 46 |
{ }; |
| 47 |
|
| 48 |
template<typename _Tp, typename... _Args> |
| 49 |
struct is_constructible |
| 50 |
: public bool_constant<__is_constructible(_Tp, _Args...)> |
| 51 |
{ |
| 52 |
}; |
| 53 |
|
| 54 |
template<bool, typename _Tp = void> |
| 55 |
struct enable_if |
| 56 |
{ }; |
| 57 |
|
| 58 |
template<typename _Tp> |
| 59 |
struct enable_if<true, _Tp> |
| 60 |
{ typedef _Tp type; }; |
| 61 |
|
| 62 |
template<bool _Cond, typename _Tp = void> |
| 63 |
using __enable_if_t = typename enable_if<_Cond, _Tp>::type; |
| 64 |
|
| 65 |
template<bool _Cond, typename _Iftrue, typename _Iffalse> |
| 66 |
struct conditional |
| 67 |
{ typedef _Iftrue type; }; |
| 68 |
|
| 69 |
|
| 70 |
template<typename _Iftrue, typename _Iffalse> |
| 71 |
struct conditional<false, _Iftrue, _Iffalse> |
| 72 |
{ typedef _Iffalse type; }; |
| 73 |
|
| 74 |
|
| 75 |
template<bool, typename... _Types> |
| 76 |
struct _TupleConstraints |
| 77 |
{ |
| 78 |
template<typename... _UTypes> |
| 79 |
static constexpr bool __is_implicitly_constructible() |
| 80 |
{ |
| 81 |
// is_constructible is incomplete here, but only when |
| 82 |
// it is also instantiated in __is_explicitly_constructible |
| 83 |
return __and_<is_constructible<_Types, _UTypes>..., |
| 84 |
true_type |
| 85 |
>::value; |
| 86 |
} |
| 87 |
|
| 88 |
template<typename... _UTypes> |
| 89 |
static constexpr bool __is_explicitly_constructible() |
| 90 |
{ |
| 91 |
#if FIX |
| 92 |
return false; |
| 93 |
#else |
| 94 |
return __and_<is_constructible<_Types, _UTypes>..., |
| 95 |
false_type |
| 96 |
>::value; |
| 97 |
#endif |
| 98 |
} |
| 99 |
}; |
| 100 |
|
| 101 |
template<typename... _Elements> |
| 102 |
class tuple |
| 103 |
{ |
| 104 |
template<bool _Cond> |
| 105 |
using _TCC = _TupleConstraints<_Cond, _Elements...>; |
| 106 |
|
| 107 |
template<bool _Cond, typename... _Args> |
| 108 |
using _ImplicitCtor = __enable_if_t< |
| 109 |
_TCC<_Cond>::template __is_implicitly_constructible<_Args...>(), |
| 110 |
bool>; |
| 111 |
|
| 112 |
template<bool _Cond, typename... _Args> |
| 113 |
using _ExplicitCtor = __enable_if_t< |
| 114 |
_TCC<_Cond>::template __is_explicitly_constructible<_Args...>(), |
| 115 |
bool>; |
| 116 |
|
| 117 |
public: |
| 118 |
|
| 119 |
template<bool _NotEmpty = true, |
| 120 |
_ImplicitCtor<_NotEmpty, const _Elements&...> = true> |
| 121 |
constexpr |
| 122 |
tuple(const _Elements&... __elements) |
| 123 |
{ } |
| 124 |
|
| 125 |
template<bool _NotEmpty = true, |
| 126 |
_ExplicitCtor<_NotEmpty, const _Elements&...> = false> |
| 127 |
explicit constexpr |
| 128 |
tuple(const _Elements&... __elements) |
| 129 |
{ } |
| 130 |
}; |
| 131 |
} |
| 132 |
|
| 133 |
// first example |
| 134 |
|
| 135 |
template <typename SessionT> |
| 136 |
struct SomeQuery { |
| 137 |
SessionT& session_; |
| 138 |
SomeQuery(SessionT& session) : session_(session) {} |
| 139 |
}; |
| 140 |
|
| 141 |
template <typename SessionT> |
| 142 |
struct Handler { |
| 143 |
std::tuple<SomeQuery<SessionT>> queries_; |
| 144 |
Handler(SessionT& session) : queries_(session) {} |
| 145 |
}; |
| 146 |
|
| 147 |
struct Session { |
| 148 |
Handler<Session> handler_; |
| 149 |
Session() : handler_{*this} {} |
| 150 |
}; |
| 151 |
|
| 152 |
int main() { |
| 153 |
Session session; |
| 154 |
} |
| 155 |
static_assert(std::is_constructible<SomeQuery<Session>, const SomeQuery<Session>&>::value, ""); |
| 156 |
|
| 157 |
// second example |
| 158 |
|
| 159 |
template <typename T> |
| 160 |
class DependsOnT |
| 161 |
{ |
| 162 |
public: |
| 163 |
DependsOnT(T&) {} |
| 164 |
}; |
| 165 |
|
| 166 |
class Test |
| 167 |
{ |
| 168 |
public: |
| 169 |
Test() : test_{*this} {} |
| 170 |
|
| 171 |
private: |
| 172 |
std::tuple<DependsOnT<Test>> test_; |
| 173 |
}; |
| 174 |
static_assert(std::is_constructible<DependsOnT<Test>, const DependsOnT<Test>&>::value, ""); |