Questions tagged «declval»

2
T是否必须是要在`std :: declval <T>`中使用的完整类型?
考虑以下示例(来自此处): #include &lt;type_traits&gt; #include &lt;iostream&gt; template &lt;typename U&gt; struct A { }; struct B { template &lt;typename F = int&gt; A&lt;F&gt; f() { return A&lt;F&gt;{}; } using default_return_type = decltype(std::declval&lt;B&gt;().f()); }; int main() { B::default_return_type x{}; std::cout &lt;&lt; std::is_same&lt; B::default_return_type, A&lt;int&gt;&gt;::value; } 它在gcc9.2上编译时没有错误,但gcc7.2和clang 10.0.0抱怨B未完成。lang的错误是: prog.cc:11:58: error: member access into incomplete …
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.