I just came across std::set's count method and was wondering, why there is no std::set-specific optimization of count (e.g. by just returning find(arg)!=end()).
The reason for my question is that the following code:
int _tmain(int argc, _TCHAR* argv)
std::cin >> n;
size_t cnt = s.count(4);
size_t cnt = size_t(s.find(4) != s.end());
std::cout << cnt << std::endl;
generates when build with VS 2015 Update 2 x64/release/O2
with USE_BUILTIN_COUNT defined: 64 lines of assembly for the "count"
without USE_BUILTIN_COUNT defined: 21 lines of assembly for the "find != end"
In x86-builds (release, O2) it get's even worse: with USE_BUILTIN_COUNT defined, the internal std::set calls to _Eqrange and _Distance2 won't get inlined!
Please check, if it's possible to tweek std::set's count method.
PS: I haven't looked up the standard, to check if this optimization is prohibited in some way.