Re: build dll project use VisualD with the "Use MS-COFF object file..." setting selected failed

2016-08-26 Thread magicdmer via Digitalmars-d-learn
On Friday, 26 August 2016 at 07:21:55 UTC, Daniel Kozak wrote: Dne 26.8.2016 v 09:12 magicdmer via Digitalmars-d-learn can you try it from console? something like dmd.exe -m32mscoff your_d_file.d same error , it's only dll project like this. console project can build successfully with the "MS-

Re: build dll project use VisualD with the "Use MS-COFF object file..." setting selected failed

2016-08-26 Thread Daniel Kozak via Digitalmars-d-learn
Dne 26.8.2016 v 09:12 magicdmer via Digitalmars-d-learn napsal(a): On Friday, 26 August 2016 at 07:00:37 UTC, rikki cattermole wrote: Okay so your Windows language is non-english, that'll be it. You need to be looking into the encoding that Visual Studio is using for you files. Something to do

Re: build dll project use VisualD with the "Use MS-COFF object file..." setting selected failed

2016-08-26 Thread magicdmer via Digitalmars-d-learn
On Friday, 26 August 2016 at 07:00:37 UTC, rikki cattermole wrote: Okay so your Windows language is non-english, that'll be it. You need to be looking into the encoding that Visual Studio is using for you files. Something to do with the BOM or hasn't even been set to utf-8 isn't quite right.

Re: build dll project use VisualD with the "Use MS-COFF object file..." setting selected failed

2016-08-26 Thread Daniel Kozak via Digitalmars-d-learn
, and select the "Use MS-COFF object file fromat for win32" . when i build it ,it display the error follow ,look at the picture I use dmd 2.071.1 https://s14.postimg.org/a4wcv74ct/image.png sorry,i post wrong url,look follow url, can you tell me how to modify the thread https:/

Re: build dll project use VisualD with the "Use MS-COFF object file..." setting selected failed

2016-08-26 Thread rikki cattermole via Digitalmars-d-learn
se MS-COFF object file fromat for win32" . when i build it ,it display the error follow ,look at the picture I use dmd 2.071.1 https://s14.postimg.org/a4wcv74ct/image.png sorry,i post wrong url,look follow url, can you tell me how to modify the thread https://s14.postimg.io/cyzi8n6j5/image.png

Re: build dll project use VisualD with the "Use MS-COFF object file..." setting selected failed

2016-08-25 Thread magicdmer via Digitalmars-d-learn
On Friday, 26 August 2016 at 06:38:01 UTC, Daniel Kozak wrote: That image is too small, so I can't see it :) Dne 26.8.2016 v 08:26 magicdmer via Digitalmars-d-learn napsal(a): I use VisualD create a windows dll project , and select the "Use MS-COFF object file fromat for win32"

Re: build dll project use VisualD with the "Use MS-COFF object file..." setting selected failed

2016-08-25 Thread Daniel Kozak via Digitalmars-d-learn
That image is too small, so I can't see it :) Dne 26.8.2016 v 08:26 magicdmer via Digitalmars-d-learn napsal(a): I use VisualD create a windows dll project , and select the "Use MS-COFF object file fromat for win32" . when i build it ,it display the error follow ,look at the

build dll project use VisualD with the "Use MS-COFF object file..." setting selected failed

2016-08-25 Thread magicdmer via Digitalmars-d-learn
I use VisualD create a windows dll project , and select the "Use MS-COFF object file fromat for win32" . when i build it ,it display the error follow ,look at the picture I use dmd 2.071.1 https://s14.postimg.org/a4wcv74ct/image.png

Re: Retreive method given object, name and arguments

2016-08-11 Thread ketmar via Digitalmars-d-learn
On Thursday, 11 August 2016 at 20:27:51 UTC, Michael Coulombe wrote: here is something for you to play with: import std.stdio; enum CallAllowed0; enum CallAllowed1; struct S { @CallAllowed0 void foo () { writeln("foo()"); } @CallAllowed1 void foo (int n) { writeln("foo(", n, ")"); } }

Re: Retreive method given object, name and arguments

2016-08-11 Thread ketmar via Digitalmars-d-learn
On Thursday, 11 August 2016 at 20:41:33 UTC, ketmar wrote: ah, my bad, i missed UDA part of the question. sorry. ;-)

Re: Retreive method given object, name and arguments

2016-08-11 Thread ketmar via Digitalmars-d-learn
On Thursday, 11 August 2016 at 20:27:51 UTC, Michael Coulombe wrote: import std.stdio; struct S { void foo () { writeln("foo()"); } void foo (int n) { writeln("foo(", n, ")"); } } auto doit(string methodName, C, Args...) (C c, Args args) { static if (is(typeof(mixin("c."~methodName~"(a

Re: Retreive method given object, name and arguments

2016-08-11 Thread Lodovico Giaretta via Digitalmars-d-learn
On Thursday, 11 August 2016 at 20:27:51 UTC, Michael Coulombe wrote: Is there a way to implement "getSymbolOfCall" and "getDelegateOfCall" such that doit is functionally equivalent to calling the method directly? auto doit(C, string methodName, Args...)(C c, Args args) { alias methodSymbol

Retreive method given object, name and arguments

2016-08-11 Thread Michael Coulombe via Digitalmars-d-learn
Is there a way to implement "getSymbolOfCall" and "getDelegateOfCall" such that doit is functionally equivalent to calling the method directly? auto doit(C, string methodName, Args...)(C c, Args args) { alias methodSymbol = getSymbolOfCall!(c, methodName, Args); pragma(msg, hasUDA!(meth

Re: Does D have object wrappers for primitives?

2016-07-30 Thread Cauterite via Digitalmars-d-learn
'not callable using a mutable object'. Even marking a string with the immutable keyword has the same result. auto s = new immutable(Boxed!string)(`foo`); what it's saying is that the box itself needs to be immutable. Honestly I don't know why it was even possible to make a

Re: Does D have object wrappers for primitives?

2016-07-29 Thread stunaep via Digitalmars-d-learn
On Friday, 29 July 2016 at 20:25:16 UTC, Cauterite wrote: On Friday, 29 July 2016 at 20:13:34 UTC, stunaep wrote: I have some java code I need to convert and at one point it uses an Object[] array to store various ints, longs, and strings. Java has built in Integer and Long classes that wrap

Re: Does D have object wrappers for primitives?

2016-07-29 Thread Ali Çehreli via Digitalmars-d-learn
.html#.Algebraic >> >> Ali > > It could work, but keep in mind Algebraic is a structure, not an object. Also, I've later noticed that your Box was a class, so it would allow "arrays of mixed primitive types" as well. Yes, Algebraic is not a struct but Java not

Re: Does D have object wrappers for primitives?

2016-07-29 Thread Cauterite via Digitalmars-d-learn
an object.

Re: Does D have object wrappers for primitives?

2016-07-29 Thread Ali Çehreli via Digitalmars-d-learn
On 07/29/2016 01:25 PM, Cauterite wrote: On Friday, 29 July 2016 at 20:13:34 UTC, stunaep wrote: I have some java code I need to convert and at one point it uses an Object[] array to store various ints, longs, and strings. Java has built in Integer and Long classes that wrap the primitives in

Re: Does D have object wrappers for primitives?

2016-07-29 Thread Cauterite via Digitalmars-d-learn
On Friday, 29 July 2016 at 20:13:34 UTC, stunaep wrote: I have some java code I need to convert and at one point it uses an Object[] array to store various ints, longs, and strings. Java has built in Integer and Long classes that wrap the primitives in an object and strings are already objects

Does D have object wrappers for primitives?

2016-07-29 Thread stunaep via Digitalmars-d-learn
I have some java code I need to convert and at one point it uses an Object[] array to store various ints, longs, and strings. Java has built in Integer and Long classes that wrap the primitives in an object and strings are already objects.

Re: Getting most derived type of object that implements interface

2016-07-25 Thread cc via Digitalmars-d-learn
Ahh I see, thanks guys.

Re: Getting most derived type of object that implements interface

2016-07-25 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/25/16 5:54 AM, Kagamin wrote: Cast it to Object: FooInterface a = new BarImplementsInterface(); FooBaseClass b = new BarDerivedClass(); Object o = cast(Object)a; writefln("a class: %s", a.classinfo.name); writefln("b class: %s", b.classinfo.name);

Re: Getting most derived type of object that implements interface

2016-07-25 Thread ketmar via Digitalmars-d-learn
yep, cast it. without the cast, compiler assuming that it knows the type in runtime, and is using well-known classinfo address instead of really looking into instance for that.

Re: Getting most derived type of object that implements interface

2016-07-25 Thread Kagamin via Digitalmars-d-learn
Cast it to Object: FooInterface a = new BarImplementsInterface(); FooBaseClass b = new BarDerivedClass(); Object o = cast(Object)a; writefln("a class: %s", a.classinfo.name); writefln("b class: %s", b.classinfo.name); w

Getting most derived type of object that implements interface

2016-07-25 Thread cc via Digitalmars-d-learn
I'm having trouble getting the full name of an object of a class that implements an interface, using typeid() or .classinfo, the behavior seems to be different from that of a class that simply derives other classes. interface FooInterface {} class BarImplementsInterface : FooInte

Re: opEquals on shared object

2016-06-30 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/30/16 8:30 AM, jj75607 wrote: On Thursday, 30 June 2016 at 12:21:03 UTC, Steven Schveighoffer wrote: On 6/30/16 6:26 AM, jj75607 wrote: Hello! I need to overload opEquals on shared class C shared class C { override bool opEquals(Object o) { return false; } } But compilation fails

Re: opEquals on shared object

2016-06-30 Thread jj75607 via Digitalmars-d-learn
On Thursday, 30 June 2016 at 12:21:03 UTC, Steven Schveighoffer wrote: On 6/30/16 6:26 AM, jj75607 wrote: Hello! I need to overload opEquals on shared class C shared class C { override bool opEquals(Object o) { return false; } } But compilation fails with the message: Error: function

Re: opEquals on shared object

2016-06-30 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/30/16 6:26 AM, jj75607 wrote: Hello! I need to overload opEquals on shared class C shared class C { override bool opEquals(Object o) { return false; } } But compilation fails with the message: Error: function f700.C.opEquals does not override any function, did you mean to override

opEquals on shared object

2016-06-30 Thread jj75607 via Digitalmars-d-learn
Hello! I need to overload opEquals on shared class C shared class C { override bool opEquals(Object o) { return false; } } But compilation fails with the message: Error: function f700.C.opEquals does not override any function, did you mean to override 'object.Object.opEquals'?

Re: ndslice: convert a sliced object to T[]

2016-06-15 Thread Ilya Yaroshenko via Digitalmars-d-learn
On Wednesday, 15 June 2016 at 14:14:23 UTC, Seb wrote: ``` T[] a = slice.ptr[0.. slice.elementsCount]; ``` This would work only for slices with continuous memory representation and positive strides. -- Ilya

Re: ndslice: convert a sliced object to T[]

2016-06-15 Thread data pulverizer via Digitalmars-d-learn
On Wednesday, 15 June 2016 at 14:14:23 UTC, Seb wrote: On Wednesday, 15 June 2016 at 13:13:05 UTC, data pulverizer And where can I find more cool tricks like that? Browse the source code and the unittests. Phobos is an amazing resource :) Very true! That's great many thanks!

Re: ndslice: convert a sliced object to T[]

2016-06-15 Thread Seb via Digitalmars-d-learn
On Wednesday, 15 June 2016 at 13:13:05 UTC, data pulverizer wrote: On Wednesday, 15 June 2016 at 12:10:32 UTC, Seb wrote: As said you can avoid the copy (see below). I also profiled it a bit and it was interesting to see that 50% of the runtime are spent on generating the random matrix. On my m

Re: ndslice: convert a sliced object to T[]

2016-06-15 Thread data pulverizer via Digitalmars-d-learn
Oh, I didn't see that runif now returns a tuple.

Re: ndslice: convert a sliced object to T[]

2016-06-15 Thread data pulverizer via Digitalmars-d-learn
On Wednesday, 15 June 2016 at 12:10:32 UTC, Seb wrote: As said you can avoid the copy (see below). I also profiled it a bit and it was interesting to see that 50% of the runtime are spent on generating the random matrix. On my machine now both scripts take 1.5s when compiled with I didn't ben

Re: ndslice: convert a sliced object to T[]

2016-06-15 Thread Seb via Digitalmars-d-learn
On Wednesday, 15 June 2016 at 11:19:20 UTC, data pulverizer wrote: On Wednesday, 15 June 2016 at 09:32:21 UTC, Andrea Fontana wrote: Then I think the slice.byElement.array is the right solution. The problem with that is that it slows down the code. I compared matrix multiplication between R a

Re: ndslice: convert a sliced object to T[]

2016-06-15 Thread data pulverizer via Digitalmars-d-learn
On Wednesday, 15 June 2016 at 09:32:21 UTC, Andrea Fontana wrote: Then I think the slice.byElement.array is the right solution. The problem with that is that it slows down the code. I compared matrix multiplication between R and D's cblas adaptor and ndslice. n = 4000 Matrices: A, B Sizes: b

Re: ndslice: convert a sliced object to T[]

2016-06-15 Thread Andrea Fontana via Digitalmars-d-learn
On Wednesday, 15 June 2016 at 08:56:15 UTC, data pulverizer wrote: On Wednesday, 15 June 2016 at 08:53:22 UTC, Andrea Fontana wrote: On Wednesday, 15 June 2016 at 08:25:35 UTC, data pulverizer wrote: I guess foreach would not copy the elements? for example: foreach(el; slice.byElement)

Re: ndslice: convert a sliced object to T[]

2016-06-15 Thread data pulverizer via Digitalmars-d-learn
On Wednesday, 15 June 2016 at 08:53:22 UTC, Andrea Fontana wrote: On Wednesday, 15 June 2016 at 08:25:35 UTC, data pulverizer wrote: I guess foreach would not copy the elements? for example: foreach(el; slice.byElement) x ~= el; But it feels wrong to be doing work pulling eleme

Re: ndslice: convert a sliced object to T[]

2016-06-15 Thread Andrea Fontana via Digitalmars-d-learn
On Wednesday, 15 June 2016 at 08:25:35 UTC, data pulverizer wrote: I guess foreach would not copy the elements? for example: foreach(el; slice.byElement) x ~= el; But it feels wrong to be doing work pulling elements that already exists by using foreach. I feel as if I am missin

Re: ndslice: convert a sliced object to T[]

2016-06-15 Thread data pulverizer via Digitalmars-d-learn
On Wednesday, 15 June 2016 at 07:45:12 UTC, Andrea Fontana wrote: On Wednesday, 15 June 2016 at 07:24:23 UTC, data pulverizer wrote: On Wednesday, 15 June 2016 at 03:17:39 UTC, Seb wrote: On Wednesday, 15 June 2016 at 03:11:23 UTC, data pulverizer wrote: in that case: import std.array : array

Re: ndslice: convert a sliced object to T[]

2016-06-15 Thread Andrea Fontana via Digitalmars-d-learn
On Wednesday, 15 June 2016 at 07:24:23 UTC, data pulverizer wrote: On Wednesday, 15 June 2016 at 03:17:39 UTC, Seb wrote: On Wednesday, 15 June 2016 at 03:11:23 UTC, data pulverizer wrote: in that case: import std.array : array; int[] x = slice.byElement.array; Are you sure you want to creat

Re: ndslice: convert a sliced object to T[]

2016-06-15 Thread data pulverizer via Digitalmars-d-learn
On Wednesday, 15 June 2016 at 03:17:39 UTC, Seb wrote: On Wednesday, 15 June 2016 at 03:11:23 UTC, data pulverizer wrote: in that case: import std.array : array; int[] x = slice.byElement.array; Are you sure you want to create a _copy_ of your data? In most cases you don't need that ;-) t

Re: ndslice: convert a sliced object to T[]

2016-06-14 Thread Seb via Digitalmars-d-learn
On Wednesday, 15 June 2016 at 03:11:23 UTC, data pulverizer wrote: in that case: import std.array : array; int[] x = slice.byElement.array; Are you sure you want to create a _copy_ of your data? In most cases you don't need that ;-) thanks, now I can go to bed! You are welcome. Sleep tig

Re: ndslice: convert a sliced object to T[]

2016-06-14 Thread data pulverizer via Digitalmars-d-learn
On Wednesday, 15 June 2016 at 02:50:30 UTC, Seb wrote: On Wednesday, 15 June 2016 at 02:43:37 UTC, data pulverizer wrote: How do I unravel a sliced item T[].sliced(...) to an array T[]? For instance: import std.experimental.ndslice; auto slice = new int[12].sliced(3, 4); int[] x = ??; Thanks

Re: ndslice: convert a sliced object to T[]

2016-06-14 Thread Seb via Digitalmars-d-learn
On Wednesday, 15 June 2016 at 02:43:37 UTC, data pulverizer wrote: How do I unravel a sliced item T[].sliced(...) to an array T[]? For instance: import std.experimental.ndslice; auto slice = new int[12].sliced(3, 4); int[] x = ??; Thanks A slice is just a _view_ on your memory, the easiest w

ndslice: convert a sliced object to T[]

2016-06-14 Thread data pulverizer via Digitalmars-d-learn
How do I unravel a sliced item T[].sliced(...) to an array T[]? For instance: import std.experimental.ndslice; auto slice = new int[12].sliced(3, 4); int[] x = ??; Thanks

Re: Error: mutable method isolated.graphics.g3d.model.Model.begin is not callable using a const object

2016-06-07 Thread Alex Parrill via Digitalmars-d-learn
On Monday, 6 June 2016 at 21:55:00 UTC, ag0aep6g wrote: On 06/06/2016 11:25 PM, Alex Parrill wrote: You might be able to get away with casting the const away, if you are sure it won't modify the hash or equality check. Casting away const and then mutating has undefined behavior. The compiler

Re: Error: mutable method isolated.graphics.g3d.model.Model.begin is not callable using a const object

2016-06-06 Thread ag0aep6g via Digitalmars-d-learn
On 06/06/2016 11:25 PM, Alex Parrill wrote: You might be able to get away with casting the const away, if you are sure it won't modify the hash or equality check. Casting away const and then mutating has undefined behavior. The compiler is free to assume that it doesn't happen. Be aware that

Re: Error: mutable method isolated.graphics.g3d.model.Model.begin is not callable using a const object

2016-06-06 Thread Begah via Digitalmars-d-learn
On Monday, 6 June 2016 at 21:25:16 UTC, Alex Parrill wrote: On Monday, 6 June 2016 at 21:16:18 UTC, Begah wrote: Does the key of a associative array will be const if the reference is requested? That's probably what it is, actually. Modifying the key with the ref could cause the hash of the ke

Re: Error: mutable method isolated.graphics.g3d.model.Model.begin is not callable using a const object

2016-06-06 Thread Alex Parrill via Digitalmars-d-learn
On Monday, 6 June 2016 at 21:16:18 UTC, Begah wrote: Does the key of a associative array will be const if the reference is requested? That's probably what it is, actually. Modifying the key with the ref could cause the hash of the key to change without the hashtable knowing about it, causing

Re: Error: mutable method isolated.graphics.g3d.model.Model.begin is not callable using a const object

2016-06-06 Thread Begah via Digitalmars-d-learn
On Monday, 6 June 2016 at 21:09:41 UTC, Alex Parrill wrote: On Monday, 6 June 2016 at 20:40:12 UTC, Begah wrote: I have a pretty weird error : Error: mutable method isolated.graphics.g3d.model.Model.begin is not callable using a const object [...] It may infer const from the type of

Re: Error: mutable method isolated.graphics.g3d.model.Model.begin is not callable using a const object

2016-06-06 Thread Alex Parrill via Digitalmars-d-learn
On Monday, 6 June 2016 at 20:40:12 UTC, Begah wrote: I have a pretty weird error : Error: mutable method isolated.graphics.g3d.model.Model.begin is not callable using a const object [...] It may infer const from the type of `this.instance`, which may be further modified if the method you

Error: mutable method isolated.graphics.g3d.model.Model.begin is not callable using a const object

2016-06-06 Thread Begah via Digitalmars-d-learn
I have a pretty weird error : Error: mutable method isolated.graphics.g3d.model.Model.begin is not callable using a const object The weird part is that i do not use const or immutable objects in my code ( for the Model ) : struct Handle { Model *asset = null; string

Re: is my code to get CTFE instantiated object valid D ?

2016-05-29 Thread Steven Schveighoffer via Digitalmars-d-learn
On Sunday, 29 May 2016 at 05:43:31 UTC, Mike Parker wrote: On Sunday, 29 May 2016 at 05:35:33 UTC, Mike Parker wrote: Well then, this completely breaks my understanding of variable scope. OK, I see now at [1] the following: " Immutable data doesn't have synchronization problems, so the comp

Re: is my code to get CTFE instantiated object valid D ?

2016-05-29 Thread chmike via Digitalmars-d-learn
On Sunday, 29 May 2016 at 06:49:42 UTC, chmike wrote: What is the right way to use it ? I answer to my self after testing so that people looking for that info can find it here. The right way would be immutable Category category_; Rebindable!(immutable Category) instance() { return

Re: is my code to get CTFE instantiated object valid D ?

2016-05-28 Thread chmike via Digitalmars-d-learn
On Saturday, 28 May 2016 at 21:21:34 UTC, ag0aep6g wrote: On 05/28/2016 09:54 PM, chmike wrote: The only inconvenience left is that we can't have mutable references to immutable objects. There is std.typecons.Rebindable for that. That would be a good news. What is the right way to use it ?

Re: is my code to get CTFE instantiated object valid D ?

2016-05-28 Thread Mike Parker via Digitalmars-d-learn
On Sunday, 29 May 2016 at 05:35:33 UTC, Mike Parker wrote: Well then, this completely breaks my understanding of variable scope. OK, I see now at [1] the following: " Immutable data doesn't have synchronization problems, so the compiler doesn't place it in TLS." I've read that page more th

Re: is my code to get CTFE instantiated object valid D ?

2016-05-28 Thread Mike Parker via Digitalmars-d-learn
On Saturday, 28 May 2016 at 15:39:44 UTC, ag0aep6g wrote: On 05/28/2016 10:34 AM, Mike Parker wrote: On Saturday, 28 May 2016 at 05:30:26 UTC, chmike wrote: [...] Is a static const Category c variable a TLS variable ? Yes. All variables are TLS unless explicitly marked with __gshared or sh

Re: is my code to get CTFE instantiated object valid D ?

2016-05-28 Thread ag0aep6g via Digitalmars-d-learn
On 05/28/2016 09:54 PM, chmike wrote: The only inconvenience left is that we can't have mutable references to immutable objects. There is std.typecons.Rebindable for that.

Re: is my code to get CTFE instantiated object valid D ?

2016-05-28 Thread chmike via Digitalmars-d-learn
On Friday, 27 May 2016 at 20:20:36 UTC, chmike wrote: I need to create an app wide singleton instance for my class. The singleton is immutable, but I want to allow mutable references to that singleton object so that I can do fast 'is' tests. I declared this class Category {

Re: Is it possible to forbid synchronization on an object ?

2016-05-28 Thread Meta via Digitalmars-d-learn
instances where in fact objects with the same state (member variable value) are the same instance. Since with play a trick with the users assumption, there is a high risk that user produces logically invalid code when using synchronization with such a flyweight object. In order to avoid this

Re: is my code to get CTFE instantiated object valid D ?

2016-05-28 Thread ag0aep6g via Digitalmars-d-learn
On 05/28/2016 06:09 PM, chmike wrote: In the following instruction of the above commit, what effect has the [] after init ? _store[0 .. __traits(classInstanceSize, T)] = typeid(T).init[]; T is a template argument that is a class derived from Error. I couldn't find an explanation here https:/

Is it possible to forbid synchronization on an object ?

2016-05-28 Thread chmike via Digitalmars-d-learn
variable value) are the same instance. Since with play a trick with the users assumption, there is a high risk that user produces logically invalid code when using synchronization with such a flyweight object. In order to avoid this problem I would need a solution to make synchronization

Re: is my code to get CTFE instantiated object valid D ?

2016-05-28 Thread chmike via Digitalmars-d-learn
On Saturday, 28 May 2016 at 08:47:48 UTC, Kagamin wrote: For a trick of static mutable allocation see https://github.com/dlang/druntime/pull/1325 In the following instruction of the above commit, what effect has the [] after init ? _store[0 .. __traits(classInstanceSize, T)] = typeid(T).ini

Re: is my code to get CTFE instantiated object valid D ?

2016-05-28 Thread ag0aep6g via Digitalmars-d-learn
On 05/28/2016 10:34 AM, Mike Parker wrote: On Saturday, 28 May 2016 at 05:30:26 UTC, chmike wrote: [...] Is a static const Category c variable a TLS variable ? Yes. All variables are TLS unless explicitly marked with __gshared or shared. I don't think that's true. import core.thread;

Re: is my code to get CTFE instantiated object valid D ?

2016-05-28 Thread chmike via Digitalmars-d-learn
On Saturday, 28 May 2016 at 08:47:48 UTC, Kagamin wrote: For a trick of static mutable allocation see https://github.com/dlang/druntime/pull/1325 Thank you that looks promising. I'll study an experiment with the code. If I would like that the instances are not in TLS, can I use the following

Re: is my code to get CTFE instantiated object valid D ?

2016-05-28 Thread Kagamin via Digitalmars-d-learn
On Saturday, 28 May 2016 at 05:30:26 UTC, chmike wrote: Would it be different if the object was declared const instead of immutable ? Sometimes compiler is able to figure out that const data is immutable. This is a bit frustrating because it is trivial to implement in C and C++. For a

Re: is my code to get CTFE instantiated object valid D ?

2016-05-28 Thread Mike Parker via Digitalmars-d-learn
On Saturday, 28 May 2016 at 08:34:17 UTC, Mike Parker wrote: const(F) cf = f; immutable(f) if = f; And, of course, those should be const(Foo) and immutable(Foo).

Re: is my code to get CTFE instantiated object valid D ?

2016-05-28 Thread Mike Parker via Digitalmars-d-learn
On Saturday, 28 May 2016 at 05:30:26 UTC, chmike wrote: What is the difference between a const and immutable object ? would a const object be allowed to modify itself by using a hash table or caching results inside ? The difference lies in the guarantees of const and immutable. Foo f = new

Re: is my code to get CTFE instantiated object valid D ?

2016-05-27 Thread chmike via Digitalmars-d-learn
On Friday, 27 May 2016 at 21:41:02 UTC, Kagamin wrote: On Friday, 27 May 2016 at 20:20:36 UTC, chmike wrote: Is this code valid D or is the behavior undefined due to the cast ? A mutable object can be synchronized on: synchronized(Category.instance){} This will create and store a mutex in the

Re: is my code to get CTFE instantiated object valid D ?

2016-05-27 Thread Era Scarecrow via Digitalmars-d-learn
On Friday, 27 May 2016 at 20:20:36 UTC, chmike wrote: The public interface of Category is designed so that the object's state can't be modified and thus remains immutable. Then... why cast away immutable? I suppose there's always a core set of variables that are what the

Re: is my code to get CTFE instantiated object valid D ?

2016-05-27 Thread Kagamin via Digitalmars-d-learn
On Friday, 27 May 2016 at 20:20:36 UTC, chmike wrote: Is this code valid D or is the behavior undefined due to the cast ? A mutable object can be synchronized on: synchronized(Category.instance){} This will create and store a mutex in the object (sad but true, design taken from java). If the

Re: is my code to get CTFE instantiated object valid D ?

2016-05-27 Thread Steven Schveighoffer via Digitalmars-d-learn
On 5/27/16 4:20 PM, chmike wrote: I need to create an app wide singleton instance for my class. The singleton is immutable, but I want to allow mutable references to that singleton object so that I can do fast 'is' tests. I declared this class Category { protected static

is my code to get CTFE instantiated object valid D ?

2016-05-27 Thread chmike via Digitalmars-d-learn
I need to create an app wide singleton instance for my class. The singleton is immutable, but I want to allow mutable references to that singleton object so that I can do fast 'is' tests. I declared this class Category { protected static immutable Category instance_ = ne

std.signals Can not connect a delegate without in Object

2016-04-29 Thread Dsby via Digitalmars-d-learn
import std.signals; import std.stdio; class hh { mixin Signal!(); void haha(){emit();} } class ff { void show() { writeln("ff show"); } } void main() { auto h = new hh(); void show() { writeln("main show"); } auto f = new ff();

Re: Shallow copy object when type is know

2016-04-21 Thread rumbu via Digitalmars-d-learn
On Wednesday, 20 April 2016 at 12:32:48 UTC, Tofu Ninja wrote: Is there a way to shallow copy an object when the type is known? I cant seem to figure out if there is a standard way. I can't just implement a copy function for the class, I need a generic solution. extern (C) Object _d_new

Re: Shallow copy object when type is know

2016-04-21 Thread Marc Schütz via Digitalmars-d-learn
On Wednesday, 20 April 2016 at 19:58:15 UTC, Tofu Ninja wrote: How does D not have shallow copy? Seems like a very basic functionality... You could implement a `dup()` method. `dup` is already used for shallow copying of arrays, why not reuse it for classes (as a convention)?

Re: Shallow copy object when type is know

2016-04-21 Thread Rene Zwanenburg via Digitalmars-d-learn
On Wednesday, 20 April 2016 at 19:58:15 UTC, Tofu Ninja wrote: To implement a copy/paste/duplicate functionality in a game editor. I have an entity-component system, to duplicate an entity, all it's components need to be duplicated. I have many many components, I don't want to rely on manually

Re: Shallow copy object when type is know

2016-04-20 Thread Tofu Ninja via Digitalmars-d-learn
On Wednesday, 20 April 2016 at 18:48:58 UTC, Alex Parrill wrote: On Wednesday, 20 April 2016 at 12:32:48 UTC, Tofu Ninja wrote: Is there a way to shallow copy an object when the type is known? I cant seem to figure out if there is a standard way. I can't just implement a copy function fo

Re: Shallow copy object when type is know

2016-04-20 Thread Alex Parrill via Digitalmars-d-learn
On Wednesday, 20 April 2016 at 12:32:48 UTC, Tofu Ninja wrote: Is there a way to shallow copy an object when the type is known? I cant seem to figure out if there is a standard way. I can't just implement a copy function for the class, I need a generic solution. A generic class copy fun

Re: Shallow copy object when type is know

2016-04-20 Thread Tofu Ninja via Digitalmars-d-learn
On Wednesday, 20 April 2016 at 12:32:48 UTC, Tofu Ninja wrote: Is there a way to shallow copy an object when the type is known? I cant seem to figure out if there is a standard way. I can't just implement a copy function for the class, I need a generic solution. I feel like

Shallow copy object when type is know

2016-04-20 Thread Tofu Ninja via Digitalmars-d-learn
Is there a way to shallow copy an object when the type is known? I cant seem to figure out if there is a standard way. I can't just implement a copy function for the class, I need a generic solution.

Re: Get address of object in constructor.

2016-03-13 Thread Adam D. Ruppe via Digitalmars-d-learn
On Sunday, 13 March 2016 at 16:16:55 UTC, MGW wrote: void* thisAddr = cast(void*) &this; This doesn't really make sense anyway, this is a local variable, you want to do cast(void*) this in a class if you need the address (which btw, you shouldn't actually, the reference itself ought to be en

Re: Get address of object in constructor.

2016-03-13 Thread MGW via Digitalmars-d-learn
On Sunday, 13 March 2016 at 16:02:07 UTC, WebFreak001 wrote: However note that this is not the same as that function. cast(void*)this and &this are 2 different things. So if you want to do the same as saveThis just do void* thisAddr = cast(void*) &this; instead void* thisAddr = cast(void*) &t

Re: Get address of object in constructor.

2016-03-13 Thread WebFreak001 via Digitalmars-d-learn
On Sunday, 13 March 2016 at 15:43:02 UTC, MGW wrote: Cfoo foo = new Cfoo(); foo.saveThis(&foo); However note that this is not the same as that function. cast(void*)this and &this are 2 different things. So if you want to do the same as saveThis just do void* thisAddr = cast(void*) &this; ins

Re: Get address of object in constructor.

2016-03-13 Thread MGW via Digitalmars-d-learn
On Sunday, 13 March 2016 at 15:49:20 UTC, WebFreak001 wrote: On Sunday, 13 March 2016 at 15:43:02 UTC, MGW wrote: I want to get address of object Cfoo in constructor. Whether it is possible? class Cfoo { void* adrThis; this() { adrThis = cast(void*) this

Re: Get address of object in constructor.

2016-03-13 Thread WebFreak001 via Digitalmars-d-learn
On Sunday, 13 March 2016 at 15:43:02 UTC, MGW wrote: I want to get address of object Cfoo in constructor. Whether it is possible? class Cfoo { void* adrThis; this() { adrThis = cast(void*) this; } } ... Cfoo foo = new Cfoo(); "this" should

Get address of object in constructor.

2016-03-13 Thread MGW via Digitalmars-d-learn
I want to get address of object Cfoo in constructor. Whether it is possible? now: - class Cfoo { void* adrThis; void saveThis(void* adr) { adrThis = adr; } } ... Cfoo foo = new Cfoo(); foo.saveThis(&foo); shall be -- class Cfoo {

Re: in a template argument, specify which object member to access?

2016-02-08 Thread Mengu via Digitalmars-d-learn
On Monday, 8 February 2016 at 22:46:06 UTC, cy wrote: On Monday, 8 February 2016 at 22:38:45 UTC, Mengu wrote: i believe you can use __traits(getMember) there. Great! Should have refreshed before sending that reply... I wonder if mixin("a."~member) is better or worse than __traits(getMember,

Re: in a template argument, specify which object member to access?

2016-02-08 Thread cym13 via Digitalmars-d-learn
On Monday, 8 February 2016 at 22:46:06 UTC, cy wrote: On Monday, 8 February 2016 at 22:38:45 UTC, Mengu wrote: i believe you can use __traits(getMember) there. Great! Should have refreshed before sending that reply... I wonder if mixin("a."~member) is better or worse than __traits(getMember,

Re: in a template argument, specify which object member to access?

2016-02-08 Thread cy via Digitalmars-d-learn
On Monday, 8 February 2016 at 22:38:45 UTC, Mengu wrote: i believe you can use __traits(getMember) there. Great! Should have refreshed before sending that reply... I wonder if mixin("a."~member) is better or worse than __traits(getMember,a,member)...

Re: in a template argument, specify which object member to access?

2016-02-08 Thread cy via Digitalmars-d-learn
xin("a."~D3); } } void main() { import std.stdio; A a = {"north","south","east","west"}; writeln(goPlaces!("up","left","down")(a)); writeln(a.left); } top postin

Re: in a template argument, specify which object member to access?

2016-02-08 Thread Mengu via Digitalmars-d-learn
On Monday, 8 February 2016 at 21:09:47 UTC, cy wrote: object.member lets me access the member of the object, but what if I want to access those members in a generic way, but in a different arrangement depending on context? Like if I wanted to first follow a tree down, and second priority would

in a template argument, specify which object member to access?

2016-02-08 Thread cy via Digitalmars-d-learn
object.member lets me access the member of the object, but what if I want to access those members in a generic way, but in a different arrangement depending on context? Like if I wanted to first follow a tree down, and second priority would be going left to right, but then I wanted to first go

Re: How do you check if object o has base type B?

2016-02-04 Thread Gary Willoughby via Digitalmars-d-learn
On Thursday, 4 February 2016 at 05:51:22 UTC, Enjoys Math wrote: Consider: class C { } class B : C { } class A : B { } class D : C { } C[] objList; how do we test if objLis[k] is of base type "B"? Ie for [new A(), new B(), new D(), new C()] would give output [true, true, false, false]

How do you check if object o has base type B?

2016-02-03 Thread Enjoys Math via Digitalmars-d-learn
Consider: class C { } class B : C { } class A : B { } class D : C { } C[] objList; how do we test if objLis[k] is of base type "B"? Ie for [new A(), new B(), new D(), new C()] would give output [true, true, false, false]. ? Thank you! :D

Re: How do you check if object o has base type B?

2016-02-03 Thread Rikki Cattermole via Digitalmars-d-learn
T[] list; foreach(v; list) { if (SpecialT v2 = cast(SpecialT)v) { writeln(v2); } else { writeln("err"); } } That should work.

Re: How should I do object serialization?

2016-01-27 Thread Saurabh Das via Digitalmars-d-learn
my dmd source tree: v2.070.0-b2 So where is the /official/ home for D object serialization? Thanks. Give http://code.dlang.org/packages/cerealed a try.

How should I do object serialization?

2016-01-27 Thread Enjoys Math via Digitalmars-d-learn
I'm not looking for anything advanced, just serialization of some of my own types (classes & structs). I've seen: http://wiki.dlang.org/Review/std.serialization However, I don't see std.serialization in my dmd source tree: v2.070.0-b2 So where is the /official/ home for D o

Re: Create an empty json object with std.json

2016-01-22 Thread Chris Wright via Digitalmars-d-learn
a literal, using the > deprecated way or the "lazy" way. Which works out to one way that actually has the behavior that Andrea needs, and that involves parsing javascript. That's not ideal. Vibe.d has a static method 'emptyObject' that returns a new empty object. That would be handy here.

<    2   3   4   5   6   7   8   9   10   11   >