Thread overview
I want delete or change class's member name on compile-time
Jun 08, 2018
Brian
Jun 08, 2018
Ali Çehreli
June 08, 2018
Like:

class A
{
    string b;
    string c;
}

compile-time to:

class A
{
    string _b;
    string c;
}

or:

class A
{
    string c;
}

June 08, 2018
On 6/8/18 2:13 PM, Brian wrote:
> Like:
> 
> class A
> {
>      string b;
>      string c;
> }
> 
> compile-time to:
> 
> class A
> {
>      string _b;
>      string c;
> }
> 
> or:
> 
> class A
> {
>      string c;
> }
> 

Not possible in D. What you are looking for is an AST macro, and D does not have those.

However, you can potentially create another type that mimics everything that A does except for one thing using compile-time introspection. But you won't be able to do that with the member functions.

-Steve
June 08, 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