我只是花了很多时间调试我认为可能在编译时发现的某些东西,但是无论我尝试了什么,我都没有使它起作用。
错误的代码:
#include <string>
template<typename ContainerT>
std::pair<typename ContainerT::const_iterator,
typename ContainerT::const_iterator>
GetIterPair(const ContainerT& container) {
return { container.cbegin(), container.cend() };
}
int main() {
GetIterPair(std::string("hello"));
}
我尝试了许多enable_if
和!is_rvalue_reference<ContainerT>
的{{1}}变体,作为模板参数和尾随返回类型,但无法拒绝右值。