I want delete or change class's member name on compile-time

Ali Çehreli acehreli at yahoo.com
Fri Jun 8 19:01:51 UTC 2018


On 06/08/2018 11:13 AM, Brian wrote:
 > Like:
 >
 > class A
 > {
 >      string b;
 >      string c;
 > }
 >
 > compile-time to:
 >
 > class A
 > {
 >      string _b;
 >      string c;
 > }
 >
 > or:
 >
 > class A
 > {
 >      string c;
 > }
 >

If these are your classes you can use static if or version:

version = Z;    // Can be provided as a compiler switch as well

class A
{
     version (X) {
         string b;

     } else version (Y) {
         string _b;
     }

      string c;
}

void main () {
}

Or with static if:

class A {
     static if (some_compile_time_condition) {
         string _b;

     } else static if (...) {
         // ...

     } else {
         // ...

     }
}

Ali



More information about the Digitalmars-d-learn mailing list