digitalmars.D - good example of assert as expression ?
- user1234 (19/19) Feb 03 Following a [previous
- Richard (Rikki) Andrew Cattermole (4/28) Feb 03 && isn't useful here, its ||
- user1234 (3/8) Feb 03 Ah yes, OrOr. Shame on me.
- user1234 (2/13) Feb 03 Initial question still stands however.
- Timon Gehr (6/10) Feb 04 auto x = c0 ? e0 :
Following a [previous thread](https://forum.dlang.org/thread/loojkahtbzigawrscmsr forum.dlang.org), can you give me good example where the assert expression is useful ? So far I only see the case where it is used as AndAnd RHS. ```d void main() { auto lhs() { extern(C) int rnd; return (rnd % 1) + 1; } lhs() && assert(0); } ``` I remember an old NG topic where someone asked if D supports the "assert idiom". So seriously assert as an expression just works in this context ? I mean don't you think it's an obscure feature that could be removed ?
Feb 03
On 04/02/2026 8:58 AM, user1234 wrote:Following a [previous thread](https://forum.dlang.org/thread/ loojkahtbzigawrscmsr forum.dlang.org), can you give me good example where the assert expression is useful ? So far I only see the case where it is used as AndAnd RHS. ```d void main() { auto lhs() { extern(C) int rnd; return (rnd % 1) + 1; } lhs() && assert(0); } ``` I remember an old NG topic where someone asked if D supports the "assert idiom". So seriously assert as an expression just works in this context ? I mean don't you think it's an obscure feature that could be removed ?&& isn't useful here, its || I.e. we use it in the form of ``ptr || assert(0)`` for the null check (not exact but close enough).
Feb 03
On Tuesday, 3 February 2026 at 20:01:47 UTC, Richard (Rikki) Andrew Cattermole wrote:On 04/02/2026 8:58 AM, user1234 wrote:Ah yes, OrOr. Shame on me.[...]&& isn't useful here, its || I.e. we use it in the form of ``ptr || assert(0)`` for the null check (not exact but close enough).
Feb 03
On Tuesday, 3 February 2026 at 20:03:31 UTC, user1234 wrote:On Tuesday, 3 February 2026 at 20:01:47 UTC, Richard (Rikki) Andrew Cattermole wrote:Initial question still stands however.On 04/02/2026 8:58 AM, user1234 wrote:Ah yes, OrOr. Shame on me.[...]&& isn't useful here, its || I.e. we use it in the form of ``ptr || assert(0)`` for the null check (not exact but close enough).
Feb 03
On 2/3/26 20:58, user1234 wrote:Following a [previous thread](https://forum.dlang.org/thread/ loojkahtbzigawrscmsr forum.dlang.org), can you give me good example where the assert expression is useful ?auto x = c0 ? e0 : c1 ? e1 : c2 ? e2 : assert(0);I mean don't you think it's an obscure feature that could be removed ?Every feature can be removed. Should it be removed? No.
Feb 04









user1234 <user1234 12.de> 