How come that std::greater is no more part of the std namespace in Visual Studio 2012? I now need to include <functional>
I thought STL libraries remained the same across toolsets
How come that std::greater is no more part of the std namespace in Visual Studio 2012?
I'd be very surprised if that were the case.
I now need to include
<functional.h>
No, you need to include <functional>
since that's the header that defines all the standard function objects, including greater
.
I thought STL libraries remained the same across toolsets
They should be. But headers are allowed to include other headers, so sometimes you'll find that something is available even if you haven't included the correct header. But you can't rely on that, as you've found here. Always include all the headers you need for the things you use.
The following example, taken from here, compiles and executes correctly for me in Visual Studio 2012:
// greater example
#include <iostream> // std::cout
#include <functional> // std::greater
#include <algorithm> // std::sort
int main () {
int numbers[]={20,40,50,10,30};
std::sort (numbers, numbers+5, std::greater<int>());
for (int i=0; i<5; i++)
std::cout << numbers[i] << ' ';
std::cout << '\n';
return 0;
}
Output:
50 40 30 20 10
As per the question comments and the example above, you need to include <functional>
, not <functional.h>
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With