さて、このC++の実装であるis_destructible
は、参照型では機能しません。私はT&
とT&&
のための部分的な特殊化は、任意の参照型を吸い取るだろうと期待していたが、その代わりに、int&
は4行目巻き込まれているようですし、コンパイラを作るそれが好む何ですかproducing a hard error.このSFINAEが期待どおりに機能しないのはなぜですか?
namespace detail {
template<class T, class Enable> struct is_destructible_impl : false_type {};
template<class T> struct is_destructible_impl<T&, void> : true_type {};
template<class T> struct is_destructible_impl<T&&, void> : true_type {};
template<class T> struct is_destructible_impl<T, decltype(declval<T&>().~T())> : true_type {};
}
template<class T> struct is_destructible :
detail::is_destructible_impl<remove_all_extents_t<T>, void> {};
int main()
{
static_assert(is_destructible<int&>::value, "oops");
}
<int&, void>
に対して<T, (complicated expression that fails)>
と一致するのではなく、その誘惑に反して<T&, void>
?
更新:これはGCCのバグです。 Clangはコードをうまく受け入れます。それで、フォローアップの質問:余分なコーディングをしなくても、このような何かをGCC上で動作させる回避策がありますか?