Re: lambdas and function literals in classes

2013-07-09 Thread Timon Gehr
On 07/09/2013 02:32 PM, Artur Skawina wrote: IIRC this issue is already reported somewhere in bugzilla. http://d.puremagic.com/issues/show_bug.cgi?id=7653

Re: Stop to! rounding?

2013-07-03 Thread Timon Gehr
On 07/03/2013 07:21 AM, H. S. Teoh wrote: On Tue, Jul 02, 2013 at 10:14:33PM -0700, Ali Çehreli wrote: [...] import std.stdio; import std.conv; void main() { auto a = to!double(151.42499); writefln(%.60f, a); } I wouldn't write it like that; IMO it's better to write:

Re: How would you solve this 'interview' question in D?

2013-06-27 Thread Timon Gehr
On 06/26/2013 10:51 PM, Gary Willoughby wrote: Just for a bit of fun, I saw this question posted on reddit the other day and wondered how *you* would solve this in D? http://stackoverflow.com/questions/731832/interview-question-ffn-n int f(int x){ return x?(x1?x:-x)+(x0?1:-1):0; } unittest{

Re: How would you solve this 'interview' question in D?

2013-06-27 Thread Timon Gehr
On 06/27/2013 09:48 PM, John Colvin wrote: On Thursday, 27 June 2013 at 18:37:26 UTC, Timon Gehr wrote: On 06/26/2013 10:51 PM, Gary Willoughby wrote: Just for a bit of fun, I saw this question posted on reddit the other day and wondered how *you* would solve this in D? http

Re: alias c=mixin(expr); disallowed, why?

2013-06-22 Thread Timon Gehr
On 06/22/2013 09:52 PM, Timothee Cour wrote: Is there a reason the language spec disallows this? void main(){ auto a=mixin(1);//OK alias b=a;//OK mixin(alias c=a;);//OK // alias c=mixin(a);//NG : Error: basic type expected, not mixin } No, it is arbitrary.

Re: Can call static method with null reference

2013-06-22 Thread Timon Gehr
On 06/22/2013 10:20 PM, Jacob Carlborg wrote: On 2013-06-22 19:11, monarch_dodra wrote: I don't see what's so terrible about it: If A can do it, I don't see what an instance of a couldn't? The problem is that you cannot overload on static. That is, have a two methods with the same name, one

Re: alias c=mixin(expr); disallowed, why?

2013-06-22 Thread Timon Gehr
On 06/22/2013 11:51 PM, Timothee Cour wrote: On Sat, Jun 22, 2013 at 2:47 PM, Timon Gehr timon.g...@gmx.ch mailto:timon.g...@gmx.ch wrote: On 06/22/2013 09:52 PM, Timothee Cour wrote: Is there a reason the language spec disallows this? void main

Re: Why is this increasing memory consumption on every iteration?

2013-06-16 Thread Timon Gehr
On 06/16/2013 07:20 PM, Geancarlo Rocha wrote: On Sunday, 16 June 2013 at 02:12:02 UTC, Geancarlo Rocha wrote: I expected the memory to ramp up in the first couple iterations and eventually reach a stable point, but for some reason, windows task manager shows it increases on every iteration.

Re: Why is this increasing memory consumption on every iteration?

2013-06-16 Thread Timon Gehr
On 06/16/2013 08:37 PM, Geancarlo Rocha wrote: ... the current GC is unreliable, booo! No it is not. You are not even allocating GC-controlled memory during the loop. This is a std.container.BinaryHeap issue. It never shrinks the underlying container. http://d.puremagic.com/issues/ If

Re: UFCS for classes with opCall( ... )

2013-06-05 Thread Timon Gehr
On 06/05/2013 05:11 PM, ParticlePeter wrote: http://dpaste.dzfl.pl/79c29c19 (What you want to do does not work, but the issue is not that UFCS does not work with opCall. It does.) Thanks for the insights, undfortunatelly you're right. Is this behaviour on purpose, or considered a bug ?

Re: UFCS for classes with opCall( ... )

2013-06-03 Thread Timon Gehr
On 06/03/2013 06:25 PM, ParticlePeter wrote: UFCS is working with opCall already. The reason your code does not work is that UFCS only works with module-level symbols (and with the latest release also for locally imported symbols IIRC.) What do you mean with locally import symbols, isn't

Re: double vs real

2013-05-31 Thread Timon Gehr
On 05/30/2013 06:45 PM, bearophile wrote: ... If you have to store many reals, they require more memory than doubles (how much is relative to the operating system). Regarding speed in theory double and real should give the same, ... If double uses xmm registers and real uses the fpu registers

Re: double vs real

2013-05-31 Thread Timon Gehr
On 05/31/2013 09:08 PM, John Colvin wrote: On Friday, 31 May 2013 at 16:17:28 UTC, Ali Çehreli wrote: On 05/31/2013 04:28 AM, Shriramana Sharma wrote: On Fri, May 31, 2013 at 4:31 PM, Timon Gehr timon.g...@gmx.ch wrote: If double uses xmm registers and real uses the fpu registers

Re: double vs real

2013-05-31 Thread Timon Gehr
On 05/31/2013 01:28 PM, Shriramana Sharma wrote: On Fri, May 31, 2013 at 4:31 PM, Timon Gehr timon.g...@gmx.ch wrote: If double uses xmm registers and real uses the fpu registers (as is standard on x64), then double multiplication has twice the throughput of real multiplication on recent intel

Re: How do you guys debug large programs?

2013-05-28 Thread Timon Gehr
On 05/27/2013 09:55 PM, Gary Willoughby wrote: This is quite an open ended question but i wondered how you guys debug your D programs (i'm talking about stepping through code, setting breakpoints, etc). The lack of nice IDE's with integrated debuggers is worrying when working with D but up until

Re: Templated Function can't deduce function arguments

2013-05-23 Thread Timon Gehr
On 05/23/2013 07:21 PM, Jonathan Crapuchettes wrote: On Wed, 22 May 2013 23:28:21 -0400, Jonathan M Davis wrote: On Wednesday, May 22, 2013 21:31:53 Steven Schveighoffer wrote: On Wed, 22 May 2013 21:16:44 -0400, Jonathan Crapuchettes jcrapuchet...@gmail.com wrote: Can anyone tell me why

Re: static analysis: how to test code reachability at compile time

2013-05-22 Thread Timon Gehr
On 05/21/2013 11:31 PM, Diggory wrote: ... It would be very easy to introduce paradoxes This is the case already. if this were possible, simply use a static if to call something only if it is unreachable. I don't think this would be possible because function-local symbols are not

Re: Compiler bug ?

2013-05-18 Thread Timon Gehr
On 05/17/2013 07:19 PM, bearophile wrote: Jonathan M Davis: However, if it _never_ makes sense to declare a variable beginning with two underscores, I don't know why the compiler wouldn't forbid it other than the fact that it probably inserts such variables prior to when it would do the

Re: abstract class member functions can not have contracts

2013-05-15 Thread Timon Gehr
On 05/15/2013 04:16 PM, ref2401 wrote: Interface member functions can have in/out contracts but why abstract class member functions can not? abstract class Base { @property int field(); void foo() in { assert(field 0); } // Error: function main.Base.foo in and out contracts require

Re: how to instantiate explicitly template parameters in struct A(T1){this(T2)(){...}}

2013-05-13 Thread Timon Gehr
On 05/13/2013 10:27 PM, Timothee Cour wrote: While writing DIP40, I came upon the following question: how to instantiate explicitly template parameters for both the class/struct AND the constructor? for example: struct A(T1){this(T2)(){...}} ? (T2 could be used somehow inside the ctor body for

Re: how to instantiate explicitly template parameters in struct A(T1){this(T2)(){...}}

2013-05-13 Thread Timon Gehr
On 05/14/2013 01:25 AM, Timon Gehr wrote: On 05/13/2013 10:27 PM, Timothee Cour wrote: While writing DIP40, I came upon the following question: how to instantiate explicitly template parameters for both the class/struct AND the constructor? for example: struct A(T1){this(T2)(){...}} ? (T2

Re: Error in assignment to 'this' inside constructor

2013-05-12 Thread Timon Gehr
On 05/11/2013 04:34 PM, TommiT wrote: ... // CTFE internal error: unsupported assignment this = Test(123) ... An internal error is always a compiler bug.

Re: function overrides but is not covariant

2013-04-29 Thread Timon Gehr
On 04/28/2013 09:45 PM, Namespace wrote: That surprised me a bit. Is that expected? import std.stdio; struct A { } interface IFoo { void bar(ref const A); } class Foo : IFoo { void bar(ref const A a) { } void bar(const A a) { return this.bar(a); } }

Re: C to D conversion for function

2013-04-29 Thread Timon Gehr
On 04/29/2013 12:57 PM, Sumit Raja wrote: Hi, I wanted some help in converting this void av_log_ask_for_sample(void *avc, const char *msg, ...) av_printf_format(2, 3); from C to D. I don't know what it means or is called in C to start with so I am a bit lost on what to search for. Thanks

Re: C to D conversion for function

2013-04-29 Thread Timon Gehr
On 04/29/2013 02:17 PM, 1100110 wrote: ... What is the difference between const(char)*, and const(char*)? I have seen them used pretty much interchangeably... Are they? Somehow I don't think they are. Variables of type const(char)* can be mutated, while const(char*) cannot be. void main(){

Re: writeln, UFCS and flip

2013-04-26 Thread Timon Gehr
On 04/26/2013 10:15 PM, bearophile wrote: Tyro[17]: While flip2 does: flip2!foo(a, b, c) === foo(b, a, c) flip2!foo(a, b, c, d) === foo(b, a, c, d) and this rotate Really? Just swapping the first two arguments and leaving the others at their place is for a rotate? Why flip in the

Re: writeln, UFCS and flip

2013-04-25 Thread Timon Gehr
On 04/25/2013 05:09 PM, bearophile wrote: ... What do you think? ... I think what you call flip2 should be called flip.

Re: Internal error: ../ztc/cgcs.c

2013-04-24 Thread Timon Gehr
On 04/24/2013 10:25 PM, Namespace wrote: import std.stdio; int[2] getSize() { return [42, 23]; } int width() { return getSize()[0]; } void main() { writeln(Hello world!); } Compilation output: Internal error: ../ztc/cgcs.c 343 http://dpaste.1azy.net/a1897e84 I

Re: static enum member of incomplete type, valid or not?

2013-03-30 Thread Timon Gehr
On 03/27/2013 01:01 PM, TommiT wrote: I'd like to get a definite answer to whether the following code is valid or not: struct S { int v = 42; this(int val) { v = val + 1; } enum s = S(4); } void main() { static assert(S.s.v == 5); } Valid. There's a bug report about

Re: Using inout in delegate

2013-03-28 Thread Timon Gehr
On 03/28/2013 09:34 AM, Jacob Carlborg wrote: The following code fails to compile: void foo (inout int[] arr) { auto dg = { foreach (i, e ; arr) {} }; dg(); } void main () { auto a = [3, 4, 5]; foo(a); } Error message: main.d(9): Error: variable

Re: template cannot use local as parameter to non-global template

2013-03-17 Thread Timon Gehr
On 03/17/2013 01:54 PM, simendsjo wrote: I get a lot of these errors, and they can be quite tricky to get around and hurts my API.. Is this a temporary restriction in DMD, or is it another reason why this doesn't work? Error: template instance template!local cannot use local 'local' as

Re: template cannot use local as parameter to non-global template

2013-03-17 Thread Timon Gehr
On 03/17/2013 05:15 PM, simendsjo wrote: On Sunday, 17 March 2013 at 15:45:54 UTC, Timon Gehr wrote: On 03/17/2013 01:54 PM, simendsjo wrote: I get a lot of these errors, and they can be quite tricky to get around and hurts my API.. Is this a temporary restriction in DMD, or is it another

Re: Variadic function not recognizing static array length

2013-03-13 Thread Timon Gehr
On 03/12/2013 10:47 PM, Zach the Mystic wrote: void func(string[2] a) {} void func2(T...)(T args) { static assert(is(typeof(args[0]) == string[2])); } void func3(T...)(T args) { static assert(args[0].length == 2); } func([,]); // Okay func2([,]); // Error: (is(string[] ==

Re: Overhead when using a C library

2013-03-13 Thread Timon Gehr
On 03/14/2013 01:48 AM, Jeremy DeHaan wrote: Hey guys! I am working on a binding for D, and am almost finished! I started to think of some things I might like to work on to improve the binding after I get everything working, and one of the things I thought of was rewriting certain parts to use

Re: joiner and map, strange behavior

2013-03-12 Thread Timon Gehr
On 03/12/2013 06:51 PM, Stephan Schiffels wrote: ... Thanks, I had a brief look at std.algorithm.joiner but couldn't find anything obvious, maybe I should look deeper into it. ... I guess it is because of the following: Eg (similar code occurs two times): ... if (_sep.empty) {

Re: how to get top N distinct elements from range?

2013-03-09 Thread Timon Gehr
On 03/09/2013 10:35 AM, Andrea Fontana wrote: ... this works. Is this: bool[typeof(_fun((ElementType!Range).init))] mySet; the right way? It's ok, but the redundant parentheses around the element type are confusing.

Re: string.mixin;

2013-03-06 Thread Timon Gehr
On 03/06/2013 05:20 PM, Andre wrote: Am 06.03.2013 17:01, schrieb Andrej Mitrovic: On 3/6/13, Andre an...@s-e-a-p.de wrote: I wonder why UCFS is not working for the MIXIN statement? UFCS is a function feature, not a statement feature. And mixin is a statement, not a function. I suspected

Re: __traits(compiles) + mixin

2013-03-05 Thread Timon Gehr
On 03/05/2013 08:53 AM, cal wrote: I'm confused about this: import std.conv; void main() { enum s = `1`.to!int;; enum c = __traits(compiles, mixin({auto a = new ~s~;})); // line 1 mixin(auto a = ~s~;); // line 2 } This does not compile, giving errors about instantiating

Re: map! filter! and range algorithm

2013-03-04 Thread Timon Gehr
On 03/04/2013 09:06 PM, Andrea Fontana wrote: If I understand it correctly something like: range.filter!(...).map!(...) browse range 2 times, one for filter and one for mapping doesn't it? It does not. Is there a way to parallelize this kind of operations? Interleaving is the default.

Re: How does array assignment for different sized types work?

2013-01-31 Thread Timon Gehr
On 01/31/2013 05:48 AM, estew wrote: void main() { float[3] v1 = [1.0, 2.0, 3.0];// No error float[3] v = [1.0, 2.0, 3.0].dup; // Fails at runtime with error message } ... It fails at compile time? The reason is that array literals have special conversion rules: Eg: bool[] x

Re: enum function can't be passed into template?

2013-01-21 Thread Timon Gehr
On 01/20/2013 03:21 PM, Zhenya wrote: Hi! Am I doing something wrong? import std.stdio; template gun(alias f) { void gun() { f(); } } void main() { auto str = hello; enum fun = (){writeln(str);};//replace enum - auto to compile gun!fun(); }

Re: Phobos Members-Tuple function?

2013-01-19 Thread Timon Gehr
On 01/20/2013 03:41 AM, Ali Çehreli wrote: ... void main() { auto ship = new Ship; alias T = typeof(ship); foreach (m; __traits(allMembers, T)) { writefln(member %s, m); enum atrs = __traits(getAttributes, mixin(T.stringof ~ . ~ m)); This only works

Re: Phobos Members-Tuple function?

2013-01-19 Thread Timon Gehr
On 01/20/2013 04:55 AM, F i L wrote: Ali Çehreli wrote: The following program produces this output: [...code...] Awesome! Thanks, I wasn't expecting it to actually be as easy as that. I tried all sort of difference combinations with __traits(allMembers, ..) but it looks like I just needed to

Re: Mixin Template: cannot mixin scope(exit)?

2013-01-14 Thread Timon Gehr
On 01/14/2013 07:26 AM, 1100110 wrote: On 01/13/2013 11:35 PM, 1100110 wrote: Ok, I wish to create a standard timing system so that I can measure ~how long each function takes to execute. I wish to be able to place at the start of a function version(Time) mixin TimeExecution(funcName); mixin

Re: Address of return value.

2012-12-11 Thread Timon Gehr
On 12/11/2012 05:58 PM, monarch_dodra wrote: On Tuesday, 11 December 2012 at 16:45:54 UTC, cal wrote: On Tuesday, 11 December 2012 at 15:38:38 UTC, monarch_dodra wrote: On Tuesday, 11 December 2012 at 14:57:27 UTC, monarch_dodra wrote: :/ I got it to work with a cast, which removes the

Re: More templated type argument inference

2012-12-07 Thread Timon Gehr
On 12/06/2012 02:04 PM, bearophile wrote: Currently this code is not supported: void foo(T)(T x, T function(T) f) {} void main() { foo(1, (int a) = a * a); // OK foo(1, a = a * a); // Error } With the latest alpha compiler it gives: test.d(4): Error: template test.foo does

Re: More templated type argument inference

2012-12-07 Thread Timon Gehr
On 12/07/2012 11:12 PM, bearophile wrote: Timon Gehr: I consider it necessary. To consider opening an enhancement request, are you able to explain us why? It is just embarrassing if it does not work. Similar things work even in C#. Of course, it is harder in D because the type system

Re: get address of object if opCast is overridden

2012-12-01 Thread Timon Gehr
On 12/01/2012 06:23 PM, Jonathan M Davis wrote: On Saturday, December 01, 2012 12:05:49 Artur Skawina wrote: So, unless there's a way to do it without a cast, you're stuck. And I have no idea how you could possibly do it without a cast. *cast(void**)O // assuming O is a class Are you

Re: Compile And Run in emacs

2012-11-30 Thread Timon Gehr
On 12/01/2012 12:13 AM, Aytug wrote: So I have installed dmd, gdc, emacs and d-mode.el on my Debian machine. I can compile the program fine with M-compile. The problem starts after that. I cannot run the output file properly from within emacs. Either there is a way and I cannot find it, or

Re: sort associative array by key

2012-11-23 Thread Timon Gehr
On 11/23/2012 07:09 PM, dsmith wrote: What is the best way to have a function sort an associative array by key? The following yields a conversion error. double[string] aa_sort(double[string] aa) { return aa.keys.sort; } A hash table is unsorted by definition. What is it that you want to

Re: sort associative array by key

2012-11-23 Thread Timon Gehr
On 11/23/2012 07:48 PM, dsmith wrote: On Friday, 23 November 2012 at 18:24:07 UTC, Timon Gehr wrote: On 11/23/2012 07:09 PM, dsmith wrote: What is the best way to have a function sort an associative array by key? The following yields a conversion error. double[string] aa_sort(double[string

Re: CTFE Memory Hogging Workaround?

2012-11-22 Thread Timon Gehr
On 11/22/2012 11:33 PM, Maxime Chevalier wrote: One of the reasons I chose to use D for my project is that I was very excited about the prospect of using CTFE in mixin code. Unfortunately, there seems to be one (or several?) bugs causing CTFE to be very slow and to hog a huge amount of memory

Re: runtime static arrays

2012-11-21 Thread Timon Gehr
On 11/20/2012 11:56 PM, Jonathan M Davis wrote: ... clearly, as if with static arrays, you'd have to be careful with slices being passed around, since they're not owned by the GC. And I'm not sure what would happen if you were foolish enough to try and append to them. ... It works as expected.

Re: Array literal template parameter?

2012-11-20 Thread Timon Gehr
On 11/21/2012 12:22 AM, Maxime Chevalier wrote: I need to pass an array literal as a template parameter. The reference on this website seems to imply this is possible, but doesn't illustrate it. The obvious way doesn't seem to work: mixin template MyTemplate(int[] arr) {} Error:

Re: template error instantiating

2012-11-18 Thread Timon Gehr
On 11/18/2012 09:19 AM, Maxim Fomin wrote: On Saturday, 17 November 2012 at 23:28:21 UTC, Timon Gehr wrote: On 11/18/2012 12:14 AM, Manfred Nowak wrote: Maxim Fomin wrote: related to the issue? ... I can see that the definition is ambiguous. And if the coder didnt't realize

Re: template error instantiating

2012-11-17 Thread Timon Gehr
On 11/18/2012 12:14 AM, Manfred Nowak wrote: Maxim Fomin wrote: related to the issue? ... I can see that the definition is ambiguous. And if the coder didnt't realize the ambiguousness as you do ... -manfred The code given in the original post is valid D code.

Re: A refinement for pure implementation

2012-11-10 Thread Timon Gehr
On 11/10/2012 03:32 PM, bearophile wrote: Do you remember if Hara has implemented a patch to allow a2 to be immutable? int[] foo1(int x) pure { return null; } int[] foo2(string s) pure { return null; } void main() { immutable a1 = foo1(10); // OK immutable a2 = foo2(hello);

Re: Compilable Recursive Data Structure ( was: Recursive data structure using template won't compile)

2012-11-10 Thread Timon Gehr
On 11/10/2012 10:12 AM, Manfred Nowak wrote: Timon Gehr wrote: In theory yes, but [...] What a pity. Because in the code given only the types Elem!0 and Elem!1 must be indeed initialized. ... In this specific case, yes. But as this is an undecidable property in general, detecting

Re: Casting an array form an associative array

2012-11-10 Thread Timon Gehr
On 11/10/2012 01:20 PM, Jacob Carlborg wrote: The following example: void main() { void[][size_t] aa; aa[1] = [1, 2, 3]; if (auto a = 1 in aa) { writeln(*(cast(int[]*) a)); writeln(cast(int[]) *a); } } Will print: [1, 2, 3, 201359280, 0, 0, 0, 0, 0,

Re: A refinement for pure implementation

2012-11-10 Thread Timon Gehr
On 11/10/2012 05:21 PM, bearophile wrote: Timon Gehr: It is strongly pure regardless of potential aliasing in the return value. This is a bug. This can't be strongly pure: int[] foo2(int[] a) pure { a[0]++; return a; } Bye, bearophile The point was that the code you gave

Re: delegate bug?

2012-11-09 Thread Timon Gehr
On 11/09/2012 07:49 PM, Jack Applegame wrote: Because this is a learning group and not a teaching group--and you did not report on your fruitless tries: go on. -manfred This is not only std::function feature. In C++ we can call member-function by combining potinter to object and pointer to

Re: delegate bug?

2012-11-09 Thread Timon Gehr
On 11/09/2012 09:13 PM, Jack Applegame wrote: Ok. I will try to explain what exactly i need. ... The following works. You can also use a (scoped) delegate in order to allow the caller to close over his context. import std.stdio; class Figure { void draw(){} void erase(){} } class

Re: delegate bug?

2012-11-09 Thread Timon Gehr
On 11/09/2012 09:31 PM, Jack Applegame wrote: On Friday, 9 November 2012 at 20:22:40 UTC, Timon Gehr wrote: The following works. You can also use a (scoped) delegate in order to allow the caller to close over his context. Wow! Great! Thanks. But I can't understend this syntax: x=x.draw

Re: Compilable Recursive Data Structure ( was: Recursive data structure using template won't compile)

2012-11-09 Thread Timon Gehr
On 11/09/2012 02:17 PM, Manfred Nowak wrote: Rob T wrote: The above template definitions define exactly the same structure as the original No, they implement not _exactly_ the same structure, because they supply more freedom than the original templates version. The original version forced a

Re: Compilable Recursive Data Structure ( was: Recursive data structure using template won't compile)

2012-11-09 Thread Timon Gehr
On 11/09/2012 10:32 PM, Manfred Nowak wrote: Timon Gehr wrote: The example definitely exposes a bug in DMD. The D front end I am developing can already handle it. May I guess, that your front end is also able to handle this code: struct Elem( size_t myNumber) { Elem!( myNumber +1)* next

Re: Compilable Recursive Data Structure ( was: Recursive data structure using template won't compile)

2012-11-09 Thread Timon Gehr
On 11/09/2012 10:24 PM, Philippe Sigaud wrote: Timon: The D front end I am developing can already handle it. Developed in D, I suppose? Yes.

Re: why my tail implementation is much more slower than coreutil ?

2012-11-04 Thread Timon Gehr
How long does the hello world program take? I guess it is just that the D program has a slightly higher startup cost than the C program.

Re: __traits(compiles,...) = ? is(typeof(...))

2012-10-30 Thread Timon Gehr
On 10/30/2012 02:53 AM, Jonathan M Davis wrote: On Tuesday, October 30, 2012 02:22:42 Timon Gehr wrote: On 10/30/2012 01:43 AM, Jonathan M Davis wrote: On Tuesday, October 30, 2012 00:29:22 Timon Gehr wrote: On 10/30/2012 12:17 AM, Jonathan M Davis wrote: On Monday, October 29, 2012 23:38:34

Re: finding composed structs

2012-10-30 Thread Timon Gehr
On 10/30/2012 09:16 PM, Tobias Pankrath wrote: On Tuesday, 30 October 2012 at 19:16:18 UTC, Dan wrote: So until this bug is fixed any time I have any dynamic array, including string in struct S, implement opEquals. When the bug is fixed I can remove them. What I didn't realize is that including

Re: __traits(compiles,...) = ? is(typeof(...))

2012-10-29 Thread Timon Gehr
On 10/29/2012 12:03 PM, Jonathan M Davis wrote: On Monday, October 29, 2012 11:42:59 Zhenya wrote: Hi! Tell me please,in this code first and second static if,are these equivalent? with arg = 1, __traits(compiles,check(arg);) = true, is(typeof(check(arg))) = false. In principle,

Re: __traits(compiles,...) = ? is(typeof(...))

2012-10-29 Thread Timon Gehr
On 10/30/2012 12:17 AM, Jonathan M Davis wrote: On Monday, October 29, 2012 23:38:34 Timon Gehr wrote: On 10/29/2012 12:03 PM, Jonathan M Davis wrote: On Monday, October 29, 2012 11:42:59 Zhenya wrote: Hi! Tell me please,in this code first and second static if,are these equivalent? with arg

Re: __traits(compiles,...) = ? is(typeof(...))

2012-10-29 Thread Timon Gehr
On 10/30/2012 01:43 AM, Jonathan M Davis wrote: On Tuesday, October 30, 2012 00:29:22 Timon Gehr wrote: On 10/30/2012 12:17 AM, Jonathan M Davis wrote: On Monday, October 29, 2012 23:38:34 Timon Gehr wrote: On 10/29/2012 12:03 PM, Jonathan M Davis wrote: On Monday, October 29, 2012 11:42:59

Re: Narrow string is not a random access range

2012-10-24 Thread Timon Gehr
On 10/24/2012 12:45 PM, mist wrote: Actually it is awesome. But all the code breakage.. eh. Obviously T[] should support indexing for any T. This is the definition of an array.

Re: Narrow string is not a random access range

2012-10-24 Thread Timon Gehr
On 10/24/2012 01:07 PM, Jonathan M Davis wrote: On Wednesday, October 24, 2012 12:42:59 mist wrote: On Tuesday, 23 October 2012 at 17:36:53 UTC, Simen Kjaeraas wrote: On 2012-10-23, 19:21, mist wrote: Hm, and all phobos functions should operate on narrow strings as if they where not

Re: Narrow string is not a random access range

2012-10-23 Thread Timon Gehr
On 10/23/2012 05:58 PM, mist wrote: On Tuesday, 23 October 2012 at 15:55:23 UTC, Andrei Alexandrescu wrote: On 10/23/12 11:36 AM, mist wrote: Was thinking on this topic after seeing this: http://stackoverflow.com/questions/13014999/cannot-slice-taker-from-std-range-in-d Still can't

Re: Narrow string is not a random access range

2012-10-23 Thread Timon Gehr
On 10/24/2012 01:07 AM, Jonathan M Davis wrote: On Wednesday, October 24, 2012 00:28:28 Timon Gehr wrote: The other valid opinion is that the 'mistake' is in Phobos because it treats narrow character arrays specially. If it didn't, then range-based functions would be useless for strings

Re: opCast using in template struct

2012-10-18 Thread Timon Gehr
On 10/18/2012 11:45 PM, bearophile wrote: Era Scarecrow: It's an easy mistake to make. Maybe the compiler should issue a warning when opAssign attempts and fails and opOpBinary is defined. This would have to be implemented very carefully. There are enough hard to reproduce symbol

Re: opCast using in template struct

2012-10-18 Thread Timon Gehr
On 10/19/2012 01:05 AM, Era Scarecrow wrote: On Thursday, 18 October 2012 at 22:07:55 UTC, Timon Gehr wrote: On 10/18/2012 11:45 PM, bearophile wrote: There are other cases. Generally the D compiler should add some warnings that help against operator overloading mistakes. I don't think

Re: opCast using in template struct

2012-10-18 Thread Timon Gehr
On 10/19/2012 01:23 AM, bearophile wrote: Era Scarecrow: Maybe.. A general warning when something starts with 'op(Op)?[A-Z]' but doesn't actually qualify as any of the override-able operators? That seems sensible... Regarding operator overloading there are several situations worth warning

Re: opCast using in template struct

2012-10-18 Thread Timon Gehr
On 10/19/2012 02:12 AM, bearophile wrote: Timon Gehr: What situations? This thread has already shown two possible cases worth discussing about. This report shows two more cases: http://d.puremagic.com/issues/show_bug.cgi?id=8844 How is that bug-prone? Are there keyboards where

Re: Operator overloading through UFCS doesn't work

2012-10-17 Thread Timon Gehr
On 10/16/2012 05:57 PM, Maxim Fomin wrote: ... At NG discussion it may look nice to define some type and then add operator overloading methods Operator overloading is not magic, so your statement can be shortened to ... and then add methods Which is still not correct, because that is not

Re: Operator overloading through UFCS doesn't work

2012-10-17 Thread Timon Gehr
On 10/14/2012 09:14 AM, Maxim Fomin wrote: On Sunday, 14 October 2012 at 07:01:30 UTC, Tommi wrote: Actually, it seems that alias this has precedence over UFCS. So, a free function opUnary wouldn't ever suit better than an actual method opUnary of the thing referred to by that alias this.

Re: Operator overloading through UFCS doesn't work

2012-10-17 Thread Timon Gehr
On 10/14/2012 09:01 AM, Maxim Fomin wrote: On Saturday, 13 October 2012 at 19:50:02 UTC, Timon Gehr wrote: On 10/13/2012 06:02 PM, Maxim Fomin wrote: ... Different groups of people have different mind and same things produce different sense on them. From my point of view operator overloading

Re: Returning dynamic array from the function

2012-10-17 Thread Timon Gehr
On 10/17/2012 10:15 PM, sclytrack wrote: On Wednesday, 17 October 2012 at 19:46:51 UTC, bearophile wrote: sclytrack: It doesn't give an error when marking the function with safe. @safe int[] create() { } I think marking it @safe is not relevant. In theory a good type system should give an

Re: Operator overloading through UFCS doesn't work

2012-10-13 Thread Timon Gehr
On 10/13/2012 06:02 PM, Maxim Fomin wrote: ... Different groups of people have different mind and same things produce different sense on them. From my point of view operator overloading methods are special functions and not treating them as candidates for UFCS does make more sense. I do not

Re: Operator overloading through UFCS doesn't work

2012-10-13 Thread Timon Gehr
On 10/13/2012 10:15 PM, Jonathan M Davis wrote: ... construct is using syntactic sugar such as UFCS, because _all_ of that syntactic sugar must be lowered to code which _isn't_ syntactic sugar anymore. That is not what lowering means. It would be far more expensive to have to continually

Re: Operator overloading through UFCS doesn't work

2012-10-13 Thread Timon Gehr
On 10/14/2012 12:36 AM, H. S. Teoh wrote: On Sun, Oct 14, 2012 at 12:12:01AM +0200, Timon Gehr wrote: On 10/13/2012 10:15 PM, Jonathan M Davis wrote: [...] but they _aren't_ mixed and they will _never_ be mixed. If it had _ever_ been intended that it be possible to overload operators as free

Re: Calling un-overridden class method

2012-10-12 Thread Timon Gehr
On 10/13/2012 04:22 AM, H. S. Teoh wrote: ... // PROBLEM #1: due to PROBLEM #1, this causes an // infinite recursion that eventually overflows // the stack. ... I'm sure it does :). @topic: yes this is a bug.

Re: Using inout in delegates

2012-10-08 Thread Timon Gehr
On 10/05/2012 04:09 PM, Ali Çehreli wrote: ... This workaround makes the compiler happy: void foo (inout(int)[] arr) { auto a = (inout int) { auto b = arr[0]; }; } But probably not what you want. :/ IIRC, inout has bugs and incomplete implementation. I think this should be in the bug

Re: Function pointer variable not recognized as function by is-operator

2012-10-07 Thread Timon Gehr
On 10/07/2012 10:35 AM, Jonathan M Davis wrote: On Sunday, October 07, 2012 10:25:41 Tommi wrote: The following compiles, which I'm pretty sure must be a bug, right? Just checking to be sure I won't be polluting the bug tracker. void main() { auto f = (int i) {}; static assert

Re: Question about anonymous delegates.

2012-10-03 Thread Timon Gehr
On 10/03/2012 03:53 PM, Sharp wrote: I found something what I don't understand. Here is a simplifed code with comments: http://dpaste.dzfl.pl/a914d11a I creating anonymous delegates, whose function is to modify their parameter. Their parameters are different class references. I pass these

Re: Functional vs simple code

2012-10-02 Thread Timon Gehr
On 10/02/2012 10:48 PM, ixid wrote: Without optimization the range and algorithm method takes about 10 times as long as the simple code below it, with no array bounds checking and optimization it takes six times as long. Why is the difference so huge? I'd expect a moderate overhead but that's a

Re: Functional vs simple code

2012-10-02 Thread Timon Gehr
On 10/03/2012 12:11 AM, Timon Gehr wrote: ... $ cat ixidbench.d module main; import std.stdio, std.algorithm, std.range, std.datetime; enum MAX = 10_000_000_000UL; void main() { StopWatch sw; sw.start; auto sum1 = MAX.iota.map!(x = x * x).reduce!a + b; sw.stop

Re: Struct assignment, possible DMD bug?

2012-09-29 Thread Timon Gehr
On 09/29/2012 06:26 PM, Maxim Fomin wrote: On Saturday, 29 September 2012 at 16:05:03 UTC, ixid wrote: This behaviour seems inconsistent and unintuitive: void main() { int[3] a = [1,2,3]; a = [4, a[0], 6]; struct S { int a, b, c; } S s = S(1,2,3); s = S(4,

Re: template condition

2012-09-27 Thread Timon Gehr
On 09/27/2012 03:01 PM, Namespace wrote: Is there any difference between these two code snippets: #1: struct Foo(T : Object) { #2: struct Foo(T) if (is(T == class)) { ? I ask because I prefer option #1, but I see most often in Phobos variant #2. Yes there is: struct S{ Object o;

Re: Testing for template argument being result of takeExactly

2012-09-26 Thread Timon Gehr
On 09/25/2012 08:41 AM, monarch_dodra wrote: On Monday, 24 September 2012 at 22:13:51 UTC, Timon Gehr wrote: On 09/24/2012 09:41 AM, monarch_dodra wrote: [SNIP] I don't think this does what you think it does. The 'is(R r)' declares r to be an alias for R. So 'r' is a type in that code snippet

Re: Testing for template argument being result of takeExactly

2012-09-26 Thread Timon Gehr
On 09/26/2012 03:50 PM, monarch_dodra wrote: On Wednesday, 26 September 2012 at 13:19:13 UTC, Timon Gehr wrote: On 09/25/2012 08:41 AM, monarch_dodra wrote: On Monday, 24 September 2012 at 22:13:51 UTC, Timon Gehr wrote: On 09/24/2012 09:41 AM, monarch_dodra wrote: [SNIP] I don't think

Re: Testing for template argument being result of takeExactly

2012-09-26 Thread Timon Gehr
On 09/26/2012 05:08 PM, Andrei Alexandrescu wrote: On 9/26/12 9:50 AM, monarch_dodra wrote: struct S{}; is(typeof(takeExactly(S, 1)) == S) //false is(S == typeof(takeExactly(S, 1))) //Error: template std.range.takeExactly does not match any function template declaration Neither should work.

Re: Testing for template argument being result of takeExactly

2012-09-24 Thread Timon Gehr
On 09/24/2012 09:41 AM, monarch_dodra wrote: ... Regarding the .init issue, I hadn't thought of that, but it can be worked around pretty easily with an is(R r): template Hello(R) if ( is(R r) is(typeof(takeExactly(r, 1))) is(R == typeof(takeExactly(r,

Re: Testing for template argument being result of takeExactly

2012-09-23 Thread Timon Gehr
On 09/23/2012 01:54 AM, Jonathan M Davis wrote: I'm trying to test whether a template argument is the type returned by takeExactly, and I haven't been able to sort out the template voodoo required yet. It would be a lot easier if I had a variable to work with, but I just have the type, and the

<    1   2   3   4   5   6   7   8   9   >