Reputation: 33924
The std::unary_function
feature was deprecated in c++11 and deleted in c++17. But with the c++17 compiler flag, this code still compiles:
struct less_than_7 : std::unary_function<int, bool>
{
bool operator()(int i) const { return i < 7; }
};
Built with g++ -std=c++17 -O0 -Wall -pedantic main.cpp
here.
Is a feature deletion optional for a compiler to implement?
Upvotes: 4
Views: 2881
Reputation: 385295
While it's nice to have standards, and multiple versions of those standards, the reality is that different toolchains have different levels of compliance.
This may involve delays implementing new features, delays implementing changes, or delays removing things.
This is simply a case of the latter.
VS 2019 has removed std::unary_function
, but neither libstdc++ nor libc++ has yet. That's just how it is!
Upvotes: 2
Reputation: 180010
I'm trying to find the appropriate wording, but implementations do have a lot of leeway in adding extra names to std
. That's a major reason why you can't - the two names might clash.
In particular, the existing implementation can have helper classes in std
. Thus std::unary_function
might have become merely a helper template for this particular implementation.
Upvotes: 1
Reputation: 234795
Since it's no longer part of the C++17 standard its inclusion in one of your source code files falls into the same category as code that introduces things into std
.
In other words, the program behaviour is undefined.
The program working is a manifestation of that undefined behaviour. And perhaps your implementation defines that undefined behaviour. But even so, your code is not portable C++17.
Upvotes: 4