www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Is there Typeof template ?

reply Temtaime <temtaime gmail.com> writes:
Hi !
Tried to find
alias Typeof(alias A) = typeof(A);
or something, but failed.

Are there something or should I create a PR to phobos?
Thanks
Oct 28 2016
next sibling parent reply Adam D. Ruppe <destructionator gmail.com> writes:
On Friday, 28 October 2016 at 10:52:05 UTC, Temtaime wrote:
 Are there something or should I create a PR to phobos?
Why would you want that?
Oct 28 2016
parent reply Temtaime <temtaime gmail.com> writes:
On Friday, 28 October 2016 at 12:44:20 UTC, Adam D. Ruppe wrote:
 On Friday, 28 October 2016 at 10:52:05 UTC, Temtaime wrote:
 Are there something or should I create a PR to phobos?
Why would you want that?
I have UDAs with values à la (`str`, 123) uint k; And i want to know a type of a value.
Oct 28 2016
parent reply =?UTF-8?Q?Ali_=c3=87ehreli?= <acehreli yahoo.com> writes:
On 10/28/2016 05:48 AM, Temtaime wrote:
 On Friday, 28 October 2016 at 12:44:20 UTC, Adam D. Ruppe wrote:
 On Friday, 28 October 2016 at 10:52:05 UTC, Temtaime wrote:
 Are there something or should I create a PR to phobos?
Why would you want that?
I have UDAs with values à la (`str`, 123) uint k; And i want to know a type of a value.
How are you using those? typeof works with any value: void main() { (`str`, 123) uint k; foreach (a; __traits(getAttributes, k)) { pragma(msg, typeof(a)); } } Prints string int You can use indexes with the loop as well: foreach (i, a; /* ... */ Ali
Oct 28 2016
parent reply Jonathan M Davis via Digitalmars-d-learn writes:
On Friday, October 28, 2016 11:19:46 Ali ehreli via Digitalmars-d-learn 
wrote:
 On 10/28/2016 05:48 AM, Temtaime wrote:
 On Friday, 28 October 2016 at 12:44:20 UTC, Adam D. Ruppe wrote:
 On Friday, 28 October 2016 at 10:52:05 UTC, Temtaime wrote:
 Are there something or should I create a PR to phobos?
Why would you want that?
I have UDAs with values la (`str`, 123) uint k; And i want to know a type of a value.
How are you using those? typeof works with any value: void main() { (`str`, 123) uint k; foreach (a; __traits(getAttributes, k)) { pragma(msg, typeof(a)); } } Prints string int You can use indexes with the loop as well: foreach (i, a; /* ... */
I don't know if Typeof is actually needed for what the OP is trying to do, but if you wanted to apply typeof using something like std.meta.staticMap, then you'd need something like Typeof. - Jonathan M Davis
Oct 28 2016
parent reply =?UTF-8?Q?Ali_=c3=87ehreli?= <acehreli yahoo.com> writes:
On 10/28/2016 11:25 AM, Jonathan M Davis via Digitalmars-d-learn wrote:

 void main() {
       (`str`, 123) uint k;
      foreach (a; __traits(getAttributes, k)) {
          pragma(msg, typeof(a));
      }
 }
 I don't know if Typeof is actually needed for what the OP is trying 
to do,
 but if you wanted to apply typeof using something like 
std.meta.staticMap,
 then you'd need something like Typeof.
I see. Just to add something that I've just remembered, it is possible to apply typeof to __traits(getAttributes) as well: foreach (T; typeof(__traits(getAttributes, k))) { pragma(msg, T); } Now we get a list of types: string int Ali
Oct 28 2016
parent Temtaime <temtaime gmail.com> writes:
On Friday, 28 October 2016 at 18:39:36 UTC, Ali Çehreli wrote:
 On 10/28/2016 11:25 AM, Jonathan M Davis via 
 Digitalmars-d-learn wrote:

 void main() {
       (`str`, 123) uint k;
      foreach (a; __traits(getAttributes, k)) {
          pragma(msg, typeof(a));
      }
 }
 I don't know if Typeof is actually needed for what the OP is
trying to do,
 but if you wanted to apply typeof using something like
std.meta.staticMap,
 then you'd need something like Typeof.
I see. Just to add something that I've just remembered, it is possible to apply typeof to __traits(getAttributes) as well: foreach (T; typeof(__traits(getAttributes, k))) { pragma(msg, T); } Now we get a list of types: string int Ali
I wanna use it with staticMap.
Oct 28 2016
prev sibling parent Jonathan M Davis via Digitalmars-d-learn writes:
On Friday, October 28, 2016 10:52:05 Temtaime via Digitalmars-d-learn wrote:
 Hi !
 Tried to find
 alias Typeof(alias A) = typeof(A);
 or something, but failed.

 Are there something or should I create a PR to phobos?
 Thanks
If it were in Phobos, I'd expect it to be in std.meta, and it's not there. - Jonathan M Davis
Oct 28 2016