我有两个功能C++ SFINAE解析顺序
template <typename... Args>
void foo(Args&&... args) { /* ... */ }
template <typename... Args>
void foo(const std::string& name, Args&&... args) { /* ... */ }
目前像foo("bar", /* arguments */)
所有的呼叫尝试去的第一个函数,而不是第二。我想重新排序这些函数,以便SFINAE在第一个之前找到第二个函数。我无法使用std::enable_if
来检查字符数组/字符串,因为Args...
数据包可能包含std::string&
或const char (&) []
。我该怎么做呢?
或添加过载'为const char *' – Sopel
@ Rakete1111 http://coliru.stacked-crooked.com/a/6367292d4c72cd8c – Sopel
嗯,不会'foo(“bar”s)'使第一个参数成为右值,这仍然会导致第一个重载是首选? –