我有一个函数,希望将返回计算值的变量从函数的返回类型中自动推导出来。
我已经看到了成员函数的,并且我知道使用decltype(func()) var,我可以获得返回类型。但这只适用于没有参数的函数。如果我有一个参数,我必须使用decltype(func(/* some dummy value convertible to argument type*/))来获得
我试图在一个自动函数上使用decltype关键字: static auto foo() { } decltype(foo());我得到了以下错误(gcc 7.4):
<source>:6:25: error: use of 'static auto Thing::foo()' before deduction of 'auto<
对于每种类型,我都有一个toString()方法。std::string toString(const B &b){ }我想提供一个模板化的operator<<,它只捕获这些类型,但不捕获此命名空间之外的类型:std::ostream & operator<<(std::ostream &out, const T &t){
out<< toS