Templates and stringof...

Era Scarecrow rtcvb32 at yahoo.com
Fri Aug 3 16:54:28 PDT 2012


On Friday, 3 August 2012 at 22:50:54 UTC, David Nadlinger wrote:
> On Friday, 3 August 2012 at 22:44:28 UTC, Andrej Mitrovic wrote:
>> In fact, this should really be put into Phobos so everyone can 
>> benefit rather than implementing this internally as a private 
>> template of bitmanip.
>
> No, it shouldn't be. There are almost no legit use cases for 
> it, and having it in the library encourages abuse of string 
> mixins/stringof in cases like this one.

  Then doesn't it seem like we're missing a potentially important 
piece of the puzzle for mixins and templates? very likely my 
modified template will include you including the same variable 
twice, but if someone gets lazy then it may not work.

  mixin(bitfieldsOn!("SomeVariable", SomeVariable, /*stuff*/));
  // or
  mixin(bitfieldsOn!("SomeVariable", variable type, /*stuff*/));

  But if it comes to it, what if they use auto or point to 
something else just to make it shut up? Constraints will let it 
pass but the code will pop up with errors that may not be 
reasonably readable.

  long l;
  float fl;
  mixin(bitfieldsOn!("fl", l, /*stuff*/)); //by name, typo or lazy
  //or
  mixin(bitfieldsOn!("fl", auto, /*stuff*/)); //explicit type, 
lazy or lying

  Now the checks pass but the compile code works wrong.

  True I can add asserts as part of the output code, but as 
mentioned hopefully the constraints could do that work, plus 
adding extra checks as part of a mixin seems a little...  
excessive.

  Let's assume we use 'localStringof' or 'callingStringof' and 
that it returns the string of how the variable is 
called/referenced; Give me some examples how it would be abused 
or used wrongly? Aliased variables are pretty much perfect 
forwarded in templates (Unless my understanding is off) so they 
would carry that information forward.


More information about the Digitalmars-d-learn mailing list