digitalmars.D.learn - alias to fully qualified enum in scope where enum is expected
- Timothee Cour via Digitalmars-d-learn (11/11) Aug 05 2014 Is there a simple way to to do this?
- Rikki Cattermole (13/24) Aug 06 2014 The magic of with statements!
- Meta (4/16) Aug 06 2014 And if you want to be *really* concise:
- Timothee Cour via Digitalmars-d-learn (10/28) Aug 06 2014 Thanks, I know with statement could be used but I was hoping for a solut...
- "Marc =?UTF-8?B?U2Now7x0eiI=?= <schuetzm gmx.net> (6/9) Aug 06 2014 If you control the declaration of the enum, you could write:
- Timothee Cour via Digitalmars-d-learn (12/22) Aug 06 2014 yes, but that pollutes the scope, what I wanted was to only expose the
Is there a simple way to to do this? enum A{ a1, a2 } void fun(A a){...} void test(){ fun(A.a1); //works fun(a1); //I'd like a1 to work, but just where an A is expected to avoid polluting namespace. }
Aug 05 2014
On 6/08/2014 6:11 p.m., Timothee Cour via Digitalmars-d-learn wrote:Is there a simple way to to do this? enum A{ a1, a2 } void fun(A a){...} void test(){ fun(A.a1); //works fun(a1); //I'd like a1 to work, but just where an A is expected to avoid polluting namespace. }The magic of with statements! enum A { a1, a2 } void func(A a){} void main(){ func(A.a1); with(A) { func(a1); } }
Aug 06 2014
On Wednesday, 6 August 2014 at 07:23:32 UTC, Rikki Cattermole wrote:The magic of with statements! enum A { a1, a2 } void func(A a){} void main(){ func(A.a1); with(A) { func(a1); } }And if you want to be *really* concise: with (A) fun(a1);
Aug 06 2014
Thanks, I know with statement could be used but I was hoping for a solution not involving adding syntax to call site. void fun(with(A){A a}, int b){...} //conceptually like this void test(){ int a1=1; fun(A.a1, a1); // would work fun(a1, a1); // would work } On Wed, Aug 6, 2014 at 8:22 AM, Meta via Digitalmars-d-learn < digitalmars-d-learn puremagic.com> wrote:On Wednesday, 6 August 2014 at 07:23:32 UTC, Rikki Cattermole wrote:The magic of with statements! enum A { a1, a2 } void func(A a){} void main(){ func(A.a1); with(A) { func(a1); } }And if you want to be *really* concise: with (A) fun(a1);
Aug 06 2014
On Wednesday, 6 August 2014 at 16:48:57 UTC, Timothee Cour via Digitalmars-d-learn wrote:Thanks, I know with statement could be used but I was hoping for a solution not involving adding syntax to call site.If you control the declaration of the enum, you could write: alias a1 = A.a1; alias a2 = A.a2; A bit tedious, but it works, and could be automated if need be.
Aug 06 2014
On Wed, Aug 6, 2014 at 12:04 PM, via Digitalmars-d-learn < digitalmars-d-learn puremagic.com> wrote:On Wednesday, 6 August 2014 at 16:48:57 UTC, Timothee Cour via Digitalmars-d-learn wrote:yes, but that pollutes the scope, what I wanted was to only expose the aliases in places where A is expected, see motivational in previous message: void fun(with(A){A a}, int b){...} //conceptually like this void test(){ int a1=1; fun(A.a1, a1); fun(a1, a1); // first a1 refers to A.a1, second one to local variable int a1 } ok I guess this isn't possible using current semantics.Thanks, I know with statement could be used but I was hoping for a solution not involving adding syntax to call site.If you control the declaration of the enum, you could write: alias a1 = A.a1; alias a2 = A.a2; A bit tedious, but it works, and could be automated if need be.
Aug 06 2014