[Issue 3546] Aliasing an element of a static array should be legal if the index is a compile time constant
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Mon Oct 11 12:58:02 PDT 2010
http://d.puremagic.com/issues/show_bug.cgi?id=3546
Manuel König <manuelk89 at gmx.net> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |manuelk89 at gmx.net
--- Comment #1 from Manuel König <manuelk89 at gmx.net> 2010-10-11 12:57:33 PDT ---
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: -------
More information about the Digitalmars-d-bugs
mailing list