我有一个检查类型是否可迭代的概念
template<typename T>
concept Iterable = requires(T t) {
t.begin();
};
Run Code Online (Sandbox Code Playgroud)
由于重载问题,我无法在模板中使用它,所以我想做类似于以下的操作:
template<typename T>
void universal_function(T x) {
if (x is Iterable)
// something which works with iterables
else if (x is Printable)
// another thing
else
// third thing
}
Run Code Online (Sandbox Code Playgroud)