Re: templates and traits

2023-03-18 Thread Chris Katko via Digitalmars-d-learn
On Saturday, 18 March 2023 at 20:42:50 UTC, Nick Treleaven wrote: On Saturday, 18 March 2023 at 19:22:07 UTC, Chris Katko wrote: ... So there's multiple sub-problems to solve. I asked this years ago, and got 90% of the way done and then lost the code and cannot find the original forum post.

Re: templates and traits

2023-03-18 Thread Nick Treleaven via Digitalmars-d-learn
On Saturday, 18 March 2023 at 19:22:07 UTC, Chris Katko wrote: ... So there's multiple sub-problems to solve. I asked this years ago, and got 90% of the way done and then lost the code and cannot find the original forum post. Maybe it was this?:

templates and traits

2023-03-18 Thread Chris Katko via Digitalmars-d-learn
Given: ```D struct pos {float x, y;} draw(myBitmap, pos(320, 240), centered); draw(pos(320, 240), myBitmap); draw("text", myFont, pos(320, 240)); ``` I'm writing a general "draw" template function that through compile-time, calls an associated DAllegro/Allegro 5 function: ``` draw(myBitmap,

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,

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.

Traits in a template enum

2021-10-10 Thread Some Guy via Digitalmars-d-learn
I have this enum to get the type of a member field in a struct: `enum typeOfMember(T, string member) = typeof(__traits(getMember, T, member));` I'm having problems when I try to used it though. For example: ```D writeln(typeOfMember!(T, member).stringof); // Doesn't work: Error: initializer

Re: Curious effect with traits, meta, and a foreach loop ... mystifies me.

2021-09-09 Thread james.p.leblanc via Digitalmars-d-learn
On Thursday, 9 September 2021 at 05:37:35 UTC, Tejas wrote: On Thursday, 9 September 2021 at 05:32:29 UTC, Tejas wrote: On Tuesday, 7 September 2021 at 17:47:15 UTC, james.p.leblanc wrote: [...] writeln([0]); scope(exit) AlignedMallocator.instance.deallocate(buffer); //... } ```

Re: Curious effect with traits, meta, and a foreach loop ... mystifies me.

2021-09-08 Thread Tejas via Digitalmars-d-learn
On Thursday, 9 September 2021 at 05:32:29 UTC, Tejas wrote: On Tuesday, 7 September 2021 at 17:47:15 UTC, james.p.leblanc wrote: [...] from what I understand you want to change the aligned data that you're referring to at runtime. ```d void main() { import

Re: Curious effect with traits, meta, and a foreach loop ... mystifies me.

2021-09-08 Thread Tejas via Digitalmars-d-learn
On Tuesday, 7 September 2021 at 17:47:15 UTC, james.p.leblanc wrote: On Tuesday, 7 September 2021 at 17:33:31 UTC, Adam D Ruppe wrote: On Tuesday, 7 September 2021 at 17:24:34 UTC, james.p.leblanc wrote: If you want to do a runtime lookup, you need to separate the two pieces. This pattern

Re: Curious effect with traits, meta, and a foreach loop ... mystifies me.

2021-09-08 Thread Bastiaan Veelo via Digitalmars-d-learn
On Tuesday, 7 September 2021 at 17:24:34 UTC, james.p.leblanc wrote: ```d /*…*/ // this is fine (notice that 'val' is never used foreach( i, val ; u.tupleof ){ ptr = u.tupleof[i].x.ptr; writeln("ptr: ", ptr); } // this fails with: "Error: variable 'i' cannot be read at

Re: Curious effect with traits, meta, and a foreach loop ... mystifies me.

2021-09-08 Thread Adam D Ruppe via Digitalmars-d-learn
On Tuesday, 7 September 2021 at 17:47:15 UTC, james.p.leblanc wrote: What I mean by "dig out" the needed "x" is: if I could alias/enum/ or someother trick be then able just to use that "x" as a simple static array. You might be able to just cast the struct to a static array of the same

Re: Curious effect with traits, meta, and a foreach loop ... mystifies me.

2021-09-07 Thread james.p.leblanc via Digitalmars-d-learn
On Tuesday, 7 September 2021 at 17:33:31 UTC, Adam D Ruppe wrote: On Tuesday, 7 September 2021 at 17:24:34 UTC, james.p.leblanc wrote: If you want to do a runtime lookup, you need to separate the two pieces. This pattern works: switch(runtime_index) { foreach(i, val; item.tupleof)

Re: Curious effect with traits, meta, and a foreach loop ... mystifies me.

2021-09-07 Thread Adam D Ruppe via Digitalmars-d-learn
On Tuesday, 7 September 2021 at 17:24:34 UTC, james.p.leblanc wrote: // this fails with: "Error: variable 'i' cannot be read at compile time // // foreach( i ; 0 .. 3 ){ //ptr = u.tupleof[i].x.ptr; tuples only exist at compile time, so you'd have to make sure the indexing is

Curious effect with traits, meta, and a foreach loop ... mystifies me.

2021-09-07 Thread james.p.leblanc via Digitalmars-d-learn
Dear All, In playing with some reflection and meta programming, this curiosity appeared. Does someone understand what is happening? I would appreciate learning about it if possible. Enclosed code snippet tells the story: ```d import std.stdio; import std.traits; import std.meta; struct

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,

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:

Traits of variadic templates

2021-02-09 Thread Jeff via Digitalmars-d-learn
Let's say I have... void foo(T...)(T xs) { foreach(x; xs) { if (typeid(x) == typeid(int)) writeln("int: ", x); else writeln("str: ", x); } } From the body, it's obvious I really only want int or string to be passed in to foo. Ideally, this

Re: Deprecation in traits

2020-09-30 Thread Ben Jones via Digitalmars-d-learn
On Wednesday, 30 September 2020 at 18:18:48 UTC, Basile B. wrote: On Tuesday, 29 September 2020 at 17:08:40 UTC, Frak wrote: Hi folks, I've this: /Users/frak/dlang/ldc-1.23.0/bin/../import/std/traits.d(3711): Deprecation: function `std.typecons.Nullable!long.Nullable.get_` is deprecated -

Re: Deprecation in traits

2020-09-30 Thread Basile B. via Digitalmars-d-learn
On Tuesday, 29 September 2020 at 17:08:40 UTC, Frak wrote: Hi folks, I've this: /Users/frak/dlang/ldc-1.23.0/bin/../import/std/traits.d(3711): Deprecation: function `std.typecons.Nullable!long.Nullable.get_` is deprecated - Implicit conversion with `alias Nullable.get this` will be removed

Re: Deprecation in traits

2020-09-30 Thread Frak via Digitalmars-d-learn
, you probably can't figure out the exact usage. What's more annoying is that likely it is a spurious warning. A lot of traits "try something", and then alias to false or true depending on what works. But it's not going to make a difference in your code. It's one of the most annoy

Re: Deprecation in traits

2020-09-30 Thread Stefan Koch via Digitalmars-d-learn
is that likely it is a spurious warning. A lot of traits "try something", and then alias to false or true depending on what works. But it's not going to make a difference in your code. It's one of the most annoying things in the library. If you see this warning coming from *your* code

Re: Deprecation in traits

2020-09-30 Thread Frak via Digitalmars-d-learn
usage. What's more annoying is that likely it is a spurious warning. A lot of traits "try something", and then alias to false or true depending on what works. But it's not going to make a difference in your code. It's one of the most annoying things in the library. If you see this warn

Re: Deprecation in traits

2020-09-29 Thread Ali Çehreli via Digitalmars-d-learn
On 9/29/20 10:08 AM, Frak wrote: Hi folks, I've this: /Users/frak/dlang/ldc-1.23.0/bin/../import/std/traits.d(3711): Deprecation: function `std.typecons.Nullable!long.Nullable.get_` is deprecated - Implicit conversion with `alias Nullable.get this` will be removed after 2.096. Please use

Re: Deprecation in traits

2020-09-29 Thread Steven Schveighoffer via Digitalmars-d-learn
of traits "try something", and then alias to false or true depending on what works. But it's not going to make a difference in your code. It's one of the most annoying things in the library. If you see this warning coming from *your* code, then you should fix it. But it will tell you th

Deprecation in traits

2020-09-29 Thread Frak via Digitalmars-d-learn
Hi folks, I've this: /Users/frak/dlang/ldc-1.23.0/bin/../import/std/traits.d(3711): Deprecation: function `std.typecons.Nullable!long.Nullable.get_` is deprecated - Implicit conversion with `alias Nullable.get this` will be removed after 2.096. Please use `.get` explicitly. I'm trying to

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

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,

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 :

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

Re: Issue with traits usability

2018-03-23 Thread Meta via Digitalmars-d-learn
On Wednesday, 21 March 2018 at 15:36:01 UTC, Márcio Martins wrote: Hi! How do I get past this? static struct X { int x; private enum T = 1; private alias M = string; } foreach (Member; __traits(allMembers, X)) { pragma(msg, __traits(getProtection, __traits(getMember,

Re: Issue with traits usability

2018-03-22 Thread Simen Kjærås via Digitalmars-d-learn
On Wednesday, 21 March 2018 at 15:36:01 UTC, Márcio Martins wrote: Hi! How do I get past this? static struct X { int x; private enum T = 1; private alias M = string; } foreach (Member; __traits(allMembers, X)) { pragma(msg, __traits(getProtection, __traits(getMember,

Issue with traits usability

2018-03-21 Thread Márcio Martins via Digitalmars-d-learn
Hi! How do I get past this? static struct X { int x; private enum T = 1; private alias M = string; } foreach (Member; __traits(allMembers, X)) { pragma(msg, __traits(getProtection, __traits(getMember, X, Member))); } Output: public private c.d(1084): Error:

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

Traits redux

2018-03-03 Thread JN via Digitalmars-d-learn
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 :(

Re: Using std traits

2018-01-25 Thread JN via Digitalmars-d-learn
On Thursday, 25 January 2018 at 19:49:05 UTC, JN wrote: if (!hasUDA!(member, "noserialize")) Nevermind, I get it now, member is only the field name, not a 'reference', changed it to: if (!hasUDA!(mixin(T.stringof ~ "." ~ member), "noserialize")) and works now

Re: Using std traits

2018-01-25 Thread Ali Çehreli via Digitalmars-d-learn
On 01/25/2018 11:49 AM, JN wrote:     foreach (i, member; FieldNameTuple!T)     {     if (!hasUDA!(member, "noserialize"))     {     writeln(member);     } 'member' is a string local variable, which does not have that UDA. You need to get the

Using std traits

2018-01-25 Thread JN via Digitalmars-d-learn
I decided it's time to learn how std traits work. I still find the whole compile time business a bit weird to deal with, so I decided to write a simple JSON serializer for struct that loops over member fields and outputs them. import std.stdio; import std.json; import std.traits; struct

Re: how do I read a class member's value using traits?

2017-12-16 Thread Marc via Digitalmars-d-learn
On Saturday, 16 December 2017 at 03:48:01 UTC, Jonathan M Davis wrote: On Saturday, December 16, 2017 03:34:43 Marc via Digitalmars-d-learn wrote: I need to give a class C, read all user-defined members of it, both name and value dynamically. for example: > [...] then >[...] I get this

Re: how do I read a class member's value using traits?

2017-12-15 Thread Jonathan M Davis via Digitalmars-d-learn
On Saturday, December 16, 2017 03:34:43 Marc via Digitalmars-d-learn wrote: > I need to give a class C, read all user-defined members of it, > > both name and value dynamically. for example: > > class C { > > > > string a; > > string b; > > string c; > > > > } > > then > > > Class c = new

how do I read a class member's value using traits?

2017-12-15 Thread Marc via Digitalmars-d-learn
I need to give a class C, read all user-defined members of it, both name and value dynamically. for example: class C { string a; string b; string c; } then Class c = new C(); // set c members... enum string[] members = [__traits(allMembers, C)]; foreach(string member; members) {

Re: How to implement `isTemplate` traits?

2017-10-04 Thread drug via Digitalmars-d-learn
04.10.2017 12:54, Biotronic пишет: template isTemplate(T...) if (T.length == 1) {     enum isTemplate = __traits(isTemplate, T[0]); } --   Biotronic Thank you!

Re: How to implement `isTemplate` traits?

2017-10-04 Thread Biotronic via Digitalmars-d-learn
, so it works, but I think it's dirty hack instead of dry and clean way... } } ``` May be phobos has such traits somewhere? template isTemplate(T...) if (T.length == 1) { enum isTemplate = __traits(isTemplate, T[0]); } -- Biotronic

How to implement `isTemplate` traits?

2017-10-04 Thread drug via Digitalmars-d-learn
dry and clean way... } } ``` May be phobos has such traits somewhere?

Re: Real beginner traits question

2017-09-25 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Sep 25, 2017 at 03:41:14PM +, WhatMeWorry via Digitalmars-d-learn wrote: > On Monday, 25 September 2017 at 06:07:58 UTC, H. S. Teoh wrote: > > On Mon, Sep 25, 2017 at 05:28:13AM +, WhatMeForget via > > Digitalmars-d-learn wrote: > > > [...] > > > > You're not the only one. I

Re: Real beginner traits question

2017-09-25 Thread WhatMeWorry via Digitalmars-d-learn
On Monday, 25 September 2017 at 06:07:58 UTC, H. S. Teoh wrote: On Mon, Sep 25, 2017 at 05:28:13AM +, WhatMeForget via Digitalmars-d-learn wrote: [...] You're not the only one. I stared at this same piece of documentation for a long time before I figured out what it meant. This is

Re: Real beginner traits question

2017-09-25 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, September 25, 2017 05:28:13 WhatMeForget via Digitalmars-d-learn wrote: > This is taken exactly from the traits documentation. > > ---- > > 25 Traits > > 25.21 identifier > > Takes one argument, a sym

Re: Real beginner traits question

2017-09-25 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Sep 25, 2017 at 05:28:13AM +, WhatMeForget via Digitalmars-d-learn wrote: > > This is taken exactly from the traits documentation. > > ---- > > 25 Traits > > 25.21 identifier > > Takes one argument, a

Re: Real beginner traits question

2017-09-24 Thread rikki cattermole via Digitalmars-d-learn
On 25/09/2017 6:28 AM, WhatMeForget wrote: This is taken exactly from the traits documentation. 25 Traits 25.21 identifier Takes one argument, a symbol. Returns the identifier for that symbol as a string literal

Real beginner traits question

2017-09-24 Thread WhatMeForget via Digitalmars-d-learn
This is taken exactly from the traits documentation. 25 Traits 25.21 identifier Takes one argument, a symbol. Returns the identifier for that symbol as a string literal

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

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:

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

traits for function having actual source declaration?

2017-09-01 Thread bitwise via Digitalmars-d-learn
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?

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 ---

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:

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

traits compiles does not work for symbols from other modules

2017-07-24 Thread Andre Pany via Digitalmars-d-learn
Hi, I want to validate whether a class contains a specific attribute. I have the attribute name as compile time string. This string could either be a direct attribute of the class or a hierarchy (TextSettings.Font.Size). As example T is the class Label and p.name contains the text

Re: Deprecation: foo.bar is not visible from module traits

2017-05-08 Thread Ali Çehreli via Digitalmars-d-learn
Known issue: https://issues.dlang.org/buglist.cgi?quicksearch=getSymbolsByUDA Ali

Deprecation: foo.bar is not visible from module traits

2017-05-07 Thread Anonymouse via Digitalmars-d-learn
I'm reworking my code to use UDAs, and I'm running into a wall of text of deprecation warnings when compiling. import std.traits; private: struct SomeUDA {} @SomeUDA void foo() {} @SomeUDA void bar() {} @SomeUDA void etc() {} public: void main() { mixin("static import thisModule = "

Re: how to define my own traits

2017-03-27 Thread Nicholas Wilson via Digitalmars-d-learn
On Monday, 27 March 2017 at 21:18:31 UTC, XavierAP wrote: When I first read about inout as a device to obviate code duplication typical in C++ const ref overloads, I liked it but I assumed it was implemented by lowering it into the actual duplicate overloads. Though I'm not even sure right now

Re: how to define my own traits

2017-03-27 Thread XavierAP via Digitalmars-d-learn
On Monday, 27 March 2017 at 16:28:13 UTC, Gary Willoughby wrote: Even Andrei was baffled: http://forum.dlang.org/thread/nepm2k$311l$1...@digitalmars.com I see... And Walter went further and reported it as a DMD bug (still open clearly). It's what I mean. This strange behavior is more

Re: how to define my own traits

2017-03-27 Thread Gary Willoughby via Digitalmars-d-learn
On Sunday, 26 March 2017 at 23:25:49 UTC, XavierAP wrote: I've looked into Phobos to emulate it when defining my own trait template, and when I see this: module std.range.primitives; // ... template isInputRange(R) { enum bool isInputRange = is(typeof( (inout int = 0) { R r

Re: how to define my own traits

2017-03-27 Thread XavierAP via Digitalmars-d-learn
On Monday, 27 March 2017 at 00:49:14 UTC, Moritz Maxeiner wrote: Have you tried it without the dummy parameter on the example given in the bug report [2]? I see, thanks for finding it! Looks a bit hacky but I can live with it. Indeed if I remove the argument from Phobos, Martin's example

Re: how to define my own traits

2017-03-26 Thread Moritz Maxeiner via Digitalmars-d-learn
On Sunday, 26 March 2017 at 23:25:49 UTC, XavierAP wrote: I've looked into Phobos to emulate it when defining my own trait template, and when I see this: module std.range.primitives; // ... template isInputRange(R) { enum bool isInputRange = is(typeof( (inout int = 0) { R r

how to define my own traits

2017-03-26 Thread XavierAP via Digitalmars-d-learn
I've looked into Phobos to emulate it when defining my own trait template, and when I see this: module std.range.primitives; // ... template isInputRange(R) { enum bool isInputRange = is(typeof( (inout int = 0) { R r = R.init; // can define a range object if

Re: simple static if / traits question...

2017-02-23 Thread Patrick Schluter via Digitalmars-d-learn
On Thursday, 23 February 2017 at 18:35:29 UTC, Profile Anaysis wrote: [...] option 1 is the one I was shooting for. does the static if (audio) just check for the existence of audio, or does it also check to see if audio is true as well? Yes, but it checks at compile time. So the code

Re: simple static if / traits question...

2017-02-23 Thread Profile Anaysis via Digitalmars-d-learn
There are a few options: 1. static if(audio) 2. version(audio) 3. if (audio) It looks like you are trying to create the version(audio) semantic(if exists then use, else don't). Ultimately, though, if you are trying to make a binary that can either use audio or not depending on where it is

Re: simple static if / traits question...

2017-02-22 Thread WhatMeForget via Digitalmars-d-learn
On Wednesday, 22 February 2017 at 22:37:25 UTC, Profile Anaysis wrote: On Wednesday, 22 February 2017 at 21:27:47 UTC, WhatMeWorry wrote: I'm doing conditional compilation using static ifs like so: enum bool audio = true; // if audio flag is present and set to true, add to code

Re: simple static if / traits question...

2017-02-22 Thread Profile Anaysis via Digitalmars-d-learn
On Wednesday, 22 February 2017 at 21:27:47 UTC, WhatMeWorry wrote: I'm doing conditional compilation using static ifs like so: enum bool audio = true; // if audio flag is present and set to true, add to code build static if ( (__traits(compiles, audio)) && audio)

Re: simple static if / traits question...

2017-02-22 Thread Era Scarecrow via Digitalmars-d-learn
On Wednesday, 22 February 2017 at 21:27:47 UTC, WhatMeWorry wrote: I'm doing conditional compilation using static ifs like so: enum bool audio = true; // if audio flag is present and set to true, add to code build static if ( (__traits(compiles, audio)) && audio)

simple static if / traits question...

2017-02-22 Thread WhatMeWorry via Digitalmars-d-learn
I'm doing conditional compilation using static ifs like so: enum bool audio = true; // if audio flag is present and set to true, add to code build static if ( (__traits(compiles, audio)) && audio) playSound(soundSys, BLEEP ); This works,

Re: Need help to compile code with traits

2017-02-05 Thread Xavier Bigand via Digitalmars-d-learn
and isType traits. And I am curious about of what is the Monitor. The whole thing you do to initialize could be replaced by a copy of the initializer, which is what emplace does: static T nogcNew(T, Args...)(Args args) @nogc { import core.stdc.stdlib : malloc; import std.traits, std.meta

Re: Need help to compile code with traits

2017-02-05 Thread Basile B. via Digitalmars-d-learn
Monitor is not an expression ..\src\core\nogc_memory.d(64): Error: template instance core.nogc_memory.__unittestL39_3.MyClass.NogcAllocator!(MyClass).nogcNew!(MyClass, int) error instantiating I don't understand my mistake with the getMember and isType traits. And I am curious about of what

Need help to compile code with traits

2017-02-05 Thread Xavier Bigand via Digitalmars-d-learn
\nogc_memory.d(64): Error: template instance core.nogc_memory.__unittestL39_3.MyClass.NogcAllocator!(MyClass).nogcNew!(MyClass, int) error instantiating I don't understand my mistake with the getMember and isType traits. And I am curious about of what is the Monitor.

Re: setting fields of object using traits

2016-09-21 Thread Jacob Carlborg via Digitalmars-d-learn
On 2016-09-20 21:45, Ram_B wrote: I'm trying to set fields of object from JSON with traits library. How i can to it properly? import std.stdio; import std.json; import std.traits; import std.meta: Alias; class Obj{ void fromJSON(this T)(JSONValue j){ foreach(field; FieldNameTuple

setting fields of object using traits

2016-09-20 Thread Ram_B via Digitalmars-d-learn
I'm trying to set fields of object from JSON with traits library. How i can to it properly? import std.stdio; import std.json; import std.traits; import std.meta: Alias; class Obj{ void fromJSON(this T)(JSONValue j){ foreach(field; FieldNameTuple!T

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

traits help

2016-09-18 Thread Bauss via Digitalmars-d-learn
I'm trying to retrieve all functions with a certain attribute. I know how to go about it and I can get it working with functions in the same module as the traits expression, but as soon as I nest modules in packages and import those packages then I don't get any functions. Is there a way

Re: Metaprogramming with traits

2016-09-16 Thread Ram_B via Digitalmars-d-learn
On Friday, 16 September 2016 at 08:01:18 UTC, Gary Willoughby wrote: On Thursday, 15 September 2016 at 22:05:55 UTC, Ram_B wrote: test.d(33): Error: variable f cannot be read at compile time test.d(33): Error: string expected as second argument of __traits hasMember instead of __error

Re: Metaprogramming with traits

2016-09-16 Thread Gary Willoughby via Digitalmars-d-learn
On Thursday, 15 September 2016 at 22:05:55 UTC, Ram_B wrote: test.d(33): Error: variable f cannot be read at compile time test.d(33): Error: string expected as second argument of __traits hasMember instead of __error test.d(46): Error: template instance test.A.t!(B) error instantiating Maybe

Re: Metaprogramming with traits

2016-09-15 Thread Ram_B via Digitalmars-d-learn
On Thursday, 15 September 2016 at 15:56:56 UTC, Gary Willoughby wrote: On Thursday, 15 September 2016 at 15:07:09 UTC, Ram_B wrote: How i can get fields of derived classes in runtime? This not works What about something like this: import std.traits; import std.stdio; class A { int

Re: Metaprogramming with traits

2016-09-15 Thread Ram_B via Digitalmars-d-learn
On Thursday, 15 September 2016 at 15:56:56 UTC, Gary Willoughby wrote: On Thursday, 15 September 2016 at 15:07:09 UTC, Ram_B wrote: How i can get fields of derived classes in runtime? This not works What about something like this: import std.traits; import std.stdio; class A { int

Re: Metaprogramming with traits

2016-09-15 Thread Gary Willoughby via Digitalmars-d-learn
On Thursday, 15 September 2016 at 15:07:09 UTC, Ram_B wrote: How i can get fields of derived classes in runtime? This not works What about something like this: import std.traits; import std.stdio; class A { int a,b; this(){} void fields(this T)(){

Re: Metaprogramming with traits

2016-09-15 Thread rikki cattermole via Digitalmars-d-learn
On 16/09/2016 3:07 AM, Ram_B wrote: How i can get fields of derived classes in runtime? This not works import std.traits; import std.experimental.logger; class A { int a,b; this(){} void fields(){ log(FieldNameTuple!this); } } class B : A{ int c; this(){} }

Metaprogramming with traits

2016-09-15 Thread Ram_B via Digitalmars-d-learn
How i can get fields of derived classes in runtime? This not works import std.traits; import std.experimental.logger; class A { int a,b; this(){} void fields(){ log(FieldNameTuple!this); } } class B : A{ int c; this(){} }

traits getMember gives a deprecation warning

2016-04-26 Thread Adil via Digitalmars-d-learn
I'm using DMD 2.071 and am getting this new deprecation error: source/screener/lib/syntax/semantics.d(42): Deprecation: screener.lib.virtualmachine.functions.object is not visible from module semantics source/screener/lib/syntax/semantics.d(42): Deprecation:

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

Re: Template specialization using traits?

2015-12-21 Thread Shriramana Sharma via Digitalmars-d-learn
Thanks all for your replies. One question: Jonathan M Davis wrote: > Alternatively, you can use static if, though you're only dealing > with one template in that case. e.g. But if we wanted to deprecate one of the alternatives, then we necessary need to declare two templates with the same name

Template specialization using traits?

2015-12-21 Thread Shriramana Sharma via Digitalmars-d-learn
Hello. I want to define a template specialization using traits: import std.stdio, std.traits; void func(T)(T t) { writeln(1); } void func(T)(T t) if(isIntegral!T) { writeln(2); } void main() { func(1); } But I'm getting an error saying that the called function matches both. If it were

Re: Template specialization using traits?

2015-12-21 Thread tcak via Digitalmars-d-learn
On Monday, 21 December 2015 at 11:12:10 UTC, Jonathan M Davis wrote: On Monday, 21 December 2015 at 11:07:16 UTC, Jonathan M Davis wrote: For your example to work with template constraints, the most straightforward solution would be void func(T)(T t) if(!isIntegral!T) { writeln(1); }

Re: Template specialization using traits?

2015-12-21 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, December 21, 2015 15:14:20 Shriramana Sharma via Digitalmars-d-learn wrote: > Hello. I want to define a template specialization using traits: > > import std.stdio, std.traits; > void func(T)(T t) { writeln(1); } > void func(T)(T t) if(isIntegral!T) { writeln(2)

Re: Template specialization using traits?

2015-12-21 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, 21 December 2015 at 11:07:16 UTC, Jonathan M Davis wrote: For your example to work with template constraints, the most straightforward solution would be void func(T)(T t) if(!isIntegral!T) { writeln(1); } void func(T)(T t) if(isIntegral!T) { writeln(2); }

Re: Template specialization using traits?

2015-12-21 Thread rumbu via Digitalmars-d-learn
On Monday, 21 December 2015 at 09:44:20 UTC, Shriramana Sharma wrote: Hello. I want to define a template specialization using traits: import std.stdio, std.traits; void func(T)(T t) { writeln(1); } void func(T)(T t) if(isIntegral!T) { writeln(2); } void main() { func(1); } But I'm getting

Re: Template specialization using traits?

2015-12-21 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, December 21, 2015 19:54:53 Shriramana Sharma via Digitalmars-d-learn wrote: > Thanks all for your replies. One question: > > Jonathan M Davis wrote: > > Alternatively, you can use static if, though you're only dealing > > with one template in that case. e.g. > > But if we wanted to

template this and traits getOverloads issue.

2015-11-20 Thread BBasile via Digitalmars-d-learn
is like in the stack overflow answer: statically check if the mixin methods are already there and remix the mixin in each descendant, so that the getOverloads traits works on the right 'this'. What do you think ? is it a bug ?

Re: template this and traits getOverloads issue.

2015-11-20 Thread Alex Parrill via Digitalmars-d-learn
Alternatively, you can use a static method and pass in the instance. Note that `new B` will print A's members twice, because A's constructor is always called and `__traits(allMembers, B)` includes A's members. --- import std.stdio; mixin template Bug() { import std.traits; static

  1   2   3   >