Names with trailing question mark

Jacob Carlborg doob at me.com
Tue Oct 4 07:06:06 PDT 2011


On 2011-10-04 12:22, Gor Gyolchanyan wrote:
> Here's what i suggest to do:
>
> struct MyTestStruct
> {
>      int[] array;
>
>      // opCond must take at least a single string template parameter
> and exactly two lazy parameters, second of which may have a default
> value.
>      T opCond(string name : "empty", T)(lazy T yes, lazy T no = T.init)
>      {
>          if(array.length == 0)
>              return yes;
>          else
>              return no;
>      }
> }
>
> unittest
> {
>      MyTestStruct mts;
>      auto mts.empty ? "wonderful" : "awful";
>      auto mts.empty ? "awesome";
> }
>
> Allowing this will not break any existing code, since the effect and
> rules are essentially the same.
> How about this?

That seems more like overloading the ternary operator.

-- 
/Jacob Carlborg


More information about the Digitalmars-d mailing list