Re: opDispatch and compile time parameters

2015-11-16 Thread Steven Schveighoffer via Digitalmars-d
On 11/14/15 12:18 AM, Jakob Ovrum wrote: On Saturday, 14 November 2015 at 04:10:59 UTC, Steven Schveighoffer wrote: Is it me, or is this a bug? struct Foo { template opDispatch(string s) { // if you uncomment this, it compiles //void opDispatch() {} void opDispatch(T...)()

Re: opDispatch and compile time parameters

2015-11-13 Thread Steven Schveighoffer via Digitalmars-d
On 10/18/15 9:00 PM, David Osborne wrote: On Saturday, 17 October 2015 at 15:31:00 UTC, Nikolay wrote: I asked on SO question about opDispatch and compile time parameters: http://stackoverflow.com/questions/32998781/opdispatch-and-compile-time-parameters [...] Is it good idea for opDispatch

Re: opDispatch and compile time parameters

2015-11-13 Thread Jakob Ovrum via Digitalmars-d
On Saturday, 14 November 2015 at 04:10:59 UTC, Steven Schveighoffer wrote: Is it me, or is this a bug? struct Foo { template opDispatch(string s) { // if you uncomment this, it compiles //void opDispatch() {} void opDispatch(T...)() {} } } void main() { Foo f;

Re: opDispatch and compile time parameters

2015-10-21 Thread Jonathan M Davis via Digitalmars-d
On Wednesday, 21 October 2015 at 12:32:37 UTC, Andrei Alexandrescu wrote: The quickest way to stop the bleeding is to disallow the code. It's incorrect for immutable data and misleading for mutable data. (What an user might expect is that each data comes with a distinct array.) It's

Re: opDispatch and compile time parameters

2015-10-21 Thread Timon Gehr via Digitalmars-d
On 10/21/2015 02:54 PM, Don wrote: Fundamentally the problem is that literals of mutable reference types do not make sense. I think considering "[x,y,z]" a 'literal' is a problem, but why is it the problem here? It is not really treated like a literal in this context. This has the same

Re: opDispatch and compile time parameters

2015-10-21 Thread Don via Digitalmars-d
On Wednesday, 21 October 2015 at 12:32:37 UTC, Andrei Alexandrescu wrote: On 10/21/2015 07:40 AM, Timon Gehr wrote: On 10/21/2015 12:55 PM, Andrei Alexandrescu wrote: On 10/19/15 9:49 PM, Jonathan M Davis wrote: On Monday, 19 October 2015 at 23:37:09 UTC, Timon Gehr wrote: This is the worst

Re: opDispatch and compile time parameters

2015-10-21 Thread Andrei Alexandrescu via Digitalmars-d
On 10/21/2015 07:40 AM, Timon Gehr wrote: On 10/21/2015 12:55 PM, Andrei Alexandrescu wrote: On 10/19/15 9:49 PM, Jonathan M Davis wrote: On Monday, 19 October 2015 at 23:37:09 UTC, Timon Gehr wrote: This is the worst part: class C{ int[] x=[1,2,3]; } void main(){ auto mut=new C;

Re: opDispatch and compile time parameters

2015-10-21 Thread Andrei Alexandrescu via Digitalmars-d
On 10/19/15 9:49 PM, Jonathan M Davis wrote: On Monday, 19 October 2015 at 23:37:09 UTC, Timon Gehr wrote: This is the worst part: class C{ int[] x=[1,2,3]; } void main(){ auto mut=new C; auto imm=new immutable(C); assert(imm.x[0]==1); mut.x[0]=2; assert(imm.x[0]==2);

Re: opDispatch and compile time parameters

2015-10-21 Thread Timon Gehr via Digitalmars-d
On 10/21/2015 12:55 PM, Andrei Alexandrescu wrote: On 10/19/15 9:49 PM, Jonathan M Davis wrote: On Monday, 19 October 2015 at 23:37:09 UTC, Timon Gehr wrote: This is the worst part: class C{ int[] x=[1,2,3]; } void main(){ auto mut=new C; auto imm=new immutable(C);

Re: opDispatch and compile time parameters

2015-10-20 Thread Marc Schütz via Digitalmars-d
On Tuesday, 20 October 2015 at 01:49:08 UTC, Jonathan M Davis wrote: On Monday, 19 October 2015 at 23:37:09 UTC, Timon Gehr wrote: This is the worst part: class C{ int[] x=[1,2,3]; } void main(){ auto mut=new C; auto imm=new immutable(C); assert(imm.x[0]==1); mut.x[0]=2;

Re: opDispatch and compile time parameters

2015-10-20 Thread Jonathan M Davis via Digitalmars-d
On Tuesday, 20 October 2015 at 11:36:36 UTC, Marc Schütz wrote: On Tuesday, 20 October 2015 at 01:49:08 UTC, Jonathan M Davis wrote: On Monday, 19 October 2015 at 23:37:09 UTC, Timon Gehr wrote: This is the worst part: class C{ int[] x=[1,2,3]; } void main(){ auto mut=new C; auto

Re: opDispatch and compile time parameters

2015-10-20 Thread Nikolay via Digitalmars-d
On Monday, 19 October 2015 at 18:16:15 UTC, Andrei Alexandrescu wrote: Tangentially related: since when we allow field initialization with new? I was surprised to see that this works: Thanks for this notice. I edited question on SO and I removed field initialization with new (replace

Re: opDispatch and compile time parameters

2015-10-19 Thread Jack Applegame via Digitalmars-d
D template system is very powerful. This is more generic solution: import std.stdio; class B { auto p1(T)(T arg) { writeln( "p1: ", arg ); } auto p2(T, int C)(T s) { writeln( "p2: ", s, " / ", C); } } class C(T) { T b = new T; template opDispatch(string s) { template

Re: opDispatch and compile time parameters

2015-10-19 Thread Adam D. Ruppe via Digitalmars-d
On Monday, 19 October 2015 at 19:53:14 UTC, Andrei Alexandrescu wrote: struct A { int[] x = new int[10]; } void main() { import std.stdio; A a; a.x[1] = 42; writeln(a.x); } Looks like a bona fide runtime array to me. It is still in the static data segment. Try this:

Re: opDispatch and compile time parameters

2015-10-19 Thread Andrei Alexandrescu via Digitalmars-d
On 10/19/2015 01:50 PM, Nikolay wrote: On Monday, 19 October 2015 at 08:41:46 UTC, Jack Applegame wrote: D template system is very powerful. This is more generic solution: http://dpaste.dzfl.pl/791c65d0e4ee Wow! I can't believe that it is possible and there is so straightforward way. You

Re: opDispatch and compile time parameters

2015-10-19 Thread Jonathan M Davis via Digitalmars-d
On Monday, 19 October 2015 at 18:26:45 UTC, Adam D. Ruppe wrote: On Monday, 19 October 2015 at 18:16:15 UTC, Andrei Alexandrescu wrote: Tangentially related: since when we allow field initialization with new? I was surprised to see that this works: Since CTFE started supporting it... this

Re: opDispatch and compile time parameters

2015-10-19 Thread Adam D. Ruppe via Digitalmars-d
On Monday, 19 October 2015 at 18:16:15 UTC, Andrei Alexandrescu wrote: Tangentially related: since when we allow field initialization with new? I was surprised to see that this works: Since CTFE started supporting it... this might actually be an unintentional feature. Since the initializer

Re: opDispatch and compile time parameters

2015-10-19 Thread Andrei Alexandrescu via Digitalmars-d
On 10/19/2015 02:26 PM, Adam D. Ruppe wrote: On Monday, 19 October 2015 at 18:16:15 UTC, Andrei Alexandrescu wrote: Tangentially related: since when we allow field initialization with new? I was surprised to see that this works: Since CTFE started supporting it... this might actually be an

Re: opDispatch and compile time parameters

2015-10-19 Thread Andrei Alexandrescu via Digitalmars-d
On 10/19/2015 02:44 PM, Jonathan M Davis wrote: On Monday, 19 October 2015 at 18:26:45 UTC, Adam D. Ruppe wrote: On Monday, 19 October 2015 at 18:16:15 UTC, Andrei Alexandrescu wrote: Tangentially related: since when we allow field initialization with new? I was surprised to see that this

Re: opDispatch and compile time parameters

2015-10-19 Thread Jack Applegame via Digitalmars-d
On Monday, 19 October 2015 at 17:50:02 UTC, Nikolay wrote: On Monday, 19 October 2015 at 08:41:46 UTC, Jack Applegame wrote: D template system is very powerful. This is more generic solution: http://dpaste.dzfl.pl/791c65d0e4ee Wow! I can't believe that it is possible and there is so

Re: opDispatch and compile time parameters

2015-10-19 Thread Nikolay via Digitalmars-d
On Monday, 19 October 2015 at 08:41:46 UTC, Jack Applegame wrote: D template system is very powerful. This is more generic solution: http://dpaste.dzfl.pl/791c65d0e4ee Wow! I can't believe that it is possible and there is so straightforward way. You should post this answer to SO Thanks!

Re: opDispatch and compile time parameters

2015-10-19 Thread Timon Gehr via Digitalmars-d
On 10/19/2015 09:57 PM, Adam D. Ruppe wrote: On Monday, 19 October 2015 at 19:53:14 UTC, Andrei Alexandrescu wrote: struct A { int[] x = new int[10]; } void main() { import std.stdio; A a; a.x[1] = 42; writeln(a.x); } Looks like a bona fide runtime array to me. It is

Re: opDispatch and compile time parameters

2015-10-19 Thread Jonathan M Davis via Digitalmars-d
On Monday, 19 October 2015 at 23:37:09 UTC, Timon Gehr wrote: This is the worst part: class C{ int[] x=[1,2,3]; } void main(){ auto mut=new C; auto imm=new immutable(C); assert(imm.x[0]==1); mut.x[0]=2; assert(imm.x[0]==2); } Oooo. Ouch. Yeah, that pushes it from

Re: opDispatch and compile time parameters

2015-10-18 Thread David Osborne via Digitalmars-d
On Saturday, 17 October 2015 at 15:31:00 UTC, Nikolay wrote: I asked on SO question about opDispatch and compile time parameters: http://stackoverflow.com/questions/32998781/opdispatch-and-compile-time-parameters [...] Is it good idea for opDispatch improvement or may there is some other

Re: opDispatch and compile time parameters

2015-10-17 Thread Meta via Digitalmars-d
On Saturday, 17 October 2015 at 15:31:00 UTC, Nikolay wrote: I asked on SO question about opDispatch and compile time parameters: http://stackoverflow.com/questions/32998781/opdispatch-and-compile-time-parameters Currently it looks like it is not possible to use opDispatch for non trivial

opDispatch and compile time parameters

2015-10-17 Thread Nikolay via Digitalmars-d
I asked on SO question about opDispatch and compile time parameters: http://stackoverflow.com/questions/32998781/opdispatch-and-compile-time-parameters Currently it looks like it is not possible to use opDispatch for non trivial template functions. I think opDispatch should get function name