digitalmars.D.learn - I want delete or change class's member name on compile-time
- Brian (17/17) Jun 08 2018 Like:
- Steven Schveighoffer (7/30) Jun 08 2018 Not possible in D. What you are looking for is an AST macro, and D does
- =?UTF-8?Q?Ali_=c3=87ehreli?= (25/42) Jun 08 2018 If these are your classes you can use static if or version:
Like:
class A
{
string b;
string c;
}
compile-time to:
class A
{
string _b;
string c;
}
or:
class A
{
string c;
}
Jun 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
Jun 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
Jun 08 2018









Steven Schveighoffer <schveiguy yahoo.com> 