DEV Community

Discussion on: Three ways to use the = delete specifier in C++

Collapse
 
pgradot profile image
Pierre Gradot

For templates, I would prefer something like:

template<typename T>
void bar() {
    static_assert(not std::is_same_v<T, int>, "T cannot be 'int', this is not supported");
}
Enter fullscreen mode Exit fullscreen mode

because it displays an error message to explain why bar<int> is not accepted.

Collapse
 
sandordargo profile image
Sandor Dargo

Right, meaningful error messages are a great treasure in C++! Especially with templates.

Collapse
 
pgradot profile image
Pierre Gradot

A colleague has just me how to do this with concepts from C++20. I will have to write an article about every possibilities we have :D

Thread Thread
 
sandordargo profile image
Sandor Dargo

Yeah, it's something I have in mind for the next few months, to experiment with concepts. They seem really interesting.

Collapse
 
maresia profile image
Maresia • Edited

Why libstdc++ authors don't use this? It would be incredible to receive a readable error message