Re: Get largest heap object at runtime? ...tracking the leak

2018-01-21 Thread Dmitry Olshansky via Digitalmars-d-learn
On Sunday, 21 January 2018 at 17:28:13 UTC, Andres Clari wrote: Hi, is there any way to get from the GC all allocated objects, so I can see their size and find where I'm leaking memory? Or perhaps a good tool to help with this issue... I tried building my program with "profile-gc" but I got

Get largest heap object at runtime? ...tracking the leak

2018-01-21 Thread Andres Clari via Digitalmars-d-learn
Hi, is there any way to get from the GC all allocated objects, so I can see their size and find where I'm leaking memory? Or perhaps a good tool to help with this issue... I tried building my program with "profile-gc" but I got an invalid MemoryOperationError with no stack trace... so no luck

Re: Alias to single function of object inside class

2018-01-16 Thread Ali Çehreli via Digitalmars-d-learn
On 01/16/2018 11:00 AM, ARaspiK wrote: I have a class Foo, which has functions a(), b(), and c(). I have a class Bar that has baz, an instance of Foo. How do I link Bar.b() -> baz.b() without also linking Foo.a() and Foo.c()? I know we can do an alias this, but I only want to link over b().

Alias to single function of object inside class

2018-01-16 Thread ARaspiK via Digitalmars-d-learn
I have a class Foo, which has functions a(), b(), and c(). I have a class Bar that has baz, an instance of Foo. How do I link Bar.b() -> baz.b() without also linking Foo.a() and Foo.c()? I know we can do an alias this, but I only want to link over b().

Re: Error: non-shared method Node.~this is not callable using a shared object

2018-01-06 Thread Binghoo Dang via Digitalmars-d-learn
object Is this a bug ? Node.~this is not called from Stack. take a look at http://ddili.org/ders/d.en/struct.html constructor and destructor for struct must be static.

Error: non-shared method Node.~this is not callable using a shared object

2018-01-06 Thread ChangLong via Digitalmars-d-learn
This code is not working. --- shared struct Stack { Node n = void ; } struct Node { ~this() {} } --- Error: non-shared method test.Node.~this is not callable using a shared object Is this a bug ? Node.~this is not called from Stack.

Re: Object oriented programming and interfaces

2017-12-05 Thread Steven Schveighoffer via Digitalmars-d-learn
{...} } The compiler says: Error: class Item interface function 'float distance(Medoid other)' is not implemented Is there a way to implement the Item.distance() member function taking any object whose class is Item? You are thinking about covariance and contravariance. In D, only the return value can

Re: Object oriented programming and interfaces

2017-12-05 Thread Jesse Phillips via Digitalmars-d-learn
@property {...} } The compiler says: Error: class Item interface function 'float distance(Medoid other)' is not implemented Is there a way to implement the Item.distance() member function taking any object whose class is Item? I think everyone here has missed the reason. The problem

Re: Object oriented programming and interfaces

2017-12-05 Thread Adam D. Ruppe via Digitalmars-d-learn
: you can generically test that two objects are of the same class through their interfaces by checking: if(typeid(cast(Object) o1) == typeid(cast(Object) o2)) { // same class } else { // same interface, but different class } Might be useful for your classifier, though checking the nan

Re: Object oriented programming and interfaces

2017-12-05 Thread bauss via Digitalmars-d-learn
On Tuesday, 5 December 2017 at 08:08:55 UTC, Daniel Kozak wrote: You can do something like this: interface Medoid(T) { float distance( T other ); uint id() const @property; } class Item : Medoid!(Item) { float distance( Item m ) { return 0.;} uint id() const @property { return

Re: Object oriented programming and interfaces

2017-12-05 Thread Daniel Kozak via Digitalmars-d-learn
You can do something like this: interface Medoid(T) { float distance( T other ); uint id() const @property; } class Item : Medoid!(Item) { float distance( Item m ) { return 0.;} uint id() const @property { return 1; } } class MedoidClassification { this(T:Medoid!T)(T[] list)

Re: Object oriented programming and interfaces

2017-12-05 Thread Andrea Fontana via Digitalmars-d-learn
On Tuesday, 5 December 2017 at 07:47:32 UTC, Dirk wrote: What would be a good way to implement this? Did you tried to use introspection?

Re: Object oriented programming and interfaces

2017-12-04 Thread Dirk via Digitalmars-d-learn
The distance function is implementation dependend and can only be computed between two objects of the same class (in this example the class is Item). My goal is to write a module for a k-medoids clustering algorithm. The class MedoidClassification shall be able to partition a list of objects

Re: Object oriented programming and interfaces

2017-12-04 Thread A Guy With a Question via Digitalmars-d-learn
On Monday, 4 December 2017 at 20:43:27 UTC, Dirk wrote: Hi! float distance( Medoid other ); float distance( Item i ) {...} The two signatures need to be the same. I think this is true of most OOP languages. Have them both be: float distance( Medoid other );

Re: Object oriented programming and interfaces

2017-12-04 Thread Jacob Carlborg via Digitalmars-d-learn
{...} } The compiler says: Error: class Item interface function 'float distance(Medoid other)' is not implemented Is there a way to implement the Item.distance() member function taking any object whose class is Item? I don't think so. In the "Item" class you have declared "distance"

Re: Object oriented programming and interfaces

2017-12-04 Thread Craig Dillabaugh via Digitalmars-d-learn
@property {...} } The compiler says: Error: class Item interface function 'float distance(Medoid other)' is not implemented Is there a way to implement the Item.distance() member function taking any object whose class is Item? Interfaces are expected to implement static or final functions. See

Re: Object oriented programming and interfaces

2017-12-04 Thread Adam D. Ruppe via Digitalmars-d-learn
says: Error: class Item interface function 'float distance(Medoid other)' is not implemented Is there a way to implement the Item.distance() member function taking any object whose class is Item? So what would happen there if someone did: Medoid i = new Item(); i.distance(new OtherMedoid

Object oriented programming and interfaces

2017-12-04 Thread Dirk via Digitalmars-d-learn
interface function 'float distance(Medoid other)' is not implemented Is there a way to implement the Item.distance() member function taking any object whose class is Item?

Re: Taking a constant reference to a constant/non const object

2017-11-15 Thread Steven Schveighoffer via Digitalmars-d-learn
:04:50 helxi via Digitalmars-d-learn wrote: Hi. What function signature should I use for receiving a constant reference of an r/l value object? Is it auto fn(inout ref const myClass obj)? I want to: 1. Take a constant reference of the object, not copy them 2. The object itself may be const or non

Re: Taking a constant reference to a constant/non const object

2017-11-15 Thread Jonathan M Davis via Digitalmars-d-learn
er 15, 2017 09:04:50 helxi via > >> > >> Digitalmars-d-learn wrote: > >>> Hi. What function signature should I use for receiving a > >>> constant > >>> reference of an r/l value object? Is it auto fn(inout ref > >>> const > >>> myClas

Re: Taking a constant reference to a constant/non const object

2017-11-15 Thread helxi via Digitalmars-d-learn
/l value object? Is it auto fn(inout ref const myClass obj)? I want to: 1. Take a constant reference of the object, not copy them 2. The object itself may be const or non const. ref const(Type) would be the const version of ref Type. e.g. auto foo(ref const(int) i) {...} - Jonathan M Davis

Re: Taking a constant reference to a constant/non const object

2017-11-15 Thread helxi via Digitalmars-d-learn
On Wednesday, 15 November 2017 at 09:23:53 UTC, Jonathan M Davis wrote: On Wednesday, November 15, 2017 09:04:50 helxi via Digitalmars-d-learn wrote: Hi. What function signature should I use for receiving a constant reference of an r/l value object? Is it auto fn(inout ref const myClass obj

Re: Taking a constant reference to a constant/non const object

2017-11-15 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, November 15, 2017 09:04:50 helxi via Digitalmars-d-learn wrote: > Hi. What function signature should I use for receiving a constant > reference of an r/l value object? Is it auto fn(inout ref const > myClass obj)? > I want to: > 1. Take a constant reference of the o

Taking a constant reference to a constant/non const object

2017-11-15 Thread helxi via Digitalmars-d-learn
Hi. What function signature should I use for receiving a constant reference of an r/l value object? Is it auto fn(inout ref const myClass obj)? I want to: 1. Take a constant reference of the object, not copy them 2. The object itself may be const or non const.

Re: How do i find a list of the methods Object implements, or maybe just locate the 'write' method?

2017-11-08 Thread codephantom via Digitalmars-d-learn
On Wednesday, 8 November 2017 at 12:48:41 UTC, codephantom wrote: Apparently its a bug in LDC (but personally, it's a bug I like). mistyped: I meant a bug in GDC, not LDC.

Re: How do i find a list of the methods Object implements, or maybe just locate the 'write' method?

2017-11-08 Thread codephantom via Digitalmars-d-learn
On Wednesday, 8 November 2017 at 12:17:14 UTC, bauss wrote: That's because the module name becomes `write` then. yeah I knew that. I was trying to demonstrate how (when the module name is 'write'), then the compiler is ok with: o.write; but not: write(o); even though semantically they

Re: How do i find a list of the methods Object implements, or maybe just locate the 'write' method?

2017-11-08 Thread bauss via Digitalmars-d-learn
or something. You could get around the error using an alias: ``` module write; import std.stdio; alias write = std.stdio.write; // <<<<<< void main() { auto o = new Object; o.write; write(o); } ```

Re: How do i find a list of the methods Object implements, or maybe just locate the 'write' method?

2017-11-07 Thread codephantom via Digitalmars-d-learn
On Wednesday, 8 November 2017 at 03:33:08 UTC, bauss wrote: -- Compiles fine with DMD: https://dpaste.dzfl.pl/95b896aa242f ahh.. that site saves it with some random temporary file name I assume. If it saved it as

Re: How do i find a list of the methods Object implements, or maybe just locate the 'write' method?

2017-11-07 Thread codephantom via Digitalmars-d-learn
On Wednesday, 8 November 2017 at 03:33:08 UTC, bauss wrote: -- Compiles fine with DMD: https://dpaste.dzfl.pl/95b896aa242f you saved it as?: write.d you didn't add in a module statement? and it compiled??

Re: How do i find a list of the methods Object implements, or maybe just locate the 'write' method?

2017-11-07 Thread bauss via Digitalmars-d-learn
named: write.d import std.stdio; void main() { auto o = new Object; // One of statements below will prevent this code from compiling. // Which one do you think it is? // btw. If I instead use gdc on debian, then it will // compile both statements just fine, and will work

Re: How do i find a list of the methods Object implements, or maybe just locate the 'write' method?

2017-11-07 Thread codephantom via Digitalmars-d-learn
On Tuesday, 7 November 2017 at 21:32:26 UTC, Adam D. Ruppe wrote: On Tuesday, 7 November 2017 at 21:25:00 UTC, dan wrote: I looked in my distribution's object.d (debian stretch, gdc, in Did you import std.stdio in the file? If so, it is calling the std.stdio.write on the object

Re: How do i find a list of the methods Object implements, or maybe just locate the 'write' method?

2017-11-07 Thread dan via Digitalmars-d-learn
On Tuesday, 7 November 2017 at 21:32:26 UTC, Adam D. Ruppe wrote: On Tuesday, 7 November 2017 at 21:25:00 UTC, dan wrote: I looked in my distribution's object.d (debian stretch, gdc, in Did you import std.stdio in the file? If so, it is calling the std.stdio.write on the object

Re: How do i find a list of the methods Object implements, or maybe just locate the 'write' method?

2017-11-07 Thread Adam D. Ruppe via Digitalmars-d-learn
On Tuesday, 7 November 2017 at 21:25:00 UTC, dan wrote: I looked in my distribution's object.d (debian stretch, gdc, in Did you import std.stdio in the file? If so, it is calling the std.stdio.write on the object (this is called UFCS, uniform function call syntax, the language allows you

How do i find a list of the methods Object implements, or maybe just locate the 'write' method?

2017-11-07 Thread dan via Digitalmars-d-learn
I was writing some code and added a line like x.write; expecting to fill it in later. I forgot to actually write a function write, but it compiled anyway, and some testing shows that if you write auto o = new Object; o.write; then this compiles just fine. (The 'write' method

Re: Get which derived class an object is if it's stored in an array of its base class

2017-07-15 Thread Morimur55 via Digitalmars-d-learn
On Saturday, 15 July 2017 at 14:46:17 UTC, Adam D. Ruppe wrote: On Saturday, 15 July 2017 at 14:36:40 UTC, Morimur55 wrote: ...let me try that again without accidentally sending it before I'd finished... tab on the web interface is so useful... but so annoying sometimes too. ...and I think

Re: Get which derived class an object is if it's stored in an array of its base class

2017-07-15 Thread Adam D. Ruppe via Digitalmars-d-learn
On Saturday, 15 July 2017 at 14:36:40 UTC, Morimur55 wrote: ...let me try that again without accidentally sending it before I'd finished... tab on the web interface is so useful... but so annoying sometimes too. ...and I think my problem is actually that redeclared static variables update

Re: Get which derived class an object is if it's stored in an array of its base class

2017-07-15 Thread Morimur55 via Digitalmars-d-learn
On Saturday, 15 July 2017 at 14:26:30 UTC, Morimur55 wrote: On Saturday, 15 July 2017 at 14:04:17 UTC, Adam D. Ruppe wrote: On Saturday, 15 July 2017 at 13:45:40 UTC, Morimur55 wrote: Well I want to cast to the derived type so I can use a method that's defined in the base class, but is

Re: Get which derived class an object is if it's stored in an array of its base class

2017-07-15 Thread Morimur55 via Digitalmars-d-learn
On Saturday, 15 July 2017 at 14:04:17 UTC, Adam D. Ruppe wrote: On Saturday, 15 July 2017 at 13:45:40 UTC, Morimur55 wrote: Well I want to cast to the derived type so I can use a method that's defined in the base class, but is overridden in several of the derived types... and calling it

Re: Get which derived class an object is if it's stored in an array of its base class

2017-07-15 Thread Nicholas Wilson via Digitalmars-d-learn
by that doesn't give a lot of info. Casting is how you actually get the object, though you might be better off putting the necessary methods in the base class. Well I want to cast to the derived type so I can use a method that's defined in the base class, but is overridden in several of the derived types

Re: Get which derived class an object is if it's stored in an array of its base class

2017-07-15 Thread Adam D. Ruppe via Digitalmars-d-learn
On Saturday, 15 July 2017 at 13:45:40 UTC, Morimur55 wrote: Well I want to cast to the derived type so I can use a method that's defined in the base class, but is overridden in several of the derived types... and calling it without a cast seems to give me the base type functionality, but I'd

Re: Get which derived class an object is if it's stored in an array of its base class

2017-07-15 Thread Morimur55 via Digitalmars-d-learn
by that doesn't give a lot of info. Casting is how you actually get the object, though you might be better off putting the necessary methods in the base class. Well I want to cast to the derived type so I can use a method that's defined in the base class, but is overridden in several of the derived

Re: Get which derived class an object is if it's stored in an array of its base class

2017-07-15 Thread Adam D. Ruppe via Digitalmars-d-learn
the object, though you might be better off putting the necessary methods in the base class.

Get which derived class an object is if it's stored in an array of its base class

2017-07-15 Thread Morimur55 via Digitalmars-d-learn
I've got a bunch of different classes all derived from the same base class sitting in a base[]. I need to check what the derived types are of these objects - is there a way to check without attempting to cast to every derived type?

Re: How to check if object is an instance of generic class?

2017-05-03 Thread Nothing via Digitalmars-d-learn
: [...] So is there an idiomatic approach to know if the Object is an instance of Box (regardless of content type T) and than if necessary to know exactly if two boxes have same concrete type T? If the types of the Boxes are known at compile-time, you could make opEquals a template, like

Re: How to check if object is an instance of generic class?

2017-05-03 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, May 03, 2017 at 08:24:31PM +0200, ag0aep6g via Digitalmars-d-learn wrote: > On 05/03/2017 08:04 PM, H. S. Teoh via Digitalmars-d-learn wrote: > > You only need a common interface if you wish to do something more > > with Box!X instantiations that's common across all Boxes. > > The goal

Re: How to check if object is an instance of generic class?

2017-05-03 Thread ag0aep6g via Digitalmars-d-learn
On 05/03/2017 08:04 PM, H. S. Teoh via Digitalmars-d-learn wrote: You only need a common interface if you wish to do something more with Box!X instantiations that's common across all Boxes. The goal is to return `true` for two empty boxes with different payload types. From the OP: "Empty

Re: How to check if object is an instance of generic class?

2017-05-03 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, May 03, 2017 at 08:04:20PM +0200, ag0aep6g via Digitalmars-d-learn wrote: > On 05/03/2017 07:26 PM, Nothing wrote: [...] > > So is there an idiomatic approach to know if the Object is an > > instance of Box (regardless of content type T) and than if necessary > > t

Re: How to check if object is an instance of generic class?

2017-05-03 Thread ag0aep6g via Digitalmars-d-learn
On 05/03/2017 07:26 PM, Nothing wrote: Equality checking is where I stuck. It should work as follows: 0. If we compare the Box [b]b[/b] to an object [b]o[/b] that is not an instance of Box, it should return false. 1. Empty boxes are equal no matter the type. 2. If type of payload for two boxes

Re: How to check if object is an instance of generic class?

2017-05-03 Thread H. S. Teoh via Digitalmars-d-learn
y type T. Have a look at std.variant.Variant and std.typecons.Nullable. The combination of these two may already do what you want. But of course, if you wish to write your own Box type, then to answer your question: [...] > So is there an idiomatic approach to know if the Object is an instance &g

How to check if object is an instance of generic class?

2017-05-03 Thread Nothing via Digitalmars-d-learn
Hi, Honestly I am new to D and templates system so excuse me if my question will seem trivial. I want to develop a generic Box(T) class that can be either empty or hold a value of arbitrary type T. // class Box(T) { override bool opEquals(Object o

Re: Member delegate/fp to another member in same object?

2017-05-02 Thread Adam D. Ruppe via Digitalmars-d-learn
On Tuesday, 2 May 2017 at 17:08:11 UTC, Juanjo Alvarez wrote: struct S { int someState; void some_foo() { return this. someState;} void delegate() foo; void enable() { foo = _foo; } } That's actually illegal in D. It will compile, but has undefined behavior because the

Re: Member delegate/fp to another member in same object?

2017-05-02 Thread Juanjo Alvarez via Digitalmars-d-learn
); // fails because the delegate keeps // the state of the object at the // assignment point } Forget it. I just noticed the simplified example that I just posted works (once the typo of the return value is corrected) but my more complex real code won't, will try to get a simple snippet

Member delegate/fp to another member in same object?

2017-05-02 Thread Juanjo Alvarez via Digitalmars-d-learn
Hi! I would like to have a "proxy" delegate, let's call it "foo" that could point to a method or another, let's call them "fast_foo" or "slow_foo" on the same object. This way depending on some conditions I could switch at runtime from one set of met

Re: Filter out common object functions

2017-03-14 Thread Inquie via Digitalmars-d-learn
On Tuesday, 14 March 2017 at 19:43:59 UTC, Adam D. Ruppe wrote: On Tuesday, 14 March 2017 at 19:39:26 UTC, Inquie wrote: __traits(allMembers, T); Try derivedMembers instead. That doesn't work, unfortunately, probably because of the types I'm using(just returns object. What I can do

Re: Filter out common object functions

2017-03-14 Thread Adam D. Ruppe via Digitalmars-d-learn
On Tuesday, 14 March 2017 at 19:39:26 UTC, Inquie wrote: __traits(allMembers, T); Try derivedMembers instead.

Filter out common object functions

2017-03-14 Thread Inquie via Digitalmars-d-learn
I am iterating over the members of classes and interfaces and get things like hash, this, etc. These are causing problems in my code. I would like to get only the "specified" members. While I can filter out __traits(allMembers, T); using Erase, it is tedius and error prone. Is there a way

How can I get changed members in class object?

2017-03-13 Thread donglei via Digitalmars-d-learn
In hibernate,update object is set all table columns to sql. code for example: ``` //orm entity class User { int id; string firstName; string lastName; } Session sess = factory.openSession(); User user =sess.createQuery("FROM User WHERE first_name=:firs

Re: Get the address of an object, within the object itself

2017-02-16 Thread Jacob Carlborg via Digitalmars-d-learn
On 2017-02-15 22:42, Andrew Chapman wrote: Thanks Jonathan. Good point about the reference address. I can work around this quite easily, but I was curious. I will try the void* cast and see what happens. If it's only for printing you can use the C "printf" without any casting: import

Re: Get the address of an object, within the object itself

2017-02-15 Thread Andrew Chapman via Digitalmars-d-learn
lly, but is it possible > to get the address of an object within the object itself? > > e.g. > > class Node > { > > this() > { > > writeln(); // Doesn't work > > } > > } > > auto node = new Node(); > writeln(); // Does work

Re: Get the address of an object, within the object itself

2017-02-15 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, February 15, 2017 13:33:23 Jonathan M Davis via Digitalmars-d- learn wrote: > On Wednesday, February 15, 2017 21:27:00 Andrew Chapman via Digitalmars-d- > learn wrote: > > Hi all, sorry if this question is silly, but is it possible to > > get the address o

Re: Get the address of an object, within the object itself

2017-02-15 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, February 15, 2017 21:27:00 Andrew Chapman via Digitalmars-d- learn wrote: > Hi all, sorry if this question is silly, but is it possible to > get the address of an object within the object itself? > > e.g. > > class Node > { > this() > { >

Get the address of an object, within the object itself

2017-02-15 Thread Andrew Chapman via Digitalmars-d-learn
Hi all, sorry if this question is silly, but is it possible to get the address of an object within the object itself? e.g. class Node { this() { writeln(); // Doesn't work } } auto node = new Node(); writeln(); // Does work Thanks very much, Cheers, Andrew.

Object function cannot change member when called from callback?

2017-01-24 Thread David Zhang via Digitalmars-d-learn
So I have a window (Windows), and my wndProc is basically the same as the one on the windows guides. However, even though WM_CLOSE gets passed (and I can use if(msg == WM_CLOSE)), I can't seem to set my shouldClose flag. I've confirmed that I still get the event within my processMessage

Re: Unexpected behavior when using both alias this and object pointer

2017-01-12 Thread xiren7 via Digitalmars-d-learn
Thanks. Ali. My previous post is not clear that I have to store class reference(object pointer) in void*. My actual code is try to use libuv in D. // genarated from uv.h, only two fields is used: 'data', 'type'. // the document of 'data': "Space for user-defined arbitrary data. libuv

Re: Unexpected behavior when using both alias this and object pointer

2017-01-12 Thread Ali Çehreli via Digitalmars-d-learn
Hiding a Foo right after Impl can be a solution. However, you need to pass 't', not '' to the C function because - Although it may be unexpected, cast(void*) is the specified way of getting the address of a class object - Taking the address of a class reference (which 't' is one), is just

Unexpected behavior when using both alias this and object pointer

2017-01-12 Thread xiren7 via Digitalmars-d-learn
auto payload = (cast(T) cast(void*) t).payload; // -> crashs // the right way to get the address of the t object writeln(*cast(void**) ); // -> 278E3373000 // the unexpected behavior // the obvious(but wrong) way to get the address of the t object writeln(cas

Re: opOpAssign on object properties

2017-01-08 Thread collerblade via Digitalmars-d-learn
On Sunday, 8 January 2017 at 21:50:12 UTC, Ivan Kazmenko wrote: On Sunday, 8 January 2017 at 18:23:34 UTC, collerblade wrote: [...] Hmm, right. The setter is not called, and it's by the spec. Which says that "a op= b" is rewritten as "a.opOpAssign !(op) (b)". Here:

Re: opOpAssign on object properties

2017-01-08 Thread Ivan Kazmenko via Digitalmars-d-learn
On Sunday, 8 January 2017 at 18:23:34 UTC, collerblade wrote: On Sunday, 8 January 2017 at 10:03:50 UTC, Ivan Kazmenko wrote: On Sunday, 8 January 2017 at 09:22:12 UTC, collerblade wrote: [...] 1. If you want the member variable to change, naturally, you should provide a getter property

Re: opOpAssign on object properties

2017-01-08 Thread collerblade via Digitalmars-d-learn
On Sunday, 8 January 2017 at 10:03:50 UTC, Ivan Kazmenko wrote: On Sunday, 8 January 2017 at 09:22:12 UTC, collerblade wrote: [...] 1. If you want the member variable to change, naturally, you should provide a getter property which returns a reference to that variable: [...] yes i tried

Re: opOpAssign on object properties

2017-01-08 Thread Ivan Kazmenko via Digitalmars-d-learn
On Sunday, 8 January 2017 at 09:22:12 UTC, collerblade wrote: How can i do opOpAssign with properties?? 1. If you want the member variable to change, naturally, you should provide a getter property which returns a reference to that variable: ref Point location() @property {

opOpAssign on object properties

2017-01-08 Thread collerblade via Digitalmars-d-learn
hello guys, i would like to have properties with /= *= += -= operators. My code: struct Point { float x=0,y=0; this(float _x, float _y) { x=_x; y=_y; } //opassign for + //opopassign for += void opOpAssign(string op=="+")(in Point p) { x+=p.x; y+=p.y; } } class

Re: Allocating a class within another class during object init w/o passing in an allocator

2016-12-16 Thread ag0aep6g via Digitalmars-d-learn
On Friday, 16 December 2016 at 18:25:42 UTC, David Zhang wrote: I though all classes were aligned to sizeof(size_t) boundaries? I don't know. Wouldn't it then just be align(sizeof(size_t)) byte[__traits(classInstanceSize, SomeClass)] scStorage; I guess? I really don't have much of a

Re: Allocating a class within another class during object init w/o passing in an allocator

2016-12-16 Thread David Zhang via Digitalmars-d-learn
I haven't considered alignment here. I'm not sure if you have to. I though all classes were aligned to sizeof(size_t) boundaries? Wouldn't it then just be align(sizeof(size_t)) byte[__traits(classInstanceSize, SomeClass)] scStorage;

Re: Allocating a class within another class during object init w/o passing in an allocator

2016-12-15 Thread ag0aep6g via Digitalmars-d-learn
On Thursday, 15 December 2016 at 21:37:34 UTC, David Zhang wrote: So the size of Foo would be the size of SomeClass plus members? ie. Is the size of the array stored too? With these definitions: class SomeClass {} class Foo { this() { import std.conv: emplace;

Re: Allocating a class within another class during object init w/o passing in an allocator

2016-12-15 Thread David Zhang via Digitalmars-d-learn
On Thursday, 15 December 2016 at 21:08:51 UTC, ag0aep6g wrote: On 12/15/2016 09:51 PM, David Zhang wrote: However, it leaves me with another question, how much (if any) space would the static array require from the class? Depends on SomeClass. The array's size is just the value of

Re: Allocating a class within another class during object init w/o passing in an allocator

2016-12-15 Thread David Zhang via Digitalmars-d-learn
Thank you for your responses. Visitor, I don't want any reference to an allocator within the class if I can avoid it. ag0aep6g, thanks! That's what I was looking for. However, it leaves me with another question, how much (if any) space would the static array require from the class? It's not a

Re: Allocating a class within another class during object init w/o passing in an allocator

2016-12-15 Thread ag0aep6g via Digitalmars-d-learn
to allocate Foo using std.experimental.allocator without having to pass in a reference to the actual allocator. Add a fixed-size array with an appropiate size to the class, and use std.conv.emplace to construct the object there: class SomeClass {} class Foo { this() { import

Re: Allocating a class within another class during object init w/o passing in an allocator

2016-12-15 Thread visitor via Digitalmars-d-learn
On Thursday, 15 December 2016 at 17:44:23 UTC, David Zhang wrote: would something like this be a solution ? import std.stdio; import std.experimental.allocator; class SomeClass { int someint = 42; static SomeClass opCall(int a) { auto inst = theAllocator.make!SomeClass;

Allocating a class within another class during object init w/o passing in an allocator

2016-12-15 Thread David Zhang via Digitalmars-d-learn
Hello, It is my understanding that a class can have a struct as one of its members, and it will be allocated in-line with the rest of the class' members. My question is this; how might I be able to do this with another class? I want to be able to allocate Foo using std.experimental.allocator

Re: How to get hash value of an object?

2016-12-11 Thread Seb via Digitalmars-d-learn
On Sunday, 4 December 2016 at 13:17:09 UTC, Era Scarecrow wrote: On Tuesday, 29 November 2016 at 00:05:31 UTC, Steven Schveighoffer wrote: hashOf is kind of this horrible hacky thing that nobody should be using. It literally takes whatever you pass it and hashes the local bytes. Ugg...

Re: How to get hash value of an object?

2016-12-04 Thread Era Scarecrow via Digitalmars-d-learn
with consistency; While anything with fixed static arrays or pure value-types will result in proper values. I'd almost prefer an option to get hashOf all inner object types and then xor them all together. Although this could make for a very complex hashOf depending on implementation of the object

Re: How to get hash value of an object?

2016-11-28 Thread Steven Schveighoffer via Digitalmars-d-learn
On 11/27/16 2:10 AM, panmengh wrote: How to get hash value of an object? Use hashOf? or typeid(T).getHash()? hashOf is kind of this horrible hacky thing that nobody should be using. It literally takes whatever you pass it and hashes the local bytes. It doesn't care about opHash or if any

How to get hash value of an object?

2016-11-26 Thread panmengh via Digitalmars-d-learn
How to get hash value of an object? Use hashOf? or typeid(T).getHash()? I test with the following code: System: windows 10 dmd --version DMD32 D Compiler v2.072.0 (official download version) ldc2 --version LDC - the LLVM D compiler (1.1.0git-62a2252) (the latest git master version) based

Re: Linking g++ compiled object files

2016-11-24 Thread Mike Parker via Digitalmars-d-learn
On Thursday, 24 November 2016 at 20:09:29 UTC, Rubikoid wrote: So, is there any way to use gcc/g++ under windows? DMD can work with COFF objects when given -m32mscoff when compiling 32-bit and -m64 for 64-bit. In both cases, yoi will need the Microsoft linker and SDK intalled. However, when

Re: Linking g++ compiled object files

2016-11-24 Thread Rubikoid via Digitalmars-d-learn
On Thursday, 24 November 2016 at 17:37:51 UTC, Basile B. wrote: * Under windows 32 bit: - create the object: Use digital mars C/C++ (dmc) to create an OMF object (GCC would produce COFF) then - link: dmd test.d test.obj So, is there any way to use gcc/g++ under windows? Note

Re: Linking g++ compiled object files

2016-11-24 Thread Basile B. via Digitalmars-d-learn
++ to link it normally? * Under linux: - create the object g++ -c test.cpp - link: dmd test.d test.o * Under windows 32 bit: - create the object: Use digital mars C/C++ (dmc) to create an OMF object (GCC would produce COFF) then - link: dmd test.d test.obj Note that in both ca

Linking g++ compiled object files

2016-11-23 Thread Rubikoid via Digitalmars-d-learn
For example, i have test.cpp: #include void test() { printf("test\n"); } And test.d: import std.stdio; extern (C++) void test(); void main() { test(); readln(); } How i should compile test.cpp using g++ to link it normally?

Re: Lazily evaluated property pointing to read only object

2016-09-27 Thread vit via Digitalmars-d-learn
_o" as a non-const and then convert it to cost on the way out. However To store it as const I guess I'd have to make it a non-const pointer to a const object, and is that not kind of what immutable is? Yes, the problem is that if you want to create a true const(Object) (with const p

Re: Lazily evaluated property pointing to read only object

2016-09-24 Thread Basile B. via Digitalmars-d-learn
wever To store it as const I guess I'd have to make it a non-const pointer to a const object, and is that not kind of what immutable is? Yes, the problem is that if you want to create a true const(Object) (with const part of the type) you have to initialize it in a constructor (so no lazyne

Re: Lazily evaluated property pointing to read only object

2016-09-24 Thread mikey via Digitalmars-d-learn
see were to have "_o" as a const or immutable type and just create a const on the first call to the lazily evaluated property, or to do what I did and have "_o" as a non-const and then convert it to cost on the way out. However To store it as const I guess I'd have to make i

Re: Lazily evaluated property pointing to read only object

2016-09-24 Thread Basile B. via Digitalmars-d-learn
On Saturday, 24 September 2016 at 09:08:52 UTC, mikey wrote: I'm trying to figure out how to best write a class with a property that is only evaluated when it's called for the first time. And that returns an object which shouldn't be modifiable a part of the owning class. I've had a go

Lazily evaluated property pointing to read only object

2016-09-24 Thread mikey via Digitalmars-d-learn
I'm trying to figure out how to best write a class with a property that is only evaluated when it's called for the first time. And that returns an object which shouldn't be modifiable a part of the owning class. I've had a go at doing something like this but am not very sure if this is how

Re: setting fields of object using traits

2016-09-21 Thread Jacob Carlborg via Digitalmars-d-learn
On 2016-09-20 21:45, Ram_B wrote: I'm trying to set fields of object from JSON with traits library. How i can to it properly? import std.stdio; import std.json; import std.traits; import std.meta: Alias; class Obj{ void fromJSON(this T)(JSONValue j){ foreach(field; FieldNameTuple

setting fields of object using traits

2016-09-20 Thread Ram_B via Digitalmars-d-learn
I'm trying to set fields of object from JSON with traits library. How i can to it properly? import std.stdio; import std.json; import std.traits; import std.meta: Alias; class Obj{ void fromJSON(this T)(JSONValue j){ foreach(field; FieldNameTuple!T

Re: DUB, link automatically right object for platform and archi

2016-09-02 Thread Basile B. via Digitalmars-d-learn
, this explains why the JSON object was missing. dflags is valid in top level config, subPackage and of course configuration.

Re: DUB, link automatically right object for platform and archi

2016-09-01 Thread rikki cattermole via Digitalmars-d-learn
["objects/coff32/beaengine.o"], "dflags-linux-x86_64" : ["objects/coff64/beaengine.o"], "dflags-windows-x86" : ["objects\\omf32\\beaengine.obj"] }, Because previously the right config could not be selected when the package was

Re: DUB, link automatically right object for platform and archi

2016-09-01 Thread Basile B. via Digitalmars-d-learn
uot;], "dflags-windows-x86" : ["objects\\omf32\\beaengine.obj"] }, Because previously the right config could not be selected when the package was used as dependency. But now the object is not linked in the static library produced by the project. What's wrong in my descrip

DUB, link automatically right object for platform and archi

2016-09-01 Thread Basile B. via Digitalmars-d-learn
;], "dflags-linux-x86_64" : ["objects/coff64/beaengine.o"], "dflags-windows-x86" : ["objects\\omf32\\beaengine.obj"] }, Because previously the right config could not be selected when the package was used as dependency. But now the object is not linked in the static library produced by the project. What's wrong in my description ?

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

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

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