<div dir="ltr"><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, 24 Aug 2024 at 21:46, IchorDev via Digitalmars-d <<a href="mailto:digitalmars-d@puremagic.com">digitalmars-d@puremagic.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Saturday, 24 August 2024 at 09:11:34 UTC, user1234 wrote:<br>
> On Saturday, 24 August 2024 at 08:06:21 UTC, IchorDev wrote:<br>
>> I think everyone in this thread can agree that we need a <br>
>> compiler-agnostic solution for changing the presumed hot-path, <br>
>> and one that doesn’t require rewriting existing code more than <br>
>> just adding on one word. For example, `if((x == <br>
>> y).expect(false)){}` makes it a pain to rewrite existing <br>
>> `if`s, where `@unlikely if(x == y) {}` is easy.<br>
><br>
> You also have the `pragma` option. I think that would be more <br>
> adequate as not every vendor has to support it. In other words <br>
> "dmd can just ignore it". Bonus: pragma can be attached to <br>
> statements, that's not the case of attributes.<br>
<br>
Like `pragma(likely, false)`? It’s a bit long, maybe <br>
`pragma(unlikely)`? It’s something I’d want to use fairly often, <br>
after all. Or we could just add some new grammar for adding <br>
special modifiers to if statements. Something like…<br>
```d<br>
if: unlikely(x){<br>
   //…<br>
}<br>
if(!x){<br>
   //…<br>
}else: likely{<br>
   //…<br>
}<br>
```<br></blockquote><div><br></div><div>
<div dir="ltr"><div>C++ is way ahead on this... they 
added attributes to the language years back, and they defined [[likely]]
 and [[unlikely]] post-fix on control statements. It's really 
convenient, it reads well, and it's easy to retrofit without disturbing 
the code.<br></div><div>That's the de-facto now, and we should follow it.<br></div></div></div></div></div>