什么意思是“this->模板” [英] What mean "this->template"
问题描述
旧Facebook新图书馆之间的差异愚蠢:
/usr/local/include/folly/futures/Future.h
旧版本:
模板< typename F,typename R =期货::详情:: callableResult< T,F>>
typename R :: Return then(F&& func){
return thenImplementation< F,R>(std :: forward< F>(func),typename R :: Arg());
}
和新币:
template< typename F,typename R = futures :: detail :: callableResult< T,F>>
typename R :: Return then(F&& func){
返回此 - >模板thenImplementation< F,R>(
std :: forward< F>(func),typename R :: Arg());
}¥b $ b b $ b b表示"this->模板"是什么意思使用此模板的代码
新的愚蠢也使用:
/usr/local/include/folly/functional/Invoke.h
或/ usr / include / c ++ / 8 / type_traits
/// std :: invoke_result_t
template< typename _Fn,typename ... _Args>
使用invoke_result_t = typename invoke_result< _Fn,_Args ...> :: type;
如何更改我的代码?
Difference bettwen old a new facebook library folly:
/usr/local/include/folly/futures/Future.h
in old version:
template <typename F, typename R = futures::detail::callableResult<T, F>>
typename R::Return then(F&& func) {
return thenImplementation<F, R>(std::forward<F>(func), typename R::Arg());
}
and new :
template <typename F, typename R = futures::detail::callableResult<T, F>>
typename R::Return then(F&& func) {
return this->template thenImplementation<F, R>(
std::forward<F>(func), typename R::Arg());
}
what means "this->template" for code using this template
new folly uses also:
/usr/local/include/folly/functional/Invoke.h
or /usr/include/c++/8/type_traits
/// std::invoke_result_t
template<typename _Fn, typename... _Args>
using invoke_result_t = typename invoke_result<_Fn, _Args...>::type;
How change my code?
推荐答案
使用template关键字来表示名称thenImplementation是一个模板。这里没有帮助的是Visual C ++编译器有一个扩展,这意味着它不需要它。
The template keyword is used like this to say that the name thenImplementation is a template. The thing that doesn't help here is that the Visual C++ compiler has an extension that means that it doesn't need it.
无论如何,如果你举例:
Anyway, if you take the example:
template<typename T>
struct S {
template<typename U> void foo() {}
};
template<typename T>
void bar()
{
S<T> s;
s.foo<T>(); // error: < parsed as less than operator
}
int wmain()
{
bar<int>();
return 0;
}
对于Clang和GCC,它们会产生编译错误:
For Clang and GCC they will produce a compiler error:
< source> ;:10:4:
错误: 使用'template'关键字将'foo'视为依赖模板名称
s.foo< T>(); //错误:<解析为小于运算符
s.foo<T>(); // error: < parsed as less than operator
&NBSP; ^
^
&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;模板
生成1个错误。
编译器返回:1
这是标准定义的行为。为了编译它,你需要说foo是一个模板:
This is standard defined behaviour. In order for this to compile, you need to say that foo is a template by:
template<typename T>
struct S {
template<typename U> void foo() {}
};
template<typename T>
void bar()
{
S<T> s;
s.template foo<T>(); // OK
}
int wmain()
{
bar<int>();
return 0;
}
这就是为什么这个>模板就在那里。
This is why that this->template is there.
这篇关于什么意思是“this->模板”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!