【发布时间】:2017-02-13 03:02:20
【问题描述】:
是否可以在调用函数时生成新类型? 我读过每个 lambda 都有自己独特的类型,所以我尝试过:
template<class T, class F> struct Tag { };
template<class T>
auto func(const T &t) -> auto
{
auto f = [] () {};
return Tag<T, decltype(f)>();
}
static_assert(!std::is_same_v<decltype(func(0)), decltype(func(1))>, "type should be different.");
但是,static_assert 失败了。
无论T 的类型和t 的值如何,我可以让func() 在调用func() 时返回不同类型的值吗?
【问题讨论】: