Re: Rebind template(bug?)

2016-08-22 Thread Engine Machine via Digitalmars-d-learn
On Monday, 22 August 2016 at 22:52:28 UTC, ag0aep6g wrote: On Monday, 22 August 2016 at 21:46:35 UTC, Engine Machine wrote: I'm sorry if it confuses you... it doesn't confuse me. You needed quite some help to get this thing to work. And you made some mistakes and wrong statements in the

Re: Rebind template(bug?)

2016-08-22 Thread Engine Machine via Digitalmars-d-learn
On Monday, 22 August 2016 at 19:09:34 UTC, Jack Applegame wrote: On Monday, 22 August 2016 at 18:04:43 UTC, Engine Machine wrote: How do you seriously think this is cleaner/simpler? 1. No extra encrypted things, such as InstantiateOrEmptySeq 2. Much more understandable. You have two classes.

Re: Rebind template(bug?)

2016-08-22 Thread Engine Machine via Digitalmars-d-learn
On Monday, 22 August 2016 at 18:48:12 UTC, ag0aep6g wrote: On 08/22/2016 08:04 PM, Engine Machine wrote: How do you seriously think this is cleaner/simpler? You have two classes. Their is no uniformity between them. You have uniformity between all the derived classes then have a special case

Re: Float values are wrong in union

2016-08-22 Thread Engine Machine via Digitalmars-d-learn
On Monday, 22 August 2016 at 05:02:41 UTC, jkpl wrote: On Monday, 22 August 2016 at 04:52:40 UTC, Cauterite wrote: [...] That's a 32 bit codegen issue then because DMD64 's disasm shows that SSE regs are used: void foo() { union test { int i; float f; } test t = { i :

Re: Rebind template(bug?)

2016-08-22 Thread Engine Machine via Digitalmars-d-learn
On Monday, 22 August 2016 at 07:54:36 UTC, Jack Applegame wrote: On Monday, 22 August 2016 at 00:43:00 UTC, Engine Machine wrote: The following code works and does what I want! template InstantiateOrEmptySeq(alias tmpl, args...) { alias Seq(T...)=T; static if (args.length > 0)

Re: Rebind template(bug?)

2016-08-21 Thread Engine Machine via Digitalmars-d-learn
On Monday, 22 August 2016 at 00:22:48 UTC, ag0aep6g wrote: On 08/22/2016 12:06 AM, Engine Machine wrote: T!()'s "data" is specified in the class just like all the other derivations. I don't want to have to specify an external base class as in your InstaniateOrBase. Why? Because!!! (There

Re: Rebind template(bug?)

2016-08-21 Thread Engine Machine via Digitalmars-d-learn
On Sunday, 21 August 2016 at 21:11:37 UTC, ag0aep6g wrote: On 08/21/2016 09:29 PM, Engine Machine wrote: I know you like to play the right or wrong game, but did you ever learn that a single example does not prove the truth of something? But you can show in a single example that something

Re: Rebind template(bug?)

2016-08-21 Thread Engine Machine via Digitalmars-d-learn
On Sunday, 21 August 2016 at 19:42:08 UTC, Lodovico Giaretta wrote: On Sunday, 21 August 2016 at 19:29:26 UTC, Engine Machine wrote: [...] The problem of this code has nothing to do with aliases. They work correctly. The problem is variable shadowing. In the following code, Child has two x

Re: Rebind template(bug?)

2016-08-21 Thread Engine Machine via Digitalmars-d-learn
On Sunday, 21 August 2016 at 06:28:25 UTC, Jack Applegame wrote: On Sunday, 21 August 2016 at 00:06:07 UTC, Engine Machine wrote: On Saturday, 20 August 2016 at 22:21:00 UTC, ag0aep6g wrote: On 08/21/2016 12:11 AM, Engine Machine wrote: Is there a way to rebind the arguments of a template?

Re: Rebind template

2016-08-20 Thread Engine Machine via Digitalmars-d-learn
On Saturday, 20 August 2016 at 22:21:00 UTC, ag0aep6g wrote: On 08/21/2016 12:11 AM, Engine Machine wrote: Is there a way to rebind the arguments of a template? template foo(X) { // X is like A!(a,b,c) Y = Rebind!(X,d,e,f); // Y is like A!(d,e,f); } foo(A!(a,b,c)); ? template

Re: Rebind template

2016-08-20 Thread Engine Machine via Digitalmars-d-learn
On Saturday, 20 August 2016 at 22:11:40 UTC, Engine Machine wrote: Is there a way to rebind the arguments of a template? template foo(X) { // X is like A!(a,b,c) Y = Rebind!(X,d,e,f); // Y is like A!(d,e,f); } foo(A!(a,b,c)); ? I'd also be happy if I could just remove the last

Rebind template

2016-08-20 Thread Engine Machine via Digitalmars-d-learn
Is there a way to rebind the arguments of a template? template foo(X) { // X is like A!(a,b,c) Y = Rebind!(X,d,e,f); // Y is like A!(d,e,f); } foo(A!(a,b,c)); ?

Re: CT Inheritence structures

2016-08-20 Thread Engine Machine via Digitalmars-d-learn
On Saturday, 20 August 2016 at 06:28:47 UTC, Enamex wrote: On Saturday, 20 August 2016 at 00:46:15 UTC, Engine Machine wrote: I am trying to get Timon Gehr's code working, with some modifications: void main() { import std.traits; auto a = new Type!("Animal", "Dog", "Pug")();

Re: CT Inheritence structures

2016-08-20 Thread Engine Machine via Digitalmars-d-learn
On Saturday, 20 August 2016 at 09:42:08 UTC, Jack Applegame wrote: On Saturday, 20 August 2016 at 00:46:15 UTC, Engine Machine wrote: Any ideas? Something like this? mixin template TypeData(string type: "Animal") { int y; } mixin template TypeData(string type: "Dog") { int z; } mixin

CT Inheritence structures

2016-08-19 Thread Engine Machine via Digitalmars-d-learn
I am trying to get Timon Gehr's code working, with some modifications: public template TypeParent(P) { import std.traits; alias T = TemplateArgsOf!P; alias Seq(T...) = T; static if (T.length == 0 || is(typeof(T[0]) == typeof(null))) {

Re: Static CT Factory

2016-08-18 Thread Engine Machine via Digitalmars-d-learn
On Friday, 19 August 2016 at 02:54:48 UTC, Basile B. wrote: On Friday, 19 August 2016 at 01:53:22 UTC, Engine Machine wrote: On Friday, 19 August 2016 at 01:25:10 UTC, Anonymouse wrote: On Friday, 19 August 2016 at 01:10:42 UTC, Engine Machine x = 1.234; Ok, well, I guess the error comes

Re: Static CT Factory

2016-08-18 Thread Engine Machine via Digitalmars-d-learn
On Friday, 19 August 2016 at 01:18:28 UTC, Adam D. Ruppe wrote: On Friday, 19 August 2016 at 01:10:42 UTC, Engine Machine wrote: I feel that in this case I feel that the scope of the static if should allow things to escape since, well, they are static if's. They do. What, exactly, did you

Re: Static CT Factory

2016-08-18 Thread Engine Machine via Digitalmars-d-learn
On Friday, 19 August 2016 at 01:25:10 UTC, Anonymouse wrote: On Friday, 19 August 2016 at 01:10:42 UTC, Engine Machine wrote: I have a template that is suppose to create a type based on a template parameter static if (T == "int") { auto x = New!int(); } else static if (T == "double") {

Static CT Factory

2016-08-18 Thread Engine Machine via Digitalmars-d-learn
I have a template that is suppose to create a type based on a template parameter static if (T == "int") { auto x = New!int(); } else static if (T == "double") { auto x = New!double(); } x = 1.234; This is just an example, I use custom types. The static if's prevent x's scope from

Virtual Classes?

2016-08-17 Thread Engine Machine via Digitalmars-d-learn
https://en.wikipedia.org/wiki/Virtual_class Can D do stuff like this naturally?

Re: Sequence separation

2016-08-17 Thread Engine Machine via Digitalmars-d-learn
On Wednesday, 17 August 2016 at 19:15:48 UTC, ag0aep6g wrote: On 08/17/2016 08:38 PM, Engine Machine wrote: [...] [...] [...] With MySequence being a type, you can do this: static if (is(x.args[2] == MySequence!Args, Args ...)) { ... } It works! Nifty that you can do that

Re: Sequence separation

2016-08-17 Thread Engine Machine via Digitalmars-d-learn
On Wednesday, 17 August 2016 at 19:21:57 UTC, Lodovico Giaretta wrote: On Wednesday, 17 August 2016 at 19:15:48 UTC, ag0aep6g wrote: [...] import std.traits: TemplateOf; static if (__traits(isSame, TemplateOf!(x.args[2]), MySequence)) { ... } std.traits.TemplateOf extracts the symbol

Re: Sequence separation

2016-08-17 Thread Engine Machine via Digitalmars-d-learn
On Wednesday, 17 August 2016 at 18:38:48 UTC, Engine Machine wrote: On Wednesday, 17 August 2016 at 08:37:32 UTC, Lodovico Giaretta wrote: On Tuesday, 16 August 2016 at 23:18:28 UTC, Adam D. Ruppe wrote: [...] You mean something like: struct MySequence(Args...) { enum length =

Re: Sequence separation

2016-08-17 Thread Engine Machine via Digitalmars-d-learn
On Wednesday, 17 August 2016 at 08:37:32 UTC, Lodovico Giaretta wrote: On Tuesday, 16 August 2016 at 23:18:28 UTC, Adam D. Ruppe wrote: On Tuesday, 16 August 2016 at 19:17:27 UTC, Engine Machine wrote: alias x = AliasSeq!(a, b, AliasSeq!(c, d)); results in a flat sequence. I would like to be

Re: Heterogeneous CT array like structure

2016-08-16 Thread Engine Machine via Digitalmars-d-learn
On Tuesday, 16 August 2016 at 15:56:18 UTC, Adam D. Ruppe wrote: On Tuesday, 16 August 2016 at 15:40:19 UTC, Engine Machine wrote: How can I actually store this data for runtime use that doesn't require the GC? The indexing set is fixed at compile time. Just create an ordinary struct...

Re: Template type reduction

2016-08-16 Thread Engine Machine via Digitalmars-d-learn
On Tuesday, 16 August 2016 at 17:39:14 UTC, Lodovico Giaretta wrote: On Monday, 15 August 2016 at 19:31:14 UTC, Engine Machine wrote: Suppose I have a templated type like struct S(T) { int x; static if (T is Y) int y; } I would like to be able to create a reference to S(T) for any T,

Sequence separation

2016-08-16 Thread Engine Machine via Digitalmars-d-learn
alias x = AliasSeq!(a, b, AliasSeq!(c, d)); results in a flat sequence. I would like to be able to keep them separate so I can have sub sequences. x.length == 4;

Heterogeneous CT array like structure

2016-08-16 Thread Engine Machine via Digitalmars-d-learn
struct Storage { // Getter static auto ref opDispatch(string name)() { } // Setter static auto ref opDispatch(string name, T)(T val) { } } auto y = Storage.Data; Storage.Data = "x"; Storage.Foo = 3; How can I actually store this data for runtime use that doesn't

Re: Template type reduction

2016-08-15 Thread Engine Machine via Digitalmars-d-learn
On Monday, 15 August 2016 at 19:40:37 UTC, Steven Schveighoffer wrote: On 8/15/16 3:31 PM, Engine Machine wrote: Suppose I have a templated type like struct S(T) { int x; static if (T is Y) int y; } I would like to be able to create a reference to S(T) for any T, struct Q { S!* s; // Can

Template type reduction

2016-08-15 Thread Engine Machine via Digitalmars-d-learn
Suppose I have a templated type like struct S(T) { int x; static if (T is Y) int y; } I would like to be able to create a reference to S(T) for any T, struct Q { S!* s; // Can hold any type of S. } and be able to access s.x, since it is common to all S. Can D do anything like this? It is

Re: Passing Structs to function like in C

2016-08-13 Thread Engine Machine via Digitalmars-d-learn
On Friday, 12 August 2016 at 17:53:12 UTC, ag0aep6g wrote: On 08/12/2016 07:33 PM, Cauterite wrote: Why would I not terminate a declaration with a semi-colon? Why should a declaration not end in a semi-colon just because the last token is a brace? Why should I not tell the lexer precisely

Re: if static member then call

2016-08-13 Thread Engine Machine via Digitalmars-d-learn
On Saturday, 13 August 2016 at 18:42:50 UTC, Cauterite wrote: On Saturday, 13 August 2016 at 18:34:43 UTC, Engine Machine wrote: static if (hasStaticMember!(T, "foo")) Here I suspect you're looking for this: __traits(isStaticFunction, __traits(getMember, T, "foo")) Thanks. It needs to

Re: Passing Structs to function like in C

2016-08-13 Thread Engine Machine via Digitalmars-d-learn
On Friday, 12 August 2016 at 18:23:55 UTC, Cauterite wrote: Thanks colon-nazis, I'll take that into consideration ¬_¬ Be careful! They will cauterize your testicles and rape your children! Those semi-clone, I mean semi-colon-nazis are the worse kind! It's a life and death matter! After all,

if static member then call

2016-08-13 Thread Engine Machine via Digitalmars-d-learn
auto ref foo(T, Args...)(args) { static if (hasStaticMember!(T, "foo")) return T.foo!(T)(args); } Basically I want to forward the *static* call to T if possible(if foo exists in T). The main problem is actually calling T.foo as the syntax here doesn't work. I also need to be able

Re: mixin bug?

2016-08-12 Thread Engine Machine via Digitalmars-d-learn
On Friday, 12 August 2016 at 23:48:54 UTC, sldkf wrote: On Friday, 12 August 2016 at 23:14:23 UTC, Engine Machine wrote: On Friday, 12 August 2016 at 15:35:50 UTC, sldkf wrote: On Friday, 12 August 2016 at 02:09:21 UTC, Engine Machine wrote: On Thursday, 11 August 2016 at 21:25:20 UTC, sldkf

Re: Template parameters that don't affect template type

2016-08-12 Thread Engine Machine via Digitalmars-d-learn
On Thursday, 11 August 2016 at 20:43:13 UTC, Meta wrote: On Thursday, 11 August 2016 at 18:11:30 UTC, Engine Machine wrote: [...] It can be done, but you have to be explicit and should think very carefully if this is really a good design. struct X(int defaultSize = 100) { int size;

Re: mixin bug?

2016-08-12 Thread Engine Machine via Digitalmars-d-learn
On Friday, 12 August 2016 at 15:35:50 UTC, sldkf wrote: On Friday, 12 August 2016 at 02:09:21 UTC, Engine Machine wrote: On Thursday, 11 August 2016 at 21:25:20 UTC, sldkf wrote: On Thursday, 11 August 2016 at 20:27:01 UTC, Engine Machine issue solved using a "template this parameter":

Re: mixin bug?

2016-08-11 Thread Engine Machine via Digitalmars-d-learn
On Thursday, 11 August 2016 at 21:25:20 UTC, sldkf wrote: On Thursday, 11 August 2016 at 20:27:01 UTC, Engine Machine wrote: This requires F2 to know the future. It also forces it to use a specific bar. I want inheritance like logic. You are goind to hit a wall. Template programming is not

Re: mixin bug?

2016-08-11 Thread Engine Machine via Digitalmars-d-learn
On Thursday, 11 August 2016 at 21:03:36 UTC, Ali Çehreli wrote: On 08/11/2016 01:27 PM, Engine Machine wrote: > I see the mixin as a sort of copy and paste. That's the case for string mixins. Template mixins bring a name resolution scope. My understanding of the topic:

Re: mixin bug?

2016-08-11 Thread Engine Machine via Digitalmars-d-learn
On Thursday, 11 August 2016 at 19:05:58 UTC, sldkf wrote: On Thursday, 11 August 2016 at 17:56:47 UTC, Engine Machine wrote: template F1(T) { void bar() { writeln("Bar0"); } } template F2(T) { mixin F1!T; void foo() { bar(); } } template F3(T) { mixin F2!T; void bar() {

Re: Template parameters that don't affect template type

2016-08-11 Thread Engine Machine via Digitalmars-d-learn
On Thursday, 11 August 2016 at 18:42:51 UTC, Steven Schveighoffer wrote: On 8/11/16 2:11 PM, Engine Machine wrote: I have the need, in some cases, to pass static information to a template class but don't want it to affect its type. import std.algorithm, core.stdc.stdlib; struct X(int

Re: Template parameters that don't affect template type

2016-08-11 Thread Engine Machine via Digitalmars-d-learn
Also, what if we use a class instead of a struct? in this case they are both references to the same thing. I see a problem with reflection though, as one could get the template parameter value and it would wrong on conversion. D takes the easy way out of just preventing complex and

Re: Template parameters that don't affect template type

2016-08-11 Thread Engine Machine via Digitalmars-d-learn
On Thursday, 11 August 2016 at 19:28:47 UTC, Lodovico Giaretta wrote: On Thursday, 11 August 2016 at 18:11:30 UTC, Engine Machine wrote: [...] If, in your case, it is possible to use one type as the other, then specify it. I mean, implement a templated opAssign that allows you to assign

Re: Template parameters that don't affect template type

2016-08-11 Thread Engine Machine via Digitalmars-d-learn
On Thursday, 11 August 2016 at 18:11:30 UTC, Engine Machine wrote: I have the need, in some cases, to pass static information to a template class but don't want it to affect its type. import std.algorithm, core.stdc.stdlib; struct X(int defaultSize = 100) { int Size; int* p; void

Template parameters that don't affect template type

2016-08-11 Thread Engine Machine via Digitalmars-d-learn
I have the need, in some cases, to pass static information to a template class but don't want it to affect its type. import std.algorithm, core.stdc.stdlib; struct X(int defaultSize = 100) { int Size; int* p; void foo(int size) { Size = max(size, defaultSize); p =

mixin bug?

2016-08-11 Thread Engine Machine via Digitalmars-d-learn
template F1(T) { void bar() { writeln("Bar0"); } } template F2(T) { mixin F1!T; void foo() { bar(); } } template F3(T) { mixin F2!T; void bar() { writeln("Bar1"); } // <- This bar should be used for F2's foo! } struct F4(T) { mixin F3!T; } (Or on can turn F3 in to a

How to add nogc to delegate

2016-08-10 Thread Engine Machine via Digitalmars-d-learn
void foo(@nogc void delegate()) doesn't work. But declaring an alias does, but too verbose. Surely we should be able to add the attribute directly?

I thought mixins didn't override?

2016-08-09 Thread Engine Machine via Digitalmars-d-learn
I try to use a mixin template and redefine some behaviors but D includes both and then I get ambiguity. I was sure I read somewhere that when one uses mixin template it won't include what is already there? mixin template X { void foo() { } } struct s { mixin template void foo() { }

Cannot distinguish between template function wtih 0 args and 1 arg

2016-08-07 Thread Engine Machine via Digitalmars-d-learn
This really makes no sense Error: template Mem cannot deduce function from argument types !(cast(eException)1280L, "main.d", 38u, "main.WinMain")(int), candidates are: Mem(T, B = eX, string file = __FILE__, uint line = __LINE__, string func = __FUNCTION__)(size_t bytes) Mem(T, B = eX, string

Re: callback craziness

2016-08-07 Thread Engine Machine via Digitalmars-d-learn
On Sunday, 7 August 2016 at 23:02:26 UTC, ag0aep6g wrote: On 08/08/2016 12:08 AM, Engine Machine wrote: On Sunday, 7 August 2016 at 20:48:29 UTC, ag0aep6g wrote: [...] Delegates don't necessarily need a GC allocation. They only need it when they need a closure. Delegates of methods don't need

Re: callback craziness

2016-08-07 Thread Engine Machine via Digitalmars-d-learn
On Sunday, 7 August 2016 at 20:48:29 UTC, ag0aep6g wrote: On 08/07/2016 10:01 PM, Engine Machine wrote: @nogc void foo(void delegate(int x) @nogc f); fails with the @nogc. Compiles just fine for me. 2nd, I cannot use a delegate because of the @nogc context, Delegates don't necessarily

callback craziness

2016-08-07 Thread Engine Machine via Digitalmars-d-learn
I use callbacks a lot and have trouble with D in a nogc context. First, I cannot declare the parameters with a nogc or I get a compile time error. @nogc void foo(void delegate(int x) @nogc f); fails with the @nogc. 2nd, I cannot use a delegate because of the @nogc context, @nogc void