Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does `std::unary_function` still compile in c++17?

Tags:

c++

g++

c++17

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?

like image 628
Fantastic Mr Fox Avatar asked Mar 06 '23 16:03

Fantastic Mr Fox


1 Answers

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.

like image 94
Bathsheba Avatar answered Mar 16 '23 07:03

Bathsheba