Howdoesincludinggtest.hbreaktemplateargumentdeductionforastdalgorithm?

I upgraded to the latest release of Google Test, and several of my tests no longer compiled. I've reduced it to this:

#include <gtest/gtest.h>

#include <algorithm>
#include <cctype>
#include <iostream>
#include <string>

int main () {
    const std::string foo = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    const auto uppers = std::count_if(foo.begin(), foo.end(), std::isupper);
    std::cout << "There are " << uppers << " capitals." << std::endl;
    return 0;
}

The Visual Studio 2019 (16.10.4) compiler with /std:c++latest complains:

1>Source.cpp(10,30): error C2672: 'std::count_if': no matching overloaded function found
1>Source.cpp(10,75): error C2780: 'conditional_t<std::_Is_from_primary<std::iterator_traits<remove_cv<remove_reference<_Ty2>::type>::type>>,std::incrementable_traits<remove_cv<remove_reference<_Ty2>::type>::type>,std::iterator_traits<remove_cv<remove_reference<_Ty2>::type>::type>>::difference_type std::count_if(_ExPo &&,const _FwdIt,const _FwdIt,_Pr) noexcept': expects 4 arguments - 3 provided
1>algorithm(570): message : see declaration of 'std::count_if'
1>Source.cpp(10,30): error C2783: 'conditional_t<std::_Is_from_primary<std::iterator_traits<remove_cv<remove_reference<_Ty>::type>::type>>,std::incrementable_traits<remove_cv<remove_reference<_Ty>::type>::type>,std::iterator_traits<remove_cv<remove_reference<_Ty>::type>::type>>::difference_type std::count_if(_InIt,_InIt,_Pr)': could not deduce template argument for '_Pr'
1>algorithm(553): message : see declaration of 'std::count_if'

If I comment out the inclusion of gtest.h, the code builds and executes correctly.

gtest.h 会做些什么来扰乱仅依赖于std定义的类型和函数的调用的模板参数推导?

[注意,我的问题不是如何解决问题,而是了解具体的根本原因。我有一个解决方法:用std::isupperlambda替换。]

以上是Howdoesincludinggtest.hbreaktemplateargumentdeductionforastdalgorithm?的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>