2015-12-28 73 views
2

我試圖從boost庫實現綁定功能。 下面你可以看到主結構bind_t與定義operator()模板扣除失敗

我的問題是:我們爲什麼要在decltype指定返回的operator()類型返回的call()類型明確爲成員函數

(如果我刪除this->之前call,模板參數推導以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...); 
    } 
}; 

實施full source
simple usecase

+0

看起來像它是固定在海灣合作委員會5.1 –

回答

2

這是gcc的一個錯誤,在錯誤報告decltype needs explicit 'this' pointer in member function declaration of template class with trailing return type它說的記載:

在使用後返回類型的成員函數模板 類,'this'指針必須明確提及。這應該是 不是必要的(隱式'this'與非模板 類一起使用)。

例子:

​​

報告被標記爲固定的,它看起來像這樣的作品開始在GCC 5.1(see it live)工作。

+0

如果你沒有最新版本的gcc你可以驗證使用[Wandbox](http://melpon.org/wandbox),看看它開始工作在哪個版本。 –