digitalmars.D.bugs - [Issue 3546] New: Aliasing an element of a static array should be legal if the index is a compile time constant
- d-bugmail puremagic.com (25/25) Nov 23 2009 http://d.puremagic.com/issues/show_bug.cgi?id=3546
- d-bugmail puremagic.com (59/59) Oct 11 2010 http://d.puremagic.com/issues/show_bug.cgi?id=3546
- d-bugmail puremagic.com (9/9) Nov 15 2012 http://d.puremagic.com/issues/show_bug.cgi?id=3546
http://d.puremagic.com/issues/show_bug.cgi?id=3546 Summary: Aliasing an element of a static array should be legal if the index is a compile time constant Product: D Version: 2.036 Platform: Other OS/Version: Windows Status: NEW Severity: minor Priority: P2 Component: DMD AssignedTo: nobody puremagic.com ReportedBy: dsimcha yahoo.com uint[3] foo; alias foo[0] bar; Error: test8.d(2): Error: alias test8.bar cannot alias an expression foo[0] Since foo is a static array and 0 is a compile time constant, there is no reason this shouldn't work. It works with tuples, and static arrays really should offer a superset of tuple functionality because they are implemented the same way as tuples with all the same type. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Nov 23 2009
http://d.puremagic.com/issues/show_bug.cgi?id=3546 Manuel König <manuelk89 gmx.net> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |manuelk89 gmx.net I second that. You can even do that with some template magic, so it would be nice if the compiler could remove the burden to use such tricks from the developer: In D1 I do: template Aliasable(alias arg) { alias arg Aliasable; } template Aliasable(arg...) { static assert(arg.length == 1, "bad usage of Aliasable detected"); alias arg Aliasable; } alias Aliasable!("foo") foo; alias Aliasable!(int) MyInt; I'm not sure if that handles all cases, and I've found a similar template for D2 in std.typetupl: /* * [internal] With the builtin alias declaration, you cannot declare * aliases of, for example, literal values. You can alias anything * including literal values via this template. */ private { // symbols and literal values template Alias(alias a) { static if (__traits(compiles, { alias a x; })) alias a Alias; else static if (__traits(compiles, { enum x = a; })) enum Alias = a; else static assert(0, "Cannot alias " ~ a.stringof); } // types and tuples template Alias(a...) { alias a Alias; } } unittest { enum abc = 1; static assert(__traits(compiles, { alias Alias!(123) a; })); static assert(__traits(compiles, { alias Alias!(abc) a; })); static assert(__traits(compiles, { alias Alias!(int) a; })); static assert(__traits(compiles, { alias Alias!(1,abc,int) a; })); } So this MakeAliasable!(...) template was at least invented twice, which shows there is a need :) -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Oct 11 2010
http://d.puremagic.com/issues/show_bug.cgi?id=3546 Walter Bright <bugzilla digitalmars.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |bugzilla digitalmars.com Severity|minor |enhancement -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Nov 15 2012