Re: compile error while use `extern(C++, class)`

2016-08-18 Thread mogu via Digitalmars-d-learn
On Thursday, 18 August 2016 at 16:41:27 UTC, Lodovico Giaretta wrote: On Thursday, 18 August 2016 at 16:19:41 UTC, Johan Engelen wrote: On Thursday, 18 August 2016 at 11:43:03 UTC, Lodovico Giaretta wrote: Which compiler version are you using? On DMD 2.071.0 this does not work. Note: this

How to specify --arch option in dub.json

2017-02-26 Thread mogu via Digitalmars-d-learn
I use dub 1.2.1 to build my project. As convenience, I choose `dflags-windows-x86: ["-m32mscoff"]` option in dub.json of my library binding to specify default architecture in win32 platform. But in the newest dub release, this cause a warning which told me to use DLFAGS environment or specify

Why typeof(template) is void?

2016-07-19 Thread mogu via Digitalmars-d-learn
``` struct S(T) {} static assert(is (typeof(S) == void)); ``` Why S's type isn't something like `S: (T) -> S`?

Re: Why typeof(template) is void?

2016-07-19 Thread mogu via Digitalmars-d-learn
On Wednesday, 20 July 2016 at 01:50:37 UTC, Adam D. Ruppe wrote: On Wednesday, 20 July 2016 at 01:14:05 UTC, mogu wrote: Why S's type isn't something like `S: (T) -> S`? Because S isn't a type... think of a template as being like a function that returns a type. int foo(int) { return 0; }

Re: Why typeof(template) is void?

2016-07-20 Thread mogu via Digitalmars-d-learn
On Wednesday, 20 July 2016 at 08:01:01 UTC, Lodovico Giaretta wrote: Note that void is a type, while S is not. So you can do: assert(is(void)) // is(type) returns true assert(!is(S)) // is(template) returns false; Thanks very much. I should have noticed this before. T.T

Re: About spinlock implementation

2016-09-01 Thread mogu via Digitalmars-d-learn
On Thursday, 1 September 2016 at 07:46:04 UTC, qznc wrote: I'm not sure I understand rel [0], but raw is too weak. Raw means no sequencing barrier, so local_var = protected_value; spinlock.unlock(); could be transformed (by compiler or CPU) to spinlock.unlock(); local_var =

About spinlock implementation

2016-09-01 Thread mogu via Digitalmars-d-learn
I found an implementation of spinlock in concurrency.d. ``` static shared struct SpinLock { void lock() { while (!cas(, false, true)) { Thread.yield(); } } void unlock() { atomicStore!(MemoryOrder.rel)(locked, false); } bool locked; } ``` Why atomicStore use MemoryOrder.rel instead

Re: About spinlock implementation

2016-09-01 Thread mogu via Digitalmars-d-learn
On Thursday, 1 September 2016 at 07:46:04 UTC, qznc wrote: This effectively makes the access to the protected value unprotected and nullifies the effect of the spinlock. So the cas operation implicit an MemoryOrder.acq? Does it make any other MemoryOrder guarantee?

Fiber cross threads terminated

2016-09-01 Thread mogu via Digitalmars-d-learn
Here's my code in main function: ``` auto fiber = new Fiber({ while (true) { Thread.sleep(1.seconds); Fiber.yield; } }); void foo() { while (true) { fiber.call; //Thread.sleep(1.seconds);

Re: Fiber cross threads terminated

2016-09-01 Thread mogu via Digitalmars-d-learn
On Friday, 2 September 2016 at 01:53:58 UTC, Steven Schveighoffer wrote: On 9/1/16 9:27 PM, mogu wrote: Here's my code in main function: ``` auto fiber = new Fiber({ while (true) { Thread.sleep(1.seconds); Fiber.yield; } }); void foo() {

Re: Prevent copy of range in foreach

2016-08-31 Thread mogu via Digitalmars-d-learn
On Tuesday, 30 August 2016 at 19:06:46 UTC, 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? Should I use move()? 国人?望加群:531010036 谢谢

compile error while use `extern(C++, class)`

2016-08-17 Thread mogu via Digitalmars-d-learn
From spec (Interfacing to C++) https://dlang.org/spec/cpp_interface.html: ``` When mapping a D class onto a C++ struct, use extern(C++, struct) to avoid linking problems with C++ compilers (notably MSVC) that distinguish between C++'s class and struct when mangling. Conversely, use

Re: compile error while use `extern(C++, class)`

2016-08-18 Thread mogu via Digitalmars-d-learn
On Thursday, 18 August 2016 at 10:45:14 UTC, Lodovico Giaretta wrote: Which kind of error? An error message by the compiler? One by the linker? The compiler crashes? Compiler Error exactly. The minimal code is(dmd or ldc2 in ubuntu 16.04 lts): ``` extern (C++, struct) class A {} ```