我知道:
> typeof是gcc扩展名,不属于C标准.
问题:
> C 11中的单词typeof是否被弃用?换句话说,在使用C 11时,是否允许它仍然用作gcc扩展名?
>用decltype替换每个类型会产生相同的代码行为是否正确?
>假设我有模板< typename T>类包装器.声明wrapper_some_field使其等效于:Wrapper< typeof(some_field)>的最佳方法是什么? wrapper_some_field
解决方法
Is the word
typeof
deprecated in C++11? in other words,is it allowed to still use it as a gcc extension when using C++11?
它没有被弃用.它从未作为关键字存在. gcc suggests如果使用-std = c **进行编译,则改为使用__typeof__.
Is it correct to say that replacing every
typeof
withdecltype
yields the same behavIoUr of the code?
不,例如,给定:
int& foo();
decltype(foo())是int&但是__typeof __(foo())是int.
Assume I have
template<typename T> class wrapper
. […]
您可以编写包装器< std :: remove_reference_t< decltype(some_field)>>包装{some_field},但编写构造函数模板会更清晰:
template <class T> wrapper<T> make_wrapper(T const& val) { return {val}; } auto wrap = make_wrapper(some_field);