| Thread overview | |||||||
|---|---|---|---|---|---|---|---|
|
December 30, 2014 Aliases and UDA's | ||||
|---|---|---|---|---|
| ||||
I've got this thing going on where I want to be able to attribute an alias, but that doesn't seem to work:
@("hello")
struct(X) S
{
X x;
}
@("world")
alias A = S!int;
Test!A;
template(T) Test
{
// at this point, if T is some S, then the "hello" attribute is
present, as expected
// if T is A, "world" is lost
}
I guess the reason is that A is not really a thing; it is translated
to S!int when being given to T?
Is that the point where "world" is lost?
I'm not really sure how I can achieve what I want here... I need to attribute particular instantiations of a template struct as shown.
| ||||
December 30, 2014 Re: Aliases and UDA's | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Manu | "Manu via Digitalmars-d" wrote in message news:mailman.3785.1419919315.9932.digitalmars-d@puremagic.com... > I guess the reason is that A is not really a thing; it is translated > to S!int when being given to T? > Is that the point where "world" is lost? Yes. "world" is still there, but you can't actually get the symbol A. > I'm not really sure how I can achieve what I want here... I need to > attribute particular instantiations of a template struct as shown. Why does it have to be UDAs? You can easily put the 'attributes' inside S or define a template for getting the attributes from an arbitrary S. Something like: enum myAttributes(T : S!int) = TypeTuple!("world"); enum myAttributes(T : S!U, U) = TypeTuple!(); | |||
December 30, 2014 Re: Aliases and UDA's | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Daniel Murphy | On 30 December 2014 at 22:51, Daniel Murphy via Digitalmars-d <digitalmars-d@puremagic.com> wrote:
> "Manu via Digitalmars-d" wrote in message news:mailman.3785.1419919315.9932.digitalmars-d@puremagic.com...
>
>> I guess the reason is that A is not really a thing; it is translated
>> to S!int when being given to T?
>> Is that the point where "world" is lost?
>
>
> Yes. "world" is still there, but you can't actually get the symbol A.
>
>> I'm not really sure how I can achieve what I want here... I need to attribute particular instantiations of a template struct as shown.
>
>
> Why does it have to be UDAs? You can easily put the 'attributes' inside S or define a template for getting the attributes from an arbitrary S.
>
> Something like:
> enum myAttributes(T : S!int) = TypeTuple!("world");
> enum myAttributes(T : S!U, U) = TypeTuple!();
In this particular case, I'm actually attributing pixel structures
with an enum that describes the pixel format to a 3rd party library.
I can approach it differently, but it was just a particularly
convenient and un-intrusive way to get the data through to the 3rd
party API.
It seemed nicer as an attribute; if I pollute the type with the 3rd
party enum by making it a template arg or something, then my type
can't exist on its own without knowledge of the particular 3rd party
lib. Like, it would expect to be given this enum to instantiate, and
that's unnecessary restrictive.
I guess I'll have to explore some alternatives.
| |||
December 31, 2014 Re: Aliases and UDA's | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Manu | On 2014-12-30 07:01, Manu via Digitalmars-d wrote: > I've got this thing going on where I want to be able to attribute an > alias, but that doesn't seem to work: > > @("hello") > struct(X) S > { > X x; > } > > @("world") > alias A = S!int; > > Test!A; > > template(T) Test > { > // at this point, if T is some S, then the "hello" attribute is > present, as expected > // if T is A, "world" is lost > } > > I guess the reason is that A is not really a thing; it is translated > to S!int when being given to T? > Is that the point where "world" is lost? What if you make T an alias parameter, will that work? -- /Jacob Carlborg | |||
December 31, 2014 Re: Aliases and UDA's | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Jacob Carlborg Attachments:
| I tried that. It doesn't work.
It's also not really what I want.
On 31/12/2014 9:35 pm, "Jacob Carlborg via Digitalmars-d" <
digitalmars-d@puremagic.com> wrote:
> On 2014-12-30 07:01, Manu via Digitalmars-d wrote:
>
>> I've got this thing going on where I want to be able to attribute an alias, but that doesn't seem to work:
>>
>> @("hello")
>> struct(X) S
>> {
>> X x;
>> }
>>
>> @("world")
>> alias A = S!int;
>>
>> Test!A;
>>
>> template(T) Test
>> {
>> // at this point, if T is some S, then the "hello" attribute is
>> present, as expected
>> // if T is A, "world" is lost
>> }
>>
>> I guess the reason is that A is not really a thing; it is translated
>> to S!int when being given to T?
>> Is that the point where "world" is lost?
>>
>
> What if you make T an alias parameter, will that work?
>
> --
> /Jacob Carlborg
>
| |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply