"if not" condition check (for data validation)

Ali Çehreli acehreli at yahoo.com
Thu Jun 18 02:24:04 UTC 2020


On 6/17/20 4:46 PM, Denis wrote:> Is there a cleaner way to implement an 
"if not" condition check?

 >    if ( configfile.isFile && configfile.extension == ".conf", message 
) { }
 >    else <handle it>

   if (isConfigFile(name)) {
     // ...

   } else {
     // ...
   }

The following is suitable in many cases:

   enforce(isConfigFile(name), format!"%s is not a config file"(name));
   // ...

I shortened that in many occasions:

   enforceConfigFile(name);
   // ...

Of course, depending on the situation it is assert() or assertConfigFile().

Ali



More information about the Digitalmars-d-learn mailing list