【发布时间】:2015-12-28 00:47:33
【问题描述】:
我正在尝试从 boost 库中实现绑定功能。
下面你可以看到主要结构 bind_t 定义了operator()。
我的问题如下:为什么我们要在decltype中指定返回类型operator()返回类型call()显式作为成员函数(如果我在call之前删除this->,模板参数推导失败g++。)
也很有趣,使用 clang++ 就没有这样的问题。
我不知道为什么会这样。
template <typename F, typename ... P>
struct bind_t {
private:
std::tuple<typename holder<P>::type...> p;
F func;
template <size_t ... N, typename ... Args>
auto call(index_list<N ...>, Args const& ... args) const -> decltype(func(std::get<N>(p)(args...)...)) {
return func(std::get<N>(p)(args...)...);
}
public:
bind_t(F f, P ... p):
p(std::move(p)...),
func(std::move(f))
{}
template <typename ... Args>
auto operator()(Args const& ... args) const -> decltype(this->call(typename indices_by_num<sizeof...(P)>::type(), args...)) {
typename indices_by_num<sizeof...(P)>::type indices;
return call(indices, args...);
}
};
【问题讨论】:
-
看起来它已在 gcc 5.1 中修复
标签: c++ templates gcc variadic-templates sfinae