Compare boost::hana to D
Steven Schveighoffer via Digitalmars-d
digitalmars-d at puremagic.com
Sun Apr 23 06:41:18 PDT 2017
On 4/23/17 12:22 AM, Jesse Phillips wrote:
> On Friday, 21 April 2017 at 13:10:43 UTC, Adam D. Ruppe wrote:
>> On Wednesday, 19 April 2017 at 18:02:46 UTC, Adrian Matoga wrote:
>>> [2] https://epi.github.io/2017/03/18/less_fun.html
>>
>> BTW in your D foreach, you could also have done `switch`
>>
>> void trigger(string event) {
>> switch(event) {
>> foreach (i, e; events) {
>> case e:
>> foreach (c; callbacks_[i])
>> c();
>> return;
>> }
>> default:
>> assert(false, "trying to trigger an unknown event: " ~ event);
>> }
>> }
>>
>>
>> And the compiler+runtime can optimize that into a binary search when
>> it gets larger automatically.
>
> Doesn't the latest compiler complain with a depreciation that i/e
> initialization is being skipped?
Yep, but it's just a warning. A really annoying warning.
https://issues.dlang.org/show_bug.cgi?id=16521 has more details. static
foreach + switch can be bad if you ref the elements of the tuple. The
"correct" thing to do is:
foreach(i, _unused; someTuple)
{
// use someTuple[i] instead of _unused
}
You will still get the warning though.
-Steve
More information about the Digitalmars-d
mailing list