在下面的代碼片段中,我試圖確定一個類是否有一個副本ctor或不。 如果我的班級沒有副本,我只會看到一個編譯錯誤。我無法讓它返回真或假。請幫助我..檢查一個班級是否有副本?返回true或false
template <typename T>
auto has_copy_ctor(T const& data) -> decltype(T(data), bool())
{
return true;
}
struct A
{
A(A const& obj) = delete;
};
struct B {};
int main()
{
std::cout << has_copy_ctor<B>(B{}) << std::endl; // compiles
std::cout << has_copy_ctor<A>(A{}) << std::endl; // does not compile
}
*「由於這些是保持在最低水平,機會是一個‘原生C++’的實施將是不平凡的,如果在所有的p 「*,[爲什麼不?](http://coliru.stacked-crooked.com/a/1f66e255907a205c) –
嗯,我想我不是很有想象力。 – zneak
嗯,我更感興趣的是瞭解SFINAE的其他部分,我想不出來...我仍然接受你的答案。 – gjha