Checking function parameters in Phobos

Dmitry Olshansky dmitry.olsh at gmail.com
Wed Nov 20 10:30:55 PST 2013


20-Nov-2013 22:01, Simen Kjærås пишет:
> On 20.11.2013 18:45, Simen Kjærås wrote:
[snip]
>> May I suggest:
>>
>> struct Validated(alias fn, T) {
>>      private T value;
>>      @property inout
>>      T get() {
>>          return value;
>>      }
>
> Uh-hm. Add this:
>         alias get this;
>

And it decays to the naked type in a blink of an eye. And some function 
down the road will do the validation again...

>> }
>>
>> Validated!(fn, T) validate(alias fn, T)(T value) {
>>      Validated!(fn, T) result;
>>      fn(value);
>>      result.value = value;
>>      return result;
>> }
>>
>> void functionThatTakesSanitizedFileNames(Validated!(sanitizeFileName,
>> string) path) {
>>     // Do stuff
>> }
>>
>
>


-- 
Dmitry Olshansky


More information about the Digitalmars-d mailing list