我想拥有具有 2 个接口的相同功能,因为两者的实现是相同的,并且在 2 个重载签名中实现了相同的功能,这真的不是我想要的。
#include <iostream>
#include <vector>
template <typename T>
void foo(T&) {} // I have to write the same things here ...
template <typename T>
void foo(T) {} // ... and here
int main() {
foo(std::vector<int>()); // call only for T
std::vector<int> v;
foo(v); // ambiguos call but I only need 1 implementation
return (0);
}
基本上我想解决这种情况并将 2 个模板化函数融合为 1 个。
我不知道,因为主要问题是保持相同的实现,而不仅仅是重载签名或删除模板的使用。