Re: Traits in a template enum

2021-10-10 Thread Mike Parker via Digitalmars-d-learn
On Sunday, 10 October 2021 at 12:56:30 UTC, Some Guy wrote: But I did not understand what you meant by "enums hold values, not types". Aren't types values at compile time? Types can be template arguments, if that's what you mean, but they aren't values.

Re: Traits in a template enum

2021-10-10 Thread Some Guy via Digitalmars-d-learn
On Sunday, 10 October 2021 at 12:48:49 UTC, Adam D Ruppe wrote: On Sunday, 10 October 2021 at 12:39:17 UTC, Some Guy wrote: I have this enum to get the type enums hold values, not types. try alias instead Thanks! `alias typeOfMember(T, string member) = typeof(__traits(getMember, T, member)

Re: Traits in a template enum

2021-10-10 Thread Adam D Ruppe via Digitalmars-d-learn
On Sunday, 10 October 2021 at 12:39:17 UTC, Some Guy wrote: I have this enum to get the type enums hold values, not types. try alias instead

Re: Traits in a template enum

2021-10-10 Thread Some Guy via Digitalmars-d-learn
It actually looks like I'm having problems wherever I try to pass that enum as a template parameter.

Re: Traits of variadic templates

2021-02-09 Thread Jeff via Digitalmars-d-learn
On Tuesday, 9 February 2021 at 16:25:46 UTC, Paul Backus wrote: On Tuesday, 9 February 2021 at 16:22:16 UTC, Jeff wrote: But, those don't work because T is a Tuple of the types. Is there some trait combination I can use to do this? Something like (obviously made up)... all(TemplateArgsOf!T, t

Re: Traits of variadic templates

2021-02-09 Thread Paul Backus via Digitalmars-d-learn
On Tuesday, 9 February 2021 at 16:22:16 UTC, Jeff wrote: But, those don't work because T is a Tuple of the types. Is there some trait combination I can use to do this? Something like (obviously made up)... all(TemplateArgsOf!T, t => isIntegral!t || isSomeString!t) Thanks! import std.meta: a

Re: traits getOverload of a template method

2018-09-11 Thread Basile B. via Digitalmars-d-learn
On Thursday, 6 February 2014 at 23:06:03 UTC, QAston wrote: How do i get aliases to overloads of a template method like Class A { int a(T)(T tq,T tw); int a(T)(T tq); } __traits(getOverloads, A, "a(int)")doesnt work Support for template in the getOverloads trait has been added recentl

Re: traits getOverload of a template method

2018-09-10 Thread aliak via Digitalmars-d-learn
On Monday, 10 September 2018 at 13:46:08 UTC, aliak wrote: On Monday, 10 September 2018 at 12:57:25 UTC, Timoses wrote: How to "select" one? Can you either: alias myPeek = () => peek!(int, Endian.bigEndian, immutable(ubyte)[])(); Or alias myPeek = (size_t *index) => peek!(int, Endian.bigEn

Re: traits getOverload of a template method

2018-09-10 Thread aliak via Digitalmars-d-learn
On Monday, 10 September 2018 at 12:57:25 UTC, Timoses wrote: On Thursday, 6 February 2014 at 23:06:03 UTC, QAston wrote: [...] Is there any way to "select" overloaded template functions? I require to select one of `std.bitmanip.peek` import std.bitmanip : peek; import std.system : En

Re: traits getOverload of a template method

2018-09-10 Thread Timoses via Digitalmars-d-learn
On Thursday, 6 February 2014 at 23:06:03 UTC, QAston wrote: How do i get aliases to overloads of a template method like Class A { int a(T)(T tq,T tw); int a(T)(T tq); } __traits(getOverloads, A, "a(int)")doesnt work Is there any way to "select" overloaded template functions? I require

Re: Traits redux

2018-03-03 Thread arturg via Digitalmars-d-learn
On Saturday, 3 March 2018 at 16:20:57 UTC, JN wrote: https://run.dlang.io/gist/ec7008372d60ac52460dd58068f1ca6d?compiler=dmd Why only listUDA2 works and listUDA doesn't? Why do I need to use __traits(getMember again, if I use what I saved in a variable, it doesn't work :( because getUDAs ret

Re: traits for function having actual source declaration?

2017-09-01 Thread bitwise via Digitalmars-d-learn
On Friday, 1 September 2017 at 18:06:04 UTC, Jonathan M Davis wrote: [...] You can use std.meta.Filter if you need to filter anything out of an AliasSeq like this, and whether you should be filtering out those functions is highly dependent on what you're doing - e.g. sometimes, you really wan

Re: traits for function having actual source declaration?

2017-09-01 Thread Jonathan M Davis via Digitalmars-d-learn
On Friday, September 01, 2017 14:38:38 bitwise via Digitalmars-d-learn wrote: > When I'm using __traits(allMembers), I get a all the invisible > functions added by the compiler as well "__ctor", "__xdtor", > "__cpctor", etc.. > > Is there a way to filter them out? You can use std.meta.Filter if y

Re: traits for function having actual source declaration?

2017-09-01 Thread bitwise via Digitalmars-d-learn
On Friday, 1 September 2017 at 17:26:11 UTC, ketmar wrote: [...] they *should* listen. anyone who doesn't just aksing for troubles, and i see no reason to guard 'em further. Yeah...eventually came to the same conclusion ;) Thanks

Re: traits for function having actual source declaration?

2017-09-01 Thread ketmar via Digitalmars-d-learn
bitwise wrote: On Friday, 1 September 2017 at 14:38:38 UTC, bitwise wrote: When I'm using __traits(allMembers), I get a all the invisible functions added by the compiler as well "__ctor", "__xdtor", "__cpctor", etc.. Is there a way to filter them out? dlang's "Lexical" page says: "Identifi

Re: traits for function having actual source declaration?

2017-09-01 Thread bitwise via Digitalmars-d-learn
On Friday, 1 September 2017 at 14:38:38 UTC, bitwise wrote: When I'm using __traits(allMembers), I get a all the invisible functions added by the compiler as well "__ctor", "__xdtor", "__cpctor", etc.. Is there a way to filter them out? dlang's "Lexical" page says: "Identifiers starting wit

Re: traits compiles does not work for symbols from other modules

2017-07-25 Thread Andre Pany via Digitalmars-d-learn
On Tuesday, 25 July 2017 at 11:34:23 UTC, Andre Pany wrote: On Tuesday, 25 July 2017 at 08:30:43 UTC, ag0aep6g wrote: Works for me. What compiler are you using? I reduced the example too lot. The issue is occuring if there is also a package.d is involved. m1.d --- modul

Re: traits compiles does not work for symbols from other modules

2017-07-25 Thread Andre Pany via Digitalmars-d-learn
On Tuesday, 25 July 2017 at 08:30:43 UTC, ag0aep6g wrote: Works for me. What compiler are you using? I reduced the example too lot. The issue is occuring if there is also a package.d is involved. m1.d --- module m1; import sub; // Does not throw if replaced with: import

Re: traits compiles does not work for symbols from other modules

2017-07-25 Thread ag0aep6g via Digitalmars-d-learn
On 07/24/2017 11:40 PM, Andre Pany wrote: m1.d - module m1; import m2; class Foo { int foo; } void main() { static assert(__traits(compiles, m1.Foo.foo)); static assert(__traits(compiles, m2.Bar.bar)); } m2.d --- module m2; class Bar { int bar;

Re: traits help

2016-09-18 Thread Bauss via Digitalmars-d-learn
On Sunday, 18 September 2016 at 13:28:15 UTC, ketmar wrote: https://issues.dlang.org/show_bug.cgi?id=11595 https://issues.dlang.org/show_bug.cgi?id=16044 Thanks that clarifies my issues... Do you if there are any statuses on that?

Re: traits help

2016-09-18 Thread ketmar via Digitalmars-d-learn
https://issues.dlang.org/show_bug.cgi?id=11595 https://issues.dlang.org/show_bug.cgi?id=16044

Re: traits getOverload of a template method

2016-01-26 Thread ZombineDev via Digitalmars-d-learn
On Thursday, 6 February 2014 at 23:06:03 UTC, QAston wrote: How do i get aliases to overloads of a template method like Class A { int a(T)(T tq,T tw); int a(T)(T tq); } __traits(getOverloads, A, "a(int)")doesnt work Bump. I also have a similar problem. I have a module with two functio

Re: Traits question and compiler crash

2015-04-14 Thread Filippo Fantini via Digitalmars-d-learn
correct link: https://issues.dlang.org/show_bug.cgi?id=14448

Re: Traits question and compiler crash

2015-04-14 Thread Filippo Fantini via Digitalmars-d-learn
On Tuesday, 14 April 2015 at 10:43:16 UTC, anonymous wrote: On Tuesday, 14 April 2015 at 09:24:04 UTC, Filippo Fantini wrote: Hello everyone! I'm new to D. While playing with around with traits, I ended up writing this short example: module test; class Foo { private int _value = 21; v

Re: Traits question and compiler crash

2015-04-14 Thread anonymous via Digitalmars-d-learn
On Tuesday, 14 April 2015 at 09:24:04 UTC, Filippo Fantini wrote: Hello everyone! I'm new to D. While playing with around with traits, I ended up writing this short example: module test; class Foo { private int _value = 21; void foo() { import std.traits; alias f

Re: Traits and functions

2015-01-10 Thread Bauss via Digitalmars-d-learn
On Saturday, 10 January 2015 at 23:23:52 UTC, Ali Çehreli wrote: On 01/10/2015 08:21 AM, Bauss wrote: Is there a way to get all functions within a module using traits? I tried "allMembers" and it seem to work, but I can't use "getFunctionAttributes" with it and if I use "getAttributes" then it

Re: Traits and functions

2015-01-10 Thread Ali Çehreli via Digitalmars-d-learn
On 01/10/2015 08:21 AM, Bauss wrote: Is there a way to get all functions within a module using traits? I tried "allMembers" and it seem to work, but I can't use "getFunctionAttributes" with it and if I use "getAttributes" then it won't find any applied attributes. What I do is having a package m

Re: Traits

2013-10-13 Thread Artur Skawina
On 10/13/13 02:25, luminousone wrote: > On Saturday, 12 October 2013 at 23:48:56 UTC, Artur Skawina wrote: >>template isBaseOf(BASE, C) { >> enum isBaseOf = { >> static if (is(C S == super)) >> foreach (A; S) >>static if (isBaseOf!(BASE, A)) >>

Re: Traits

2013-10-12 Thread luminousone
On Saturday, 12 October 2013 at 23:48:56 UTC, Artur Skawina wrote: On 10/12/13 21:42, luminousone wrote: On Saturday, 12 October 2013 at 11:50:05 UTC, Artur Skawina wrote: template isBaseOf(BASE, C) { enum isBaseOf = { static if (is(C S == super)) foreach (A; S)

Re: Traits

2013-10-12 Thread Artur Skawina
On 10/12/13 21:42, luminousone wrote: > On Saturday, 12 October 2013 at 11:50:05 UTC, Artur Skawina wrote: >>template isBaseOf(BASE, C) { >> enum isBaseOf = { >> static if (is(C S == super)) >> foreach (A; S) >>static if (is(A==BASE)) >>

Re: Traits

2013-10-12 Thread luminousone
On Saturday, 12 October 2013 at 11:50:05 UTC, Artur Skawina wrote: On 10/12/13 13:42, Artur Skawina wrote: template isBaseOf(BASE, C) { static if (is(C S == super)) enum isBaseOf = { foreach (A; S) static if (is(A==BASE)) return true

Re: Traits

2013-10-12 Thread Artur Skawina
On 10/12/13 13:42, Artur Skawina wrote: >template isBaseOf(BASE, C) { > static if (is(C S == super)) > enum isBaseOf = { > foreach (A; S) >static if (is(A==BASE)) > return true; > return is(C==BASE); > }(); >

Re: Traits

2013-10-12 Thread Artur Skawina
On 10/11/13 06:13, Agustin wrote: > I have a function that needs to check if the template provided inherit a > class. > > For example: > > public void function(T, A...)(auto ref A values) > { > // static assert(IsBaseOf(L, T)); > } > > Check if T inherit class "L". Same result that std::is_ba

Re: Traits

2013-10-12 Thread Jonathan M Davis
On Saturday, October 12, 2013 11:50:27 luminousone wrote: > On Saturday, 12 October 2013 at 08:40:42 UTC, Jonathan M Davis > > wrote: > > On Saturday, October 12, 2013 10:24:13 luminousone wrote: > >> 1. > >> > >> opCast, and alias can break the cast approach. You pointed this > >> out yourself.

Re: Traits

2013-10-12 Thread luminousone
On Saturday, 12 October 2013 at 08:40:42 UTC, Jonathan M Davis wrote: On Saturday, October 12, 2013 10:24:13 luminousone wrote: 1. opCast, and alias can break the cast approach. You pointed this out yourself. And as I pointed out, that's perfectly acceptable in most cases, because what you c

Re: Traits

2013-10-12 Thread Jonathan M Davis
On Saturday, October 12, 2013 10:24:13 luminousone wrote: > 1. > > opCast, and alias can break the cast approach. You pointed this > out yourself. And as I pointed out, that's perfectly acceptable in most cases, because what you care about is the conversion. alias this is specifically designed w

Re: Traits

2013-10-12 Thread luminousone
On Saturday, 12 October 2013 at 07:47:18 UTC, Jonathan M Davis wrote: On Saturday, October 12, 2013 09:32:09 luminousone wrote: And again, the casting solution is a bloody hack, it is loaded with corner cases that will break things if you are not aware of them. It also requires an allocated in

Re: Traits

2013-10-12 Thread Jonathan M Davis
On Saturday, October 12, 2013 09:32:09 luminousone wrote: > And again, the casting solution is a bloody hack, it is loaded > with corner cases that will break things if you are not aware of > them. It also requires an allocated instance of that object Of course, it requires an instance of the obje

Re: Traits

2013-10-12 Thread luminousone
On Saturday, 12 October 2013 at 05:38:16 UTC, Jonathan M Davis wrote: On Friday, October 11, 2013 22:31:25 Jonathan M Davis wrote: On Saturday, October 12, 2013 00:54:48 luminousone wrote: > The inability to handle null is pretty big, specially > considering > that at not point is the class in

Re: Traits

2013-10-11 Thread Jonathan M Davis
On Friday, October 11, 2013 22:31:25 Jonathan M Davis wrote: > On Saturday, October 12, 2013 00:54:48 luminousone wrote: > > The inability to handle null is pretty big, specially considering > > that at not point is the class instance itself cared about!, > > No. It's expected. When you are castin

Re: Traits

2013-10-11 Thread Jonathan M Davis
On Saturday, October 12, 2013 00:54:48 luminousone wrote: > The inability to handle null is pretty big, specially considering > that at not point is the class instance itself cared about!, No. It's expected. When you are casting to a particular object to test whether the object is of that type, y

Re: Traits

2013-10-11 Thread luminousone
On Friday, 11 October 2013 at 21:49:50 UTC, Jonathan M Davis wrote: On Friday, October 11, 2013 23:06:53 luminousone wrote: On Friday, 11 October 2013 at 19:54:39 UTC, Jonathan M Davis wrote: > On Friday, October 11, 2013 21:19:29 luminousone wrote: >> Using casts that way won't always be corre

Re: Traits

2013-10-11 Thread Jonathan M Davis
On Friday, October 11, 2013 23:06:53 luminousone wrote: > On Friday, 11 October 2013 at 19:54:39 UTC, Jonathan M Davis > > wrote: > > On Friday, October 11, 2013 21:19:29 luminousone wrote: > >> Using casts that way won't always be correct, it would be > >> better > >> to use reflection in some wa

Re: Traits

2013-10-11 Thread luminousone
On Friday, 11 October 2013 at 19:54:39 UTC, Jonathan M Davis wrote: On Friday, October 11, 2013 21:19:29 luminousone wrote: Using casts that way won't always be correct, it would be better to use reflection in some way if possible. The only reason that the casts wouldn't be correct would be i

Re: Traits

2013-10-11 Thread Agustin
On Friday, 11 October 2013 at 19:19:31 UTC, luminousone wrote: On Friday, 11 October 2013 at 14:09:09 UTC, Gary Willoughby wrote: On Friday, 11 October 2013 at 05:49:38 UTC, luminousone wrote: On Friday, 11 October 2013 at 04:13:55 UTC, Agustin wrote: I have a function that needs to check if th

Re: Traits

2013-10-11 Thread Jonathan M Davis
On Friday, October 11, 2013 21:19:29 luminousone wrote: > Using casts that way won't always be correct, it would be better > to use reflection in some way if possible. The only reason that the casts wouldn't be correct would be if the class overrode opCast for the type that you're casting to or h

Re: Traits

2013-10-11 Thread luminousone
On Friday, 11 October 2013 at 14:09:09 UTC, Gary Willoughby wrote: On Friday, 11 October 2013 at 05:49:38 UTC, luminousone wrote: On Friday, 11 October 2013 at 04:13:55 UTC, Agustin wrote: I have a function that needs to check if the template provided inherit a class. For example: public voi

Re: Traits

2013-10-11 Thread Jonathan M Davis
On Friday, October 11, 2013 15:34:28 Jacob Carlborg wrote: > On 2013-10-11 11:49, luminousone wrote: > > Is is just the typeid call that makes it unable to be ran at compile > > time or is their something else wrong in their?, > > > > Would a string compare with type.classInfo.name fix that, or is

Re: Traits

2013-10-11 Thread Agustin
On Friday, 11 October 2013 at 04:35:38 UTC, Ali Çehreli wrote: On 10/10/2013 09:13 PM, Agustin wrote: > I have a function that needs to check if the template provided inherit a > class. > > For example: > > public void function(T, A...)(auto ref A values) function happens to be a keyword. :) >

Re: Traits

2013-10-11 Thread Gary Willoughby
On Friday, 11 October 2013 at 05:49:38 UTC, luminousone wrote: On Friday, 11 October 2013 at 04:13:55 UTC, Agustin wrote: I have a function that needs to check if the template provided inherit a class. For example: public void function(T, A...)(auto ref A values) { // static assert(IsBaseOf(

Re: Traits

2013-10-11 Thread Jacob Carlborg
On 2013-10-11 11:49, luminousone wrote: Is is just the typeid call that makes it unable to be ran at compile time or is their something else wrong in their?, Would a string compare with type.classInfo.name fix that, or is their not a tool yet in place for that? Hmm, it may actually be possibl

Re: Traits

2013-10-11 Thread luminousone
On Friday, 11 October 2013 at 09:37:33 UTC, Jacob Carlborg wrote: On 2013-10-11 07:49, luminousone wrote: import std.traits; bool ChildInheritsFromParent( parent, child )( ) { foreach ( k, t; BaseClassesTuple!child ) { if( typeid(t) == typeid(parent) ) return true;

Re: Traits

2013-10-11 Thread Jacob Carlborg
On 2013-10-11 07:49, luminousone wrote: import std.traits; bool ChildInheritsFromParent( parent, child )( ) { foreach ( k, t; BaseClassesTuple!child ) { if( typeid(t) == typeid(parent) ) return true; } return false; } That will perform a runtime check and

Re: Traits

2013-10-10 Thread luminousone
On Friday, 11 October 2013 at 04:13:55 UTC, Agustin wrote: I have a function that needs to check if the template provided inherit a class. For example: public void function(T, A...)(auto ref A values) { // static assert(IsBaseOf(L, T)); } Check if T inherit class "L". Same result that std:

Re: Traits

2013-10-10 Thread Jonathan M Davis
On Thursday, October 10, 2013 21:35:37 Ali Çehreli wrote: > One of the uses of the is expression determines "whether implicitly > convertible to". It may work for you: > > public void foo(T, A...)(auto ref A values) > { > static assert(is (T : L)); > } Actually, checking for implicit convers

Re: Traits

2013-10-10 Thread Ali Çehreli
On 10/10/2013 09:13 PM, Agustin wrote: > I have a function that needs to check if the template provided inherit a > class. > > For example: > > public void function(T, A...)(auto ref A values) function happens to be a keyword. :) > { >// static assert(IsBaseOf(L, T)); > } > > Check if T inh

Re: Traits: getting all *public* members of a class?

2013-06-08 Thread Q
On Saturday, 8 June 2013 at 14:06:32 UTC, Andrej Mitrovic wrote: On Saturday, 8 June 2013 at 13:57:13 UTC, Q wrote: Hi there, I want to iterate over all the public members of a class. It is a known problem. The workaround is to use is(typeof()): void main() { foreach (mem; __traits(allMem

Re: Traits: getting all *public* members of a class?

2013-06-08 Thread Adam D. Ruppe
You could probably throw in a traits(compiles) right above. foreach(...) { // or maybe compiles, getProtection(getMember)) static if(__traits(compiles, __traits(getMember,Foo.init, mem)) { enum prot = __traits(getProtection, __traits(getMember, Foo.init, mem)); // and so on } } I haven't

Re: Traits: getting all *public* members of a class?

2013-06-08 Thread Andrej Mitrovic
On Saturday, 8 June 2013 at 13:57:13 UTC, Q wrote: Hi there, I want to iterate over all the public members of a class. It is a known problem. The workaround is to use is(typeof()): void main() { foreach (mem; __traits(allMembers, Foo)) { static if (is(typeof( __trai

Re: Traits and UDAs

2013-06-06 Thread Dicebot
On Thursday, 6 June 2013 at 17:50:08 UTC, Chris Williams wrote: ... It will work if use "enum" instead of "auto" for storing attribute tuple. If compile-time value is needed you almost always want to store it in enum.

Re: Traits and UDAs

2013-06-06 Thread Adam D. Ruppe
Here's how I do it: enum Dump; // just a type, no value here template Dumper(T) { void dump() { foreach (mem; __traits(allMembers, T)) { // loop over the attrs instead of try to store them in a var foreach(attr; __traits(getAttributes, __traits(getMember, T, mem)))

Re: traits allMembers and imported modules

2013-03-11 Thread Andrej Mitrovic
On 3/12/13, Andrej Mitrovic wrote: > On 3/12/13, cal wrote: >> if i remove the parenthesis around 'other'. > > Ah yes, I can recreate it now. Can you file this as a bug? > Ok I filed it: http://d.puremagic.com/issues/show_bug.cgi?id=9692

Re: traits allMembers and imported modules

2013-03-11 Thread cal
On Monday, 11 March 2013 at 23:38:20 UTC, Andrej Mitrovic wrote: On 3/12/13, cal wrote: if i remove the parenthesis around 'other'. Ah yes, I can recreate it now. Can you file this as a bug? Sure thanks for checking it

Re: traits allMembers and imported modules

2013-03-11 Thread Andrej Mitrovic
On 3/12/13, cal wrote: > if i remove the parenthesis around 'other'. Ah yes, I can recreate it now. Can you file this as a bug?

Re: traits allMembers and imported modules

2013-03-11 Thread cal
On Monday, 11 March 2013 at 23:22:42 UTC, cal wrote: On Monday, 11 March 2013 at 23:19:18 UTC, cal wrote: On Monday, 11 March 2013 at 23:10:58 UTC, Andrej Mitrovic I can't reproduce this. How are you compiling the modules? Specifically: dmd main.d other.d dir/other.d produces: Error: impor

Re: traits allMembers and imported modules

2013-03-11 Thread cal
On Monday, 11 March 2013 at 23:19:18 UTC, cal wrote: On Monday, 11 March 2013 at 23:10:58 UTC, Andrej Mitrovic wrote: On 3/11/13, cal wrote: When the module name I use inside __traits is in the same dir as the main module, I need the extra parenthesis to satisfy the compiler. Is this a bug, o

Re: traits allMembers and imported modules

2013-03-11 Thread cal
On Monday, 11 March 2013 at 23:10:58 UTC, Andrej Mitrovic wrote: On 3/11/13, cal wrote: When the module name I use inside __traits is in the same dir as the main module, I need the extra parenthesis to satisfy the compiler. Is this a bug, or unavoidable? I can't reproduce this. How are you c

Re: traits allMembers and imported modules

2013-03-11 Thread Andrej Mitrovic
On 3/11/13, cal wrote: > When the module name I use inside __traits is in the same dir as > the main module, I need the extra parenthesis to satisfy the > compiler. Is this a bug, or unavoidable? I can't reproduce this. How are you compiling the modules?

Re: traits and class protection

2011-05-03 Thread Lutger Blijdestijn
Adam D. Ruppe wrote: > Is there a way in today's D to exclude members marked private and > protected from processing in the __traits(allMembers) family of > functions? > > I thought if I at least put it in a separate module, trying to get > a private member would fail to compile, but I tried it

Re: traits: how to split parametrized type into basic type and parameters

2011-02-14 Thread Philippe Sigaud
On Mon, Feb 14, 2011 at 22:09, Martin Kinkelin wrote: > So from the outside, components are accessed either via indexing or > via x,y,z and w (analog to HLSL/GLSL). I also added some downcasting > shortcuts via properties, e.g.: > > auto f4 = float4(1,2,3,4); > auto r = f4.xyz + 2.0; // downcast

Re: traits: how to split parametrized type into basic type and parameters

2011-02-14 Thread Martin Kinkelin
> Did you try without the cast? Since we know that _data components can > be cast to r._data elements, the compiler should take care of that for > you. Nope, I didn't try that because, for instance, floats shouldn't be implicitly castable to ints. > You can also use cast(float2) f3 to get rid of

Re: traits: how to split parametrized type into basic type and parameters

2011-02-14 Thread Philippe Sigaud
On Mon, Feb 14, 2011 at 13:09, Martin Kinkelin wrote: > Hi Philippe, > > thank you very much! You're welcome. > I added your isVector!T template as well as the two aliases. > opCast!NewType is implemented like this: > > V opCast(V)() if (isVector!V) > // parameters {d2,T2} of V are checked when

Re: traits: how to split parametrized type into basic type and parameters

2011-02-14 Thread Martin Kinkelin
Hi Philippe, thank you very much! I added your isVector!T template as well as the two aliases. opCast!NewType is implemented like this: V opCast(V)() if (isVector!V) // parameters {d2,T2} of V are checked when instantiating V: d2 >= 1 && isNumeric!T2 { V r; foreach (i; 0 .. (d < V.dim ?

Re: traits: how to split parametrized type into basic type and parameters

2011-02-14 Thread Philippe Sigaud
Hi Martin, > I'm implementing a generic Vector!(uint d, T) struct (wrapping a T[d] array). > For readability: > alias Vector!(4u,float) float4; > alias Vector!(4u,int)   int4; > > I'd like to be able to cast a float4 variable explicitly to an int4 > (component-wise casting): > auto f4 = float4(1,2

Re: traits: how to split parametrized type into basic type and parameters

2011-02-13 Thread Martin Kinkelin
I realize a parametrized constructor would be a better option: this(T2)(const(Vector!(d,T2)) rhs) if (isNumeric!T2) { ... } // e.g., auto i4 = int4(f4); but I'd still prefer the casting syntax if possible.