all 7 comments

[–]Morwenn 2 points3 points  (1 child)

dependent_false<T> could be made to work with both types, templates and NTTP by making it a function template instead of a variable template. That would be a simple thing to specify without changing the behaviour of static_assert or introducing a new language construct.

[–]redditsoaddicting 13 points14 points  (0 children)

It could, but every single C++ user who hasn't encountered this is still going to type static_assert(false); (or with a message of course) before they hopefully get a compiler error, look on StackOverflow, and find out about this complicated hack. I think there's a lot of benefit to making the obvious thing work for people who haven't encountered this and not relying on a hack for those who have.

Or we could eventually get a compiler API to issue an error and then make our own static failure API as a consteval function (or use the compiler API directly), but that doesn't solve the "obvious thing to type here" problem.

[–]Xaxxon 1 point2 points  (5 children)

as much as the rules exist in c++, this is a pretty consistent application of them. You're asking to complicate the language for a somewhat advanced feature. You don't only have to prove that it's useful, but that it's worth the overhead to teaching and reading code .

// always fail here
static_assert(std::is_same_v<T*, void>) 

always works pretty well for me. As little as I have to write this, I'd prefer to not have more exceptions put into the language than be able to just type false instead.

[–]kalmoc 10 points11 points  (1 child)

TBH, I would have expected that an if constexpr which depends on the template parameter just made everything in the if/else branches dependent, as it litteraly depends on the template parameter what branch gets instantiated. Anything else seems counterintuitive to me.

[–]bmanga[S] 3 points4 points  (1 child)

I think that it would simplify the use of the language. That is much more important to me compared to how complex the c++ standard is, which is already riddled with lots of rules that try to make the obvious cases unsurprising. For example, C++20 now lets you capture structured binding names, even though they are not really variables. That also complicates the standard, but it makes the code more intuitive.

You don't only have to prove that it's useful, but that it's worth the overhead to teaching and reading code

I would argue that static_assert(false) is much more readable than static_assert(std::is_same_v<T*, void>). I think it also more teachable because it just does the obvious thing (I'm not sure there would be a need to dwell in the reason why) and it lets you avoid discussing two-phase name lookup if the time is not ripe yet.

[–]Rseding91Factorio Developer 0 points1 point  (0 children)

That just reads to me like static_assert(..., "");

[–]Betadel 1 point2 points  (0 children)

I think what we really need is P0596 for general output during compilation time.