Why is there no named parameter support?

2015-06-08 Thread Yuxuan Shui via Digitalmars-d-learn
Is there any reasons/difficulties for not implementing named parameters? There is clearly a need: http://forum.dlang.org/thread/wokfqqbexazcguffw...@forum.dlang.org#post-pxndhoskpjxvnoacajaz:40forum.dlang.org

Re: Erroneous auto can only be used for template function parameters?

2015-06-22 Thread Yuxuan Shui via Digitalmars-d-learn
On Monday, 22 June 2015 at 13:49:21 UTC, Steven Schveighoffer wrote: On 6/20/15 10:26 PM, Yuxuan Shui wrote: On Sunday, 21 June 2015 at 01:26:51 UTC, Adam D. Ruppe wrote: On Saturday, 20 June 2015 at 01:50:11 UTC, Yuxuan Shui wrote: auto ref R) is indeed a template function, so I don't

Re: Erroneous auto can only be used for template function parameters?

2015-06-22 Thread Yuxuan Shui via Digitalmars-d-learn
On Saturday, 20 June 2015 at 01:50:11 UTC, Yuxuan Shui wrote: Try to compile this code snippet: import std.traits; template a(R) { auto a(S)(auto ref R i) { return cast(S)i*2; } } template ReturnTypeEx(alias A, B) { alias ReturnTypeEx = ReturnType!(A!B);

Erroneous auto can only be used for template function parameters?

2015-06-19 Thread Yuxuan Shui via Digitalmars-d-learn
Try to compile this code snippet: import std.traits; template a(R) { auto a(S)(auto ref R i) { return cast(S)i*2; } } template ReturnTypeEx(alias A, B) { alias ReturnTypeEx = ReturnType!(A!B); } template b(alias R) { int b(S)(S i) {

Re: Erroneous auto can only be used for template function parameters?

2015-06-19 Thread Yuxuan Shui via Digitalmars-d-learn
On Saturday, 20 June 2015 at 01:50:11 UTC, Yuxuan Shui wrote: Try to compile this code snippet: import std.traits; template a(R) { auto a(S)(auto ref R i) { return cast(S)i*2; } } template ReturnTypeEx(alias A, B) { alias ReturnTypeEx = ReturnType!(A!B);

Re: Encapsulate return value in scoped

2015-06-18 Thread Yuxuan Shui via Digitalmars-d-learn
On Friday, 19 June 2015 at 00:00:50 UTC, Ali Çehreli wrote: On 06/18/2015 04:53 PM, Yuxuan Shui wrote: On Thursday, 11 June 2015 at 21:38:59 UTC, Ali Çehreli wrote: About returning scoped!C, I think it works: I just find out that the document of scoped says that It's Thanks for fixing the

Re: Erroneous auto can only be used for template function parameters?

2015-06-20 Thread Yuxuan Shui via Digitalmars-d-learn
On Sunday, 21 June 2015 at 01:26:51 UTC, Adam D. Ruppe wrote: On Saturday, 20 June 2015 at 01:50:11 UTC, Yuxuan Shui wrote: auto ref R) is indeed a template function, so I don't understand. But R is not a parameter on the function itself. It comes from the outside template. Move it to the

Re: Erroneous auto can only be used for template function parameters?

2015-06-20 Thread Yuxuan Shui via Digitalmars-d-learn
On Sunday, 21 June 2015 at 01:26:51 UTC, Adam D. Ruppe wrote: On Saturday, 20 June 2015 at 01:50:11 UTC, Yuxuan Shui wrote: auto ref R) is indeed a template function, so I don't understand. But R is not a parameter on the function itself. It comes from the outside template. Move it to the

Re: Encapsulate return value in scoped

2015-06-18 Thread Yuxuan Shui via Digitalmars-d-learn
On Thursday, 11 June 2015 at 21:38:59 UTC, Ali Çehreli wrote: On 06/11/2015 12:51 PM, Yuxuan Shui wrote: On Thursday, 11 June 2015 at 19:23:49 UTC, Ali Çehreli wrote: [...] Can you explain more about why the destructor is not called when returning a struct? Are you asking in general or

Encapsulate return value in scoped

2015-06-11 Thread Yuxuan Shui via Digitalmars-d-learn
Is there a way to encapsulate return value into scoped? Say I have a function that returns a new object: X new_x(T t...) { //Super complex input processing return new X(something); } And I want to encapsulate the result using scoped, is that possible? Can I just do: return

Re: Encapsulate return value in scoped

2015-06-11 Thread Yuxuan Shui via Digitalmars-d-learn
On Thursday, 11 June 2015 at 08:48:22 UTC, Yuxuan Shui wrote: Is there a way to encapsulate return value into scoped? Say I have a function that returns a new object: X new_x(T t...) { //Super complex input processing return new X(something); } And I want to encapsulate the result

Re: Encapsulate return value in scoped

2015-06-11 Thread Yuxuan Shui via Digitalmars-d-learn
On Thursday, 11 June 2015 at 09:11:47 UTC, Daniel Kozák wrote: On Thu, 11 Jun 2015 09:01:04 + Yuxuan Shui via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: A x = scoped!A(10); use auto x = scoped!A(10); Thanks! Curious question, why doesn't compiler reject

Re: Encapsulate return value in scoped

2015-06-11 Thread Yuxuan Shui via Digitalmars-d-learn
On Thursday, 11 June 2015 at 17:34:56 UTC, Steven Schveighoffer wrote: On 6/11/15 1:28 PM, Yuxuan Shui wrote: On Thursday, 11 June 2015 at 09:11:47 UTC, Daniel Kozák wrote: On Thu, 11 Jun 2015 09:01:04 + Yuxuan Shui via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote

Re: Encapsulate return value in scoped

2015-06-11 Thread Yuxuan Shui via Digitalmars-d-learn
Jun 2015 09:01:04 + Yuxuan Shui via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: A x = scoped!A(10); use auto x = scoped!A(10); Thanks! Curious question, why doesn't compiler reject this code? Because scoped!A implicitly casts to A. -Steve Thanks! I just found

Re: dmd and string imports on Windows

2015-06-10 Thread Yuxuan Shui via Digitalmars-d-learn
On Wednesday, 10 June 2015 at 19:59:17 UTC, Atila Neves wrote: On Linux: foo.d: import std.stdio; void main() { writeln(import(dir/bar.txt)); } dmd -J. foo.d # ok On Windows: Error: file dir/bar.txt cannot be found or not in a path specified with -J I tried the obvious buildPath(dir,

What is the exact meaning of 'nothrow'?

2015-06-10 Thread Yuxuan Shui via Digitalmars-d-learn
I want to know exactly what is considered to be 'throw'. I'm able to use dynamic arrays (which can throw 'Range violation') and asserts in a nothrow function. Shouldn't those be considered 'throw'?

Extract template parameter at runtime?

2015-06-15 Thread Yuxuan Shui via Digitalmars-d-learn
I have a template class which is derived from a base class. Is it possible to extract the template parameter from a reference to the base class? Can is() operate on TypeInfo?

Re: What is the exact meaning of 'nothrow'?

2015-06-10 Thread Yuxuan Shui via Digitalmars-d-learn
On Thursday, 11 June 2015 at 00:27:36 UTC, Ali Çehreli wrote: On 06/10/2015 05:06 PM, Yuxuan Shui wrote: I want to know exactly what is considered to be 'throw'. I'm able to use dynamic arrays (which can throw 'Range violation') and asserts in a nothrow function. Shouldn't those be considered

Re: Extract template parameter at runtime?

2015-06-15 Thread Yuxuan Shui via Digitalmars-d-learn
On Monday, 15 June 2015 at 18:30:55 UTC, Steven Schveighoffer wrote: On 6/15/15 2:10 PM, Yuxuan Shui wrote: I have a template class which is derived from a base class. Is it possible to extract the template parameter from a reference to the base class? No. You can't get compile-time

Re: Extract template parameter at runtime?

2015-06-15 Thread Yuxuan Shui via Digitalmars-d-learn
On Monday, 15 June 2015 at 22:56:57 UTC, Yuxuan Shui wrote: On Monday, 15 June 2015 at 18:30:55 UTC, Steven Schveighoffer wrote: [...] Well I don't have a serious use case of this. I just started using D couple of weeks ago, and is now experimenting with it by writing a toy compiler. What

Process a TypeTuple

2015-06-14 Thread Yuxuan Shui via Digitalmars-d-learn
Is it possible to apply some operation on every member of a TypeTuple, then get the result back? Say I have a TypeTuple of array types, and I want a TypeTuple of their element types, how could I do that?

Re: Mutable reference to const objects

2015-07-01 Thread Yuxuan Shui via Digitalmars-d-learn
On Wednesday, 1 July 2015 at 08:30:23 UTC, Yuxuan Shui wrote: How do I express a mutable reference to a const object in D? What I want to do is to define a variable, which refers a constant object, but I can change which constant object it is referring. Is this possible? I wonder will

Mutable reference to const objects

2015-07-01 Thread Yuxuan Shui via Digitalmars-d-learn
How do I express a mutable reference to a const object in D? What I want to do is to define a variable, which refers a constant object, but I can change which constant object it is referring. Is this possible?

Re: More threads - Slower program ??

2015-08-12 Thread Yuxuan Shui via Digitalmars-d-learn
On Wednesday, 12 August 2015 at 23:15:48 UTC, Adam D. Ruppe wrote: On Wednesday, 12 August 2015 at 23:06:32 UTC, Yuxuan Shui wrote: What is wrong here? I didn't look too closely, but there's some memory allocations going on there which have the potential of locking all the threads any time

More threads - Slower program ??

2015-08-12 Thread Yuxuan Shui via Digitalmars-d-learn
Here is a small program (https://gist.github.com/yshui/a426f73be77d1d699555) that uses taskPool to parallely reading from /proc/pid/ and sum the swap usage. Individual tasks has zero dependency between each other, but when I remove the 'defaultPoolThreads(1)' line, the programs takes 8x

How to make a standalone .a using dub?

2015-07-29 Thread Yuxuan Shui via Digitalmars-d-learn
Is there a way to have dub pack the library along with all its dependencies into a single .a?

Re: How to make a standalone .a using dub?

2015-07-29 Thread Yuxuan Shui via Digitalmars-d-learn
On Thursday, 30 July 2015 at 00:14:23 UTC, Yuxuan Shui wrote: Is there a way to have dub pack the library along with all its dependencies into a single .a? And if not, is there any D build system capable of doing this? reggae maybe?

Re: Delayed const variable initialization

2015-07-13 Thread Yuxuan Shui via Digitalmars-d-learn
On Monday, 13 July 2015 at 09:05:25 UTC, ketmar wrote: On Mon, 13 Jul 2015 08:56:05 +, Yuxuan Shui wrote: On Monday, 13 July 2015 at 07:43:16 UTC, Marc Schütz wrote: On Monday, 13 July 2015 at 07:11:33 UTC, Yuxuan Shui wrote: [...] const(A) = condition ? func1() : func2(); Well I

Re: Delayed const variable initialization

2015-07-13 Thread Yuxuan Shui via Digitalmars-d-learn
On Monday, 13 July 2015 at 08:55:00 UTC, ketmar wrote: On Mon, 13 Jul 2015 07:11:32 +, Yuxuan Shui wrote: How can I do something like this? const(A) x; if (condition) { x = func1(); } else { x = func2(); } This is a valid use case, and to make this work I'll have to use

Re: Delayed const variable initialization

2015-07-13 Thread Yuxuan Shui via Digitalmars-d-learn
On Monday, 13 July 2015 at 07:43:16 UTC, Marc Schütz wrote: On Monday, 13 July 2015 at 07:11:33 UTC, Yuxuan Shui wrote: How can I do something like this? const(A) x; if (condition) { x = func1(); } else { x = func2(); } This is a valid use case, and to make this work I'll have to use

Re: Template function that accept strings and array of strings

2015-07-15 Thread Yuxuan Shui via Digitalmars-d-learn
On Wednesday, 15 July 2015 at 21:57:50 UTC, badlink wrote: Hello, I can't figure how to write a template function that accept either strings or array of strings. This is my current code: bool hasItemParent(T)(const(char)[] itemId, const(T)[] parentId) if (is(typeof(T) == char) || (isArray!T

Re: Delayed const variable initialization

2015-07-13 Thread Yuxuan Shui via Digitalmars-d-learn
On Monday, 13 July 2015 at 17:18:53 UTC, Jesse Phillips wrote: On Monday, 13 July 2015 at 14:41:36 UTC, Steven Schveighoffer wrote: You can also do a temporary lambda that you call immediately, but I'm not 100% sure of the syntax. Someone will chime in with the answer :) -Steve Syntax is

Delayed const variable initialization

2015-07-13 Thread Yuxuan Shui via Digitalmars-d-learn
How can I do something like this? const(A) x; if (condition) { x = func1(); } else { x = func2(); } This is a valid use case, and to make this work I'll have to use Rebindable, which is really inconvenient.

Can't chain reduce(seed, range)

2015-08-30 Thread Yuxuan Shui via Digitalmars-d-learn
Why is reduce defined as 'auto reduce(S, R)(S seed, R r)', instead of reduce(R r, S seed)? I can't chain it. Maybe provide both?

Re: Modify Function Pointer to Take Additional Parameters

2016-02-19 Thread Yuxuan Shui via Digitalmars-d-learn
On Friday, 19 February 2016 at 20:45:23 UTC, jmh530 wrote: On Friday, 19 February 2016 at 15:00:51 UTC, jmh530 wrote: This works. But when I re-write foo to take that into account as in below, I get an error that I can't implicitly convert int function(int x) to int function(int x, int y).

Re: Struct Inheritence

2016-02-19 Thread Yuxuan Shui via Digitalmars-d-learn
On Friday, 19 February 2016 at 21:58:24 UTC, user001 wrote: Well struct don't have it, but i would like something like it but only for data, i don't need functions or anything like that just data. [...] How about struct A { int valueA; } struct B { A a; int valueB; alias a

Re: Is it safe to use 'is' to compare types?

2016-03-10 Thread Yuxuan Shui via Digitalmars-d-learn
On Thursday, 10 March 2016 at 02:14:19 UTC, H. S. Teoh wrote: On Thu, Mar 10, 2016 at 01:33:41AM +, Yuxuan Shui via Digitalmars-d-learn wrote: [...] You can't rely on invoking the compiler to link these objects, because if you're using shared libraries, it will be the OS's dynamic

Re: Is it safe to use 'is' to compare types?

2016-03-09 Thread Yuxuan Shui via Digitalmars-d-learn
On Tuesday, 8 March 2016 at 23:13:32 UTC, Anon wrote: On Tuesday, 8 March 2016 at 20:26:04 UTC, Yuxuan Shui wrote: [...] [Note: I phrase my answer in terms of Linux shared libraries (*.so) because D doesn't actually have proper Windows DLL support yet. The same would apply to DLLs, it just

Re: Is it safe to use 'is' to compare types?

2016-03-09 Thread Yuxuan Shui via Digitalmars-d-learn
On Wednesday, 9 March 2016 at 22:26:38 UTC, Ali Çehreli wrote: On 03/09/2016 07:05 AM, Yuxuan Shui wrote: > Can we left TypeInfo symbol undefined in the shared libraries? i.e. D > compiler will strip out TypeInfo definition when creating .so. > (Alternatively, we can have TypeInfo always

Problem using shared D library from C shared library

2016-04-06 Thread Yuxuan Shui via Digitalmars-d-learn
I have a D shared library which is loaded by a C shared library, which is in turn loaded by my main program. When the D library tries to allocate something, the whole program get an SIGSEGV in __GI___pthread_mutex_lock. Stack trace: (gdb) bt #0 __GI___pthread_mutex_lock

Re: Problem using shared D library from C shared library

2016-04-06 Thread Yuxuan Shui via Digitalmars-d-learn
On Thursday, 7 April 2016 at 01:42:54 UTC, rikki cattermole wrote: On 07/04/2016 1:38 PM, Yuxuan Shui wrote: [...] Have you started D's runtime? How to start D's runtime? I followed the examples found here: https://dlang.org/dll-linux.html#dso9, which doesn't say anything about starting

Re: Problem using shared D library from C shared library

2016-04-06 Thread Yuxuan Shui via Digitalmars-d-learn
On Thursday, 7 April 2016 at 02:01:31 UTC, Mike Parker wrote: On Thursday, 7 April 2016 at 01:50:31 UTC, Yuxuan Shui wrote: [...] The runtime is needed if you are going to use any of its features, like the GC. If you restrict yourself strictly to C in D (and that means avoiding thinks like

Re: Problem using shared D library from C shared library

2016-04-06 Thread Yuxuan Shui via Digitalmars-d-learn
On Thursday, 7 April 2016 at 02:01:31 UTC, Mike Parker wrote: On Thursday, 7 April 2016 at 01:50:31 UTC, Yuxuan Shui wrote: [...] The runtime is needed if you are going to use any of its features, like the GC. If you restrict yourself strictly to C in D (and that means avoiding thinks like

Re: Problem using shared D library from C shared library

2016-04-06 Thread Yuxuan Shui via Digitalmars-d-learn
On Thursday, 7 April 2016 at 03:37:39 UTC, Yuxuan Shui wrote: On Thursday, 7 April 2016 at 03:19:58 UTC, rikki cattermole wrote: On 07/04/2016 3:18 PM, Yuxuan Shui wrote: On Thursday, 7 April 2016 at 02:01:31 UTC, Mike Parker wrote: [...] static this/static ~this should work, right? They

Re: Problem using shared D library from C shared library

2016-04-06 Thread Yuxuan Shui via Digitalmars-d-learn
On Thursday, 7 April 2016 at 04:24:48 UTC, Yuxuan Shui wrote: On Thursday, 7 April 2016 at 03:37:39 UTC, Yuxuan Shui wrote: On Thursday, 7 April 2016 at 03:19:58 UTC, rikki cattermole wrote: On 07/04/2016 3:18 PM, Yuxuan Shui wrote: On Thursday, 7 April 2016 at 02:01:31 UTC, Mike Parker

Re: Problem using shared D library from C shared library

2016-04-06 Thread Yuxuan Shui via Digitalmars-d-learn
On Thursday, 7 April 2016 at 04:36:02 UTC, Yuxuan Shui wrote: On Thursday, 7 April 2016 at 04:24:48 UTC, Yuxuan Shui wrote: [...] Looks like _d_arrayappendcTX asked for a enormous amount of memory and it fails, can't figure out why Just find out it's my own fault. BTW, memory block

Re: Problem using shared D library from C shared library

2016-04-06 Thread Yuxuan Shui via Digitalmars-d-learn
On Thursday, 7 April 2016 at 03:19:58 UTC, rikki cattermole wrote: On 07/04/2016 3:18 PM, Yuxuan Shui wrote: On Thursday, 7 April 2016 at 02:01:31 UTC, Mike Parker wrote: [...] static this/static ~this should work, right? They execute when the runtime is started. So now I add call

getOverloads, but also include all the imported members

2016-03-23 Thread Yuxuan Shui via Digitalmars-d-learn
Say: module one; void func(int a){} / module two; import one; void func(float a){} Is there a way to get both func() in module two?

Re: getOverloads, but also include all the imported members

2016-03-24 Thread Yuxuan Shui via Digitalmars-d-learn
On Thursday, 24 March 2016 at 13:55:31 UTC, Adam D. Ruppe wrote: On Thursday, 24 March 2016 at 12:11:33 UTC, Marc Schütz wrote: On Wednesday, 23 March 2016 at 20:54:20 UTC, Yuxuan Shui wrote: module one; void func(int a){} / module two; import one; void func(float a){}

Re: getOverloads, but also include all the imported members

2016-03-25 Thread Yuxuan Shui via Digitalmars-d-learn
On Thursday, 24 March 2016 at 15:52:49 UTC, Adam D. Ruppe wrote: On Thursday, 24 March 2016 at 15:07:09 UTC, Yuxuan Shui wrote: Is there a way to do this automatically? No. You have to decide to bring them together if you want them to overload. Oh, sorry, this is not what I meant. What I

Re: Is it safe to use 'is' to compare types?

2016-03-03 Thread Yuxuan Shui via Digitalmars-d-learn
On Thursday, 3 March 2016 at 23:51:16 UTC, Adam D. Ruppe wrote: On Thursday, 3 March 2016 at 23:46:50 UTC, Yuxuan Shui wrote: Will typeid(a) is typeid(b) yield different results than typeid(a) == typeid(b)? No. Indeed, opEquals on TypeInfo just calls is itself. But opEquals also has extra

Is it safe to use 'is' to compare types?

2016-03-03 Thread Yuxuan Shui via Digitalmars-d-learn
Will typeid(a) is typeid(b) yield different results than typeid(a) == typeid(b)?

Re: Is it safe to use 'is' to compare types?

2016-03-03 Thread Yuxuan Shui via Digitalmars-d-learn
On Thursday, 3 March 2016 at 23:58:39 UTC, Yuxuan Shui wrote: On Thursday, 3 March 2016 at 23:51:16 UTC, Adam D. Ruppe wrote: On Thursday, 3 March 2016 at 23:46:50 UTC, Yuxuan Shui wrote: Will typeid(a) is typeid(b) yield different results than typeid(a) == typeid(b)? No. Indeed, opEquals on

Re: If stdout is __gshared, why does this throw / crash?

2016-03-05 Thread Yuxuan Shui via Digitalmars-d-learn
On Saturday, 5 March 2016 at 14:18:31 UTC, Atila Neves wrote: With a small number of threads, things work as intended in the code below. But with 1000, on my machine it either crashes or throws an exception: import std.stdio; import std.parallelism; import std.range; void main() {

Re: Is it safe to use 'is' to compare types?

2016-03-04 Thread Yuxuan Shui via Digitalmars-d-learn
On Friday, 4 March 2016 at 15:18:55 UTC, Steven Schveighoffer wrote: On 3/3/16 6:58 PM, Yuxuan Shui wrote: On Thursday, 3 March 2016 at 23:51:16 UTC, Adam D. Ruppe wrote: On Thursday, 3 March 2016 at 23:46:50 UTC, Yuxuan Shui wrote: Will typeid(a) is typeid(b) yield different results than

D thinks it is OK to mess around with TypeInfo

2016-03-04 Thread Yuxuan Shui via Digitalmars-d-learn
For example struct A{} @safe void main(){ import std.stdio; A a, b; auto y = typeid(a); y.name = "Nope, I'm not A"; auto x = typeid(b); writeln(x); } Make changes to TypeInfo will affect all the future typeid() results! And D is OK with that?

Re: Is it safe to use 'is' to compare types?

2016-03-08 Thread Yuxuan Shui via Digitalmars-d-learn
On Monday, 7 March 2016 at 16:13:45 UTC, Steven Schveighoffer wrote: On 3/4/16 4:30 PM, Yuxuan Shui wrote: On Friday, 4 March 2016 at 15:18:55 UTC, Steven Schveighoffer wrote: [...] Thanks for answering. But I still don't understand why TypeInfo would need to be allocated. Aren't typeid()

No aa.byKey.length?

2016-04-01 Thread Yuxuan Shui via Digitalmars-d-learn
Why? This is annoying when I need to feed it into a function that requires hasLength.

Re: Possible bug in RVO?

2016-04-04 Thread Yuxuan Shui via Digitalmars-d-learn
On Monday, 4 April 2016 at 21:31:08 UTC, Ali Çehreli wrote: On 04/04/2016 09:36 AM, Anonymouse wrote: On Monday, 4 April 2016 at 03:55:26 UTC, Yuxuan Shui wrote: [...] assert(x.aa.length > 0); // <-- boom [...] No idea myself but that's where it seems to go wrong. Looks like

key in aa.keys, but aa[key] give range violation?

2016-03-29 Thread Yuxuan Shui via Digitalmars-d-learn
My code looks something like this: bool[ulong][ulong] edge; foreach(u; from) foreach(v; to_) edge[u][v] = true; foreach(u; edge.keys) { auto adj = edge[u]; // } And sometimes edge[u] would give Range violation error.

Re: key in aa.keys, but aa[key] give range violation?

2016-03-29 Thread Yuxuan Shui via Digitalmars-d-learn
On Wednesday, 30 March 2016 at 00:26:49 UTC, Yuxuan Shui wrote: My code looks something like this: bool[ulong][ulong] edge; foreach(u; from) foreach(v; to_) edge[u][v] = true; foreach(u; edge.keys) { auto adj = edge[u]; // } And sometimes edge[u] would give Range

Re: No aa.byKey.length?

2016-04-03 Thread Yuxuan Shui via Digitalmars-d-learn
On Monday, 4 April 2016 at 00:50:27 UTC, Jonathan M Davis wrote: On Sunday, April 03, 2016 23:46:10 John Colvin via Digitalmars-d-learn wrote: On Saturday, 2 April 2016 at 16:00:51 UTC, Jonathan M Davis wrote: > [...] Maybe aa.byKey().takeExactly(aa.length) Yeah, that's a clever

Possible bug in RVO?

2016-04-03 Thread Yuxuan Shui via Digitalmars-d-learn
I have encountered a weird bug. I defined a Set class, which has a opBinary!"-". And somehow this: auto tmp = set_a-set_b; produces different results as this: set_a = set_a-set_b; the latter will produce an empty set. I tried to reduce the source code to get a test case. But this problem

Re: Possible bug in RVO?

2016-04-03 Thread Yuxuan Shui via Digitalmars-d-learn
On Monday, 4 April 2016 at 03:28:01 UTC, Yuxuan Shui wrote: I have encountered a weird bug. I defined a Set class, which has a opBinary!"-". And somehow this: auto tmp = set_a-set_b; produces different results as this: set_a = set_a-set_b; the latter will produce an empty set. I tried to

Re: Possible bug in RVO?

2016-04-03 Thread Yuxuan Shui via Digitalmars-d-learn
On Monday, 4 April 2016 at 03:28:01 UTC, Yuxuan Shui wrote: I have encountered a weird bug. I defined a Set class, which has a opBinary!"-". And somehow this: auto tmp = set_a-set_b; produces different results as this: set_a = set_a-set_b; the latter will produce an empty set. I tried to

Re: Possible bug in RVO?

2016-04-03 Thread Yuxuan Shui via Digitalmars-d-learn
On Monday, 4 April 2016 at 03:55:26 UTC, Yuxuan Shui wrote: On Monday, 4 April 2016 at 03:28:01 UTC, Yuxuan Shui wrote: I have encountered a weird bug. I defined a Set class, which has a opBinary!"-". And somehow this: auto tmp = set_a-set_b; produces different results as this: set_a =

Re: aliasing/referencing expressions in with statements

2016-04-21 Thread Yuxuan Shui via Digitalmars-d-learn
On Thursday, 21 April 2016 at 23:05:38 UTC, deed wrote: Often I find myself wanting to alias an expression, such as verbose fields, possibly nested. AFAIK, the with statement makes it easier, but not as good as it could have been. What I'd like to express is for example something like this:

Re: Implement async/await using Fiber

2016-05-19 Thread Yuxuan Shui via Digitalmars-d-learn
On Thursday, 19 May 2016 at 23:42:03 UTC, Ali Çehreli wrote: On 05/19/2016 12:57 PM, Yuxuan Shui wrote: [...] You can use a delegate that takes a ref parameter: import std.stdio; import core.thread; void fiberFunc(ref string y) { y = "produced_by_fiberFunc"; Fiber.yield(); } void

Re: Implement async/await using Fiber

2016-05-20 Thread Yuxuan Shui via Digitalmars-d-learn
On Friday, 20 May 2016 at 06:40:42 UTC, Jacob Carlborg wrote: On 2016-05-20 04:14, Yuxuan Shui wrote: Hmm... This could work. But I'm not satisfied with this solution. What if I have multiple yield sites in the fiber, and each have different return types? Maybe I should use a Variant? I

Re: Is there a way to make a class variable visible but constant to outsiders, but changeable (mutable) to the class itself?

2016-05-21 Thread Yuxuan Shui via Digitalmars-d-learn
On Saturday, 21 May 2016 at 17:32:47 UTC, dan wrote: Is it possible to have a class which has a variable which can be seen from the outside, but which can only be modified from the inside? Something like: class C { int my_var = 3; // semi_const?? void do_something() { my_var = 4; } }

Implement async/await using Fiber

2016-05-19 Thread Yuxuan Shui via Digitalmars-d-learn
I find this difficult because I can't passing data via Fiber.yield/Fiber.call pair. e.g. I want something like: void fiberFunc() { //Add some file descriptor to main loop string y = Fiber.yield(); writeln(y); } auto f = new Fiber(); f.call(); mainloop { if (fd_readable)

std.experimental.allocator and @nogc

2016-07-21 Thread Yuxuan Shui via Digitalmars-d-learn
I was trying to use allocators in a @nogc function. I tried FreeList!Mallocator and it works fine. But AllocatorList!Mallocator doesn't work. dmd complains that AllocatorList.allocate is not @nogc, even when BookkeepingAllocator is NullAllocator. But if I add '@nogc' to

Re: Another bug?

2017-01-30 Thread Yuxuan Shui via Digitalmars-d-learn
On Monday, 30 January 2017 at 12:40:44 UTC, Jack Applegame wrote: bug report: https://issues.dlang.org/show_bug.cgi?id=17128 LDC (2.070.2) has a different problem: the dtor is never called.

Re: switch statement with variable branches

2017-01-18 Thread Yuxuan Shui via Digitalmars-d-learn
On Thursday, 19 January 2017 at 02:00:10 UTC, Ali Çehreli wrote: On 01/18/2017 05:22 PM, Yuxuan Shui wrote: Somehow I can't use ubyte variables behind 'case', but ulong works fine. Why is that? case expressions must be constants: "The case expressions must all evaluate to a constant

switch statement with variable branches

2017-01-18 Thread Yuxuan Shui via Digitalmars-d-learn
Somehow I can't use ubyte variables behind 'case', but ulong works fine. Why is that? void main() { alias TestType = ulong; // won't compile if = ubyte import std.stdio; TestType a,b,c; readf("%s %s %s ", , , ); switch(c){ case a:

Chain a range of ranges?

2017-01-16 Thread Yuxuan Shui via Digitalmars-d-learn
The built in chain seems to only be able to chain a fixed number of ranges, is there a way to chain a range/array of ranges?

Re: Debug prints in @nogc

2016-08-31 Thread Yuxuan Shui via Digitalmars-d-learn
On Wednesday, 31 August 2016 at 18:07:46 UTC, Cauterite wrote: On Wednesday, 31 August 2016 at 16:17:51 UTC, Yuxuan Shui wrote: No. When you use assumeUnique, you know something the compiler does know, and have to use assumeUnique to tell the compiler that (at least when you use it correctly).

Re: Debug prints in @nogc

2016-08-31 Thread Yuxuan Shui via Digitalmars-d-learn
On Wednesday, 31 August 2016 at 19:39:36 UTC, ag0aep6g wrote: On 08/31/2016 09:23 PM, Yuxuan Shui wrote: Correct me if I'm wrong. But I believe this is only true when the source code of function is not available. Otherwise the compiler should always know if a function is actually @nogc or

Re: Prevent copy of range in foreach

2016-08-31 Thread Yuxuan Shui via Digitalmars-d-learn
On Wednesday, 31 August 2016 at 18:28:20 UTC, Ali Çehreli wrote: On 08/31/2016 07:03 AM, Yuxuan Shui wrote: > I want to make a hash table that uses > std.experiment.allocator. The bucket is allocated from an > allocator, and freed in ~this(). I don't want to copy the whole > bucket in

Re: Storing a reference

2016-09-01 Thread Yuxuan Shui via Digitalmars-d-learn
On Thursday, 1 September 2016 at 20:28:03 UTC, Rene Zwanenburg wrote: On Thursday, 1 September 2016 at 19:37:25 UTC, Yuxuan Shui wrote: [...] This will allocate a closure. A struct definition inside a function has a hidden context / closure pointer, unless it's a static struct. There is

Re: Storing a reference

2016-09-01 Thread Yuxuan Shui via Digitalmars-d-learn
On Thursday, 1 September 2016 at 21:07:36 UTC, Steven Schveighoffer wrote: On 9/1/16 4:38 PM, Yuxuan Shui wrote: [...] Referring to a null object is not a problem. Your program crashes ungracefully, but does not corrupt memory. However, in either approach, it can easily end up being a

Storing a reference

2016-09-01 Thread Yuxuan Shui via Digitalmars-d-learn
I just figured out how to store a reference: @safe: auto x(ref int a) { struct A { ref int xa() { return a; } } return A(); } void main() { import std.stdio; int b = 10; auto a = x(b); a.xa = 20; writeln(b); //Prints

Get all files imported by a D source file

2016-09-07 Thread Yuxuan Shui via Digitalmars-d-learn
Hi, I wonder if there's standardized way to gather which files are imported by a source file. I know I can run "dmd -v" and look for lines start with "import", but I don't know if this is the best way to do it.

Re: Get all files imported by a D source file

2016-09-08 Thread Yuxuan Shui via Digitalmars-d-learn
On Thursday, 8 September 2016 at 06:33:00 UTC, Jacob Carlborg wrote: On 2016-09-08 07:39, Yuxuan Shui wrote: Hi, I wonder if there's standardized way to gather which files are imported by a source file. I know I can run "dmd -v" and look for lines start with "import", but I don't know if

Prevent copy of range in foreach

2016-08-30 Thread Yuxuan Shui via Digitalmars-d-learn
Is there a way to use a range defined with disabled post-blit in foreach? In other words, is there a way to prevent foreach from copying the range? Should I use move()?

Performance issue with GC

2016-09-07 Thread Yuxuan Shui via Digitalmars-d-learn
I have a little data processing program which makes heavy use of associative arrays, and GC almost doubles the runtime of it (~2m with GC disabled -> ~4m). I just want to ask what's the best practice in this situation? Do I just use GC.disable and manually run GC.collect periodically?

Re: Performance issue with GC

2016-09-07 Thread Yuxuan Shui via Digitalmars-d-learn
On Wednesday, 7 September 2016 at 22:54:14 UTC, Basile B. wrote: On Wednesday, 7 September 2016 at 21:20:30 UTC, Yuxuan Shui wrote: I have a little data processing program which makes heavy use of associative arrays, and GC almost doubles the runtime of it (~2m with GC disabled -> ~4m). I

Re: Prevent copy of range in foreach

2016-08-31 Thread Yuxuan Shui via Digitalmars-d-learn
On Tuesday, 30 August 2016 at 20:30:12 UTC, Ali Çehreli wrote: On 08/30/2016 12:06 PM, Yuxuan Shui wrote: Is there a way to use a range defined with disabled post-blit in foreach? In other words, is there a way to prevent foreach from copying the range? It's not possible. You can't do much

Re: Debug prints in @nogc

2016-08-31 Thread Yuxuan Shui via Digitalmars-d-learn
On Wednesday, 31 August 2016 at 15:52:18 UTC, Cauterite wrote: On Wednesday, 31 August 2016 at 15:10:11 UTC, Seb wrote: AssumeNogc is potentially dangerous, so I don't know whether it can make it directly, but only if you try you know ;-) So is assumeUnique No. When you use assumeUnique,

Re: Get all files imported by a D source file

2016-09-09 Thread Yuxuan Shui via Digitalmars-d-learn
On Friday, 9 September 2016 at 10:03:01 UTC, wobbles wrote: On Thursday, 8 September 2016 at 07:20:52 UTC, Yuxuan Shui wrote: On Thursday, 8 September 2016 at 06:33:00 UTC, Jacob Carlborg wrote: On 2016-09-08 07:39, Yuxuan Shui wrote: Hi, I wonder if there's standardized way to gather which

Re: Copy a struct and its context

2016-09-13 Thread Yuxuan Shui via Digitalmars-d-learn
On Tuesday, 13 September 2016 at 01:32:19 UTC, Steven Schveighoffer wrote: On 9/12/16 4:11 PM, Ali Çehreli wrote: On 09/10/2016 10:44 PM, Yuxuan Shui wrote: I recently noticed nested struct capture its context by reference (which, BTW, is not mentioned at all here:

Copy a struct and its context

2016-09-10 Thread Yuxuan Shui via Digitalmars-d-learn
I recently noticed nested struct capture its context by reference (which, BTW, is not mentioned at all here: https://dlang.org/spec/struct.html#nested). And bliting a struct obviously doesn't do a deep copy of its context. So my question is, is there a way to deep copy the context of a

Re: Copy a struct and its context

2016-09-13 Thread Yuxuan Shui via Digitalmars-d-learn
On Tuesday, 13 September 2016 at 20:36:22 UTC, Steven Schveighoffer wrote: On 9/13/16 4:11 PM, Yuxuan Shui wrote: On Tuesday, 13 September 2016 at 20:00:40 UTC, Steven Schveighoffer wrote: Not familiar with C++ lambda. You can always "specify" how to capture the data by directly declaring it:

Re: Copy a struct and its context

2016-09-13 Thread Yuxuan Shui via Digitalmars-d-learn
On Tuesday, 13 September 2016 at 20:00:40 UTC, Steven Schveighoffer wrote: On 9/13/16 3:42 PM, Yuxuan Shui wrote: [...] There's nothing in the language to prevent this optimization. [...] Again, could be clearer. But the fact that both the function and the struct affect the same data

Re: Member not accessible in delegate body

2016-09-23 Thread Yuxuan Shui via Digitalmars-d-learn
On Friday, 23 September 2016 at 15:29:43 UTC, Rene Zwanenburg wrote: On Friday, 23 September 2016 at 07:54:15 UTC, John C wrote: How is it possible that "onTextChanged" isn't accessible but the private method "changeSize" *is*? Smells like an oversight. I guess the compiler doesn't see the

Append const to array

2016-09-20 Thread Yuxuan Shui via Digitalmars-d-learn
struct A { ulong[] x; } struct B { ulong x; } void main() { B[] b; const(B) xx = B(1); b ~= xx; // Works A[] c; const(A) yy = A([1]); c ~= yy; // Does not } What gives?

Re: Append const to array

2016-09-20 Thread Yuxuan Shui via Digitalmars-d-learn
On Tuesday, 20 September 2016 at 22:38:33 UTC, Jonathan M Davis wrote: On Tuesday, September 20, 2016 22:23:08 Yuxuan Shui via Digitalmars-d-learn wrote: struct A { ulong[] x; } struct B { ulong x; } void main() { B[] b; const(B) xx = B(1); b ~= xx; // Works A[] c; const(A) yy

opIndexDispatch?

2016-10-10 Thread Yuxuan Shui via Digitalmars-d-learn
Hi, Why is there no opIndexDispatch for overloading a[x].func() ?

Get return type of a template function without instantiating it

2016-11-22 Thread Yuxuan Shui via Digitalmars-d-learn
Is there a way to get a template function return type with instantiating it? The return type is independent of the template arguments. I'm asking because there's potentially recursive template instantiation if I do try to instantiate it.

Re: opIndexDispatch?

2016-10-12 Thread Yuxuan Shui via Digitalmars-d-learn
On Monday, 10 October 2016 at 19:16:06 UTC, Jonathan M Davis wrote: On Monday, October 10, 2016 19:01:19 Yuxuan Shui via Digitalmars-d-learn wrote: Hi, Why is there no opIndexDispatch for overloading a[x].func() ? There's opIndex for overloading a[x], and then you can call a function

  1   2   >