Date: Fri, 17 Apr 2026 08:10:16 -0700
On Friday, 17 April 2026 03:35:13 Pacific Daylight Time David Brown via Std-
Proposals wrote:
> > I am not a big fan of static_assert and to my understanding the c++
> > community has started to make a push away from it.
> >
> > This is news to me.
>
> And to me. Static assertions are a great idea - they express things you
> used to write in comments, but now you have them in code and checked by
> tools with zero run-time cost.
The requires clause is a replacement and expansion to enable_if. It serves a
similar but different purpose than static_assert. If you want something not to
participate in overload resolution, you use requires, so the other
possibilities (if any) are still present. If you want this to participate but
check some conditions, use static_assert.
And of course you can use both together, for an even more powerful
static_assert.
static_assert(requires { ... });
Proposals wrote:
> > I am not a big fan of static_assert and to my understanding the c++
> > community has started to make a push away from it.
> >
> > This is news to me.
>
> And to me. Static assertions are a great idea - they express things you
> used to write in comments, but now you have them in code and checked by
> tools with zero run-time cost.
The requires clause is a replacement and expansion to enable_if. It serves a
similar but different purpose than static_assert. If you want something not to
participate in overload resolution, you use requires, so the other
possibilities (if any) are still present. If you want this to participate but
check some conditions, use static_assert.
And of course you can use both together, for an even more powerful
static_assert.
static_assert(requires { ... });
-- Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org Principal Engineer - Intel Data Center - Platform & Sys. Eng.
Received on 2026-04-17 15:10:26
