Testing for object property supporting "<" comparison

2021-05-11 Thread Chris Piker via Digitalmars-d-learn
Hi D I'm working on a bit of code that handles selecting one *.front from multiple range-ish objects. It's a select-or-drop algorithm for a data streaming service, the details aren't important. The algorithm takes a range of something I'll call "PriorityRange" objects. PriorityRange

Re: Is there a generic type such as void* or C#'s object?

2021-02-07 Thread Jack via Digitalmars-d-learn
Thanks for your answers guys!

Re: Is there a generic type such as void* or C#'s object?

2021-02-05 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, Feb 06, 2021 at 02:01:28AM +, Jack via Digitalmars-d-learn wrote: > in C/C++ you have void* and C#'s object, to create a variable to hold > a genetic type. So in C# you can do: > > class A { > object foo; > } > > and > > var a = new A(); > a.foo

Re: Is there a generic type such as void* or C#'s object?

2021-02-05 Thread Paul Backus via Digitalmars-d-learn
On Saturday, 6 February 2021 at 02:01:28 UTC, Jack wrote: in C/C++ you have void* and C#'s object, to create a variable to hold a genetic type. So in C# you can do: class A { object foo; } and var a = new A(); a.foo = any class...; does D have something like this or template parameters

Is there a generic type such as void* or C#'s object?

2021-02-05 Thread Jack via Digitalmars-d-learn
in C/C++ you have void* and C#'s object, to create a variable to hold a genetic type. So in C# you can do: class A { object foo; } and var a = new A(); a.foo = any class...; does D have something like this or template parameters are used instead of?

Re: Field Initialiser Reused Across Object Instances

2021-01-01 Thread Adam via Digitalmars-d-learn
That's a fantastic answer! Thank you. I was not aware that initializers were always compile time, that was the missing piece in my understanding. It's a shame that I can't use the nicer (IMO) syntax, but the reasoning is sound.

Re: Field Initialiser Reused Across Object Instances

2021-01-01 Thread Adam D. Ruppe via Digitalmars-d-learn
nt outside a function is a compile time thing. Is this intended? Yes, it is a frequent thing to surprise people though. The reference there is part of the object but it points to the same default thing because of how that was made. Constructors are actually run at runtime, but in

Field Initialiser Reused Across Object Instances

2021-01-01 Thread Adam via Digitalmars-d-learn
ld expect one for each instance of B. The field is not marked static. Is this intended? My gut reaction is the compiler is memoising "new A" because purity is inferred, but doesn't that contradict the meaning of "new Class" which should always yield an object with it's own

Re: Can't pass [] to extern function object method

2020-11-19 Thread frame via Digitalmars-d-learn
On Thursday, 19 November 2020 at 07:46:20 UTC, Bastiaan Veelo wrote: On Wednesday, 18 November 2020 at 10:50:12 UTC, frame wrote: I found the "bug". It was caused by a debug {} statement within a struct method. I assume that the debug symbol is just incompatible called from the DLL context.

Re: Can't pass [] to extern function object method

2020-11-18 Thread Bastiaan Veelo via Digitalmars-d-learn
On Wednesday, 18 November 2020 at 10:50:12 UTC, frame wrote: I found the "bug". It was caused by a debug {} statement within a struct method. I assume that the debug symbol is just incompatible called from the DLL context. Were the DLL and main program built in different modes

Re: Can't pass [] to extern function object method

2020-11-18 Thread frame via Digitalmars-d-learn
On Monday, 16 November 2020 at 22:22:42 UTC, frame wrote: On Monday, 16 November 2020 at 21:58:44 UTC, Jack wrote: What is the function prototype like and how are you declaring that struct? The struct is very simple, it contains: I found the "bug". It was caused by a debug {} statement

Re: Can't pass [] to extern function object method

2020-11-16 Thread frame via Digitalmars-d-learn
On Monday, 16 November 2020 at 21:58:44 UTC, Jack wrote: What is the function prototype like and how are you declaring that struct? The struct is very simple, it contains: struct S { SysTime a; ulong b; double c; ubyte[] d; string e; } And I tried: bool foo(S[] params);

Re: Can't pass [] to extern function object method

2020-11-16 Thread Jack via Digitalmars-d-learn
On Monday, 16 November 2020 at 21:31:44 UTC, frame wrote: I have a DLL in D-code which returns an object and want to pass a struct S[] to a member function of that object. The first element is passed correctly, the rest is just garbage. In fact the next item is just a single byte with value

Can't pass [] to extern function object method

2020-11-16 Thread frame via Digitalmars-d-learn
I have a DLL in D-code which returns an object and want to pass a struct S[] to a member function of that object. The first element is passed correctly, the rest is just garbage. In fact the next item is just a single byte with value 0x11 following some 0x00. It doesn't matter if I'm using S

Re: Does dmd's -i "include imported modules in the compilation" switch generate object files?

2020-11-04 Thread Jacob Carlborg via Digitalmars-d-learn
and produces only a single object file for the final executable. Separate compilation only happens if you invoke the compiler separately for each source file or group of source files. If the `-c` flag is passed, the compiler will produce one object file for each source file. If the `-c` flag

Re: Does dmd's -i "include imported modules in the compilation" switch generate object files?

2020-11-03 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Nov 03, 2020 at 10:42:55AM -0800, Ali Çehreli via Digitalmars-d-learn wrote: > -i is a useful feature: > > https://dlang.org/dmd-linux.html > > Does dmd compile auto-included files separately? Does it generate > temporary object files? If so, where does it write t

Does dmd's -i "include imported modules in the compilation" switch generate object files?

2020-11-03 Thread Ali Çehreli via Digitalmars-d-learn
-i is a useful feature: https://dlang.org/dmd-linux.html Does dmd compile auto-included files separately? Does it generate temporary object files? If so, where does it write the files? Would -i cause race conditions on the file system? Thank you, Ali

Re: Given a TypeInfo_Class, instance a new object of its type

2020-10-26 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 26 October 2020 at 21:57:18 UTC, Not A Rectangle wrote: Is this possible to do? Only if you know the type ahead of time, then you can cast it. Normally you'd probably just know an interface or base class it implements then you can cast to that, with the exact derived type being

Given a TypeInfo_Class, instance a new object of its type

2020-10-26 Thread Not A Rectangle via Digitalmars-d-learn
Hi everyone, Say i have a TypeInfo_Class representing a custom type, and i want a new instance of this class with its custom type, is there a way to do that? I am aware that TypeInfo_Class has the methods create() and factory(), both of which return a new object of the type Object. I have

Re: Call method of object variable

2020-10-16 Thread Andrey via Digitalmars-d-learn
Thank you!

Re: Call method of object variable

2020-10-16 Thread Simen Kjærås via Digitalmars-d-learn
.. Qaz qaz; qaz.method(); // ??? } How to call alias "method" on object "qaz"? https://dlang.org/spec/traits.html#child The resulting code would be: __traits(child, qaz, method)(/*arguments go here*/); -- Simen

Call method of object variable

2020-10-16 Thread Andrey via Digitalmars-d-learn
as "method" on object "qaz"?

Re: Any way to tell if an object is inside another class?

2020-09-28 Thread Steven Schveighoffer via Digitalmars-d-learn
On 9/28/20 7:11 AM, Ruby The Roobster wrote: For example: class test {} class T { auto c = new test(); } Any way to tell if an object of type test is a member of object T? I don't want to use the name of the member variable. I just want to know if this works in general. Why am I asking

Re: Any way to tell if an object is inside another class?

2020-09-28 Thread Ruby The Roobster via Digitalmars-d-learn
On Monday, 28 September 2020 at 14:36:01 UTC, Mike Parker wrote: There's the `parent` trait. You can wrap it like this: `` then is (hasParent!f) legal code?

Re: Any way to tell if an object is inside another class?

2020-09-28 Thread Mike Parker via Digitalmars-d-learn
On Monday, 28 September 2020 at 14:23:12 UTC, Ruby The Roobster wrote: On Monday, 28 September 2020 at 14:22:34 UTC, Ruby The Roobster wrote: I meant User Defined types. not UDAs. Anyways, the whole thing is me trying to find a hacky workaround that allows something similar to multiple alias

Re: Any way to tell if an object is inside another class?

2020-09-28 Thread Ruby The Roobster via Digitalmars-d-learn
On Monday, 28 September 2020 at 14:09:07 UTC, Paul Backus wrote: Can you re-write this as actual valid D code, but with the implementation of the function stubbed out? I still don't understand what your function is supposed to take as its input(s), or what "parent object is a member var

Re: Any way to tell if an object is inside another class?

2020-09-28 Thread Ruby The Roobster via Digitalmars-d-learn
On Monday, 28 September 2020 at 14:22:34 UTC, Ruby The Roobster wrote: I meant User Defined types. not UDAs. Anyways, the whole thing is me trying to find a hacky workaround that allows something similar to multiple alias this declarations(because multiple of these are not possible). And for

Re: Any way to tell if an object is inside another class?

2020-09-28 Thread Paul Backus via Digitalmars-d-learn
, and it would help clarify. Okay. Here is an example. class Test { this.is_in_aggregate } I want a function that returns true when the parent object is a member variable of an aggregate type(UDA) Can you re-write this as actual valid D code, but with the implementation of the function stubbed out

Re: Any way to tell if an object is inside another class?

2020-09-28 Thread Ruby The Roobster via Digitalmars-d-learn
{ this.is_in_aggregate } I want a function that returns true when the parent object is a member variable of an aggregate type(UDA)

Re: Any way to tell if an object is inside another class?

2020-09-28 Thread Paul Backus via Digitalmars-d-learn
On Monday, 28 September 2020 at 11:11:13 UTC, Ruby The Roobster wrote: For example: class test {} class T { auto c = new test(); } Any way to tell if an object of type test is a member of object T? I don't want to use the name of the member variable. I just want to know if this works

Re: Any way to tell if an object is inside another class?

2020-09-28 Thread Ruby The Roobster via Digitalmars-d-learn
On Monday, 28 September 2020 at 11:40:40 UTC, k2aj wrote: pragma(msg, hasFieldOfType!(T, int)); //false pragma(msg, hasFieldOfType!(T, test)); //true Not exactly what I meant. I more of meant is there a way to check if a test object is a member variable, not if it is in a particular class.

Re: Any way to tell if an object is inside another class?

2020-09-28 Thread k2aj via Digitalmars-d-learn
On Monday, 28 September 2020 at 11:11:13 UTC, Ruby The Roobster wrote: For example: class test {} class T { auto c = new test(); } Any way to tell if an object of type test is a member of object T? I don't want to use the name of the member variable. I just want to know if this works

Any way to tell if an object is inside another class?

2020-09-28 Thread Ruby The Roobster via Digitalmars-d-learn
For example: class test {} class T { auto c = new test(); } Any way to tell if an object of type test is a member of object T? I don't want to use the name of the member variable. I just want to know if this works in general. Why am I asking this? Because I need it to develop this Multiple

Re: Shallow copy object when type is know

2020-08-27 Thread mw via Digitalmars-d-learn
On Thursday, 21 April 2016 at 11:53:13 UTC, rumbu 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 for the class, I

Re: what's this Error: corrupt MS Coff object module

2020-08-24 Thread mw via Digitalmars-d-learn
On Tuesday, 25 August 2020 at 01:44:16 UTC, mw wrote: I just tried, using -m32: /mnt/c/project/dlang/dmd-2.093.1/windows/bin/sc.ini [Environment] DFLAGS="-I%@P%\..\..\src\phobos" "-I%@P%\..\..\src\druntime\import" "-d" "-m32" at least that error is gone, and I was able to build:

Re: what's this Error: corrupt MS Coff object module

2020-08-24 Thread mw via Digitalmars-d-learn
filling up lol I just completely deleted that `packages` dir, and the /.dub dir and also the app.sln file; then I start from scratch: dub.exe generate visuald But I got the exact same build error: corrupt MS Coff object. I think it's showhow caused by the build process itself, maybe just

Re: what's this Error: corrupt MS Coff object module

2020-08-24 Thread mw via Digitalmars-d-learn
that `packages` dir, and the /.dub dir and also the app.sln file; then I start from scratch: dub.exe generate visuald But I got the exact same build error: corrupt MS Coff object. I think it's showhow caused by the build process itself, maybe just inside the unit-threaded-1.0.4 package, any suggestions

Re: what's this Error: corrupt MS Coff object module

2020-08-24 Thread Adam D. Ruppe via Digitalmars-d-learn
On Tuesday, 25 August 2020 at 01:08:49 UTC, mw wrote: Is it safe to just delete all the: yup. I have to do this every other week on my work box to keep its hard drive from filling up lol

Re: what's this Error: corrupt MS Coff object module

2020-08-24 Thread mw via Digitalmars-d-learn
On Tuesday, 25 August 2020 at 00:56:51 UTC, Adam D. Ruppe wrote: Might help to just delete the old directories and let it redownload and recompile fresh with all the new settings. Is it safe to just delete all the: C:\Users...\AppData\Local\dub\packages\ and run `dub upgrade` again to

Re: what's this Error: corrupt MS Coff object module

2020-08-24 Thread Adam D. Ruppe via Digitalmars-d-learn
On Tuesday, 25 August 2020 at 00:41:27 UTC, mw wrote: How to fix this Coff object issues? there's two library formats: coff and omf. omf is the old one that dmd assumes without arguments. coff is the new one with `dmd -m32mscoff` or `dmd -m64`. I would guess one of those libs was built

what's this Error: corrupt MS Coff object module

2020-08-24 Thread mw via Digitalmars-d-learn
I got this error, when build with VisualD-v1.0.1-dmd-2.093.1-ldc2-1.23.0.exe dmd: lib\unit-threaded_property.lib: Error: corrupt MS Coff object module obj\debug\dummy\dummy\dummy\dummy\dummy\dummy\unit-threaded_property\..\..\..\..\..\..\Users...\AppData\Local\dub\packages\unit-threaded

Re: Web Assembly, struct to JavaScript Object and back

2020-06-24 Thread tirithen via Digitalmars-d-learn
On Wednesday, 24 June 2020 at 10:53:19 UTC, Sebastiaan Koppe wrote: On Tuesday, 23 June 2020 at 18:15:25 UTC, tirithen wrote: [...] Passing anything besides int/double/bool between JS and wasm is hard work. [...] Thanks for a really good explanation, passing pointers over the structs

Re: Web Assembly, struct to JavaScript Object and back

2020-06-24 Thread Sebastiaan Koppe via Digitalmars-d-learn
On Tuesday, 23 June 2020 at 18:15:25 UTC, tirithen wrote: Anyone that has something similar working with struct objects? Passing anything besides int/double/bool between JS and wasm is hard work. Currently the ABI generated by LDC is so that arguments besides int/double/bool (and

Web Assembly, struct to JavaScript Object and back

2020-06-23 Thread tirithen via Digitalmars-d-learn
I'm experimenting with generating wasm files with ldc2 but I'm having problems when trying to pass JavaScript Objects and receive them as structs and the other way around. I found this super nice getting started guide that works fine for basic types like double and so on

Re: Storing a reference to the calling object

2020-05-23 Thread Tim via Digitalmars-d-learn
On Saturday, 23 May 2020 at 09:48:57 UTC, Mike Parker wrote: Since you're using classes, one way is to use a common base class or an interface. But assuming "parent" is the owner of the Sprite instance, you might eliminate the dependency on the parent and have it update the Sprite's position

Re: Storing a reference to the calling object

2020-05-23 Thread Luis via Digitalmars-d-learn
On Saturday, 23 May 2020 at 09:27:46 UTC, Tim wrote: Hi all, I'm a little new to D and I'm wondering how I can store a reference to the calling object. I want to create a reference to an object's parent so that each time I go to update the sprite, it is able to grab its position from

Re: Storing a reference to the calling object

2020-05-23 Thread Mike Parker via Digitalmars-d-learn
On Saturday, 23 May 2020 at 09:27:46 UTC, Tim wrote: Hi all, I'm a little new to D and I'm wondering how I can store a reference to the calling object. I want to create a reference to an object's parent so that each time I go to update the sprite, it is able to grab its position from

Re: Storing a reference to the calling object

2020-05-23 Thread drug via Digitalmars-d-learn
23.05.2020 12:27, Tim пишет: class Sprite{     /// Postional components of the sprite     int* x, y;     SDL_Surface* image_surface;     auto parent;     this(const char* path, auto parent){     writeln(*x);     this.parent = parent;     }     void update(){     // Copy

Storing a reference to the calling object

2020-05-23 Thread Tim via Digitalmars-d-learn
Hi all, I'm a little new to D and I'm wondering how I can store a reference to the calling object. I want to create a reference to an object's parent so that each time I go to update the sprite, it is able to grab its position from the parent. So if I have: class Sprite{ /// Postional

Re: How to dispatch a class function for an object accessed by handle?

2020-03-06 Thread wjoe via Digitalmars-d-learn
On Friday, 6 March 2020 at 15:19:39 UTC, Adam D. Ruppe wrote: On Friday, 6 March 2020 at 15:05:56 UTC, wjoe wrote: But didn't like the string part and that's when I introduced the alias fn because I figured maybe it's possible to do something like: factory.dispatch!(Bitmap.load)(handle,

Re: How to dispatch a class function for an object accessed by handle?

2020-03-06 Thread Adam D. Ruppe via Digitalmars-d-learn
On Friday, 6 March 2020 at 15:05:56 UTC, wjoe wrote: But didn't like the string part and that's when I introduced the alias fn because I figured maybe it's possible to do something like: factory.dispatch!(Bitmap.load)(handle, path); and get the Bitmap part from that alias and hence save the

Re: How to dispatch a class function for an object accessed by handle?

2020-03-06 Thread wjoe via Digitalmars-d-learn
On Friday, 6 March 2020 at 14:14:04 UTC, Adam D. Ruppe wrote: On Friday, 6 March 2020 at 14:05:55 UTC, Steven Schveighoffer wrote: Adam's way doesn't work either, because the call doesn't use the alias, but just instantiates opDispatch with the new name!' oh yikes, how did I not notice that?!

Re: How to dispatch a class function for an object accessed by handle?

2020-03-06 Thread wjoe via Digitalmars-d-learn
On Friday, 6 March 2020 at 13:55:25 UTC, Steven Schveighoffer wrote: On 3/6/20 6:51 AM, wjoe wrote: On Thursday, 5 March 2020 at 18:33:41 UTC, Adam D. Ruppe wrote: On Thursday, 5 March 2020 at 14:24:33 UTC, wjoe wrote: [...] template opDispatch(string name) {     auto opDispatch(T,

Re: How to dispatch a class function for an object accessed by handle?

2020-03-06 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/6/20 9:42 AM, Steven Schveighoffer wrote: alias opdispatch(T) = other_name!(name, T); And obviously, this should be opDispatch with a capital D ! -Steve

Re: How to dispatch a class function for an object accessed by handle?

2020-03-06 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/6/20 9:14 AM, Adam D. Ruppe wrote: On Friday, 6 March 2020 at 14:05:55 UTC, Steven Schveighoffer wrote: Adam's way doesn't work either, because the call doesn't use the alias, but just instantiates opDispatch with the new name!' oh yikes, how did I not notice that?! so yeah just kinda

Re: How to dispatch a class function for an object accessed by handle?

2020-03-06 Thread Adam D. Ruppe via Digitalmars-d-learn
On Friday, 6 March 2020 at 14:05:55 UTC, Steven Schveighoffer wrote: Adam's way doesn't work either, because the call doesn't use the alias, but just instantiates opDispatch with the new name!' oh yikes, how did I not notice that?! so yeah just kinda screwed. I'd probably suggest at tis point

Re: How to dispatch a class function for an object accessed by handle?

2020-03-06 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/6/20 8:55 AM, Steven Schveighoffer wrote: Instantiate!(f.opDispatch!fname, Bitmap)("path/to/wallpaper.png") I realized, this doesn't work. Because f.opDispatch is a `this` call, but is not called that way in this case. Adam's way doesn't work either, because the call doesn't use the

Re: How to dispatch a class function for an object accessed by handle?

2020-03-06 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/6/20 6:51 AM, wjoe wrote: On Thursday, 5 March 2020 at 18:33:41 UTC, Adam D. Ruppe wrote: On Thursday, 5 March 2020 at 14:24:33 UTC, wjoe wrote: [...] template opDispatch(string name) {     auto opDispatch(T, Args...)(Args args) {    ...     } } [...] NOTE: opDispatch suppresses

Re: How to dispatch a class function for an object accessed by handle?

2020-03-06 Thread Adam D. Ruppe via Digitalmars-d-learn
On Friday, 6 March 2020 at 11:51:54 UTC, wjoe wrote: I don't understand this error message. Which type can't be resolved? I don't know. It works if you rename the inner one but it doesn't like eponymous templates like this. I suspect either the spec subtly doesn't allow it or a compiler

Re: How to dispatch a class function for an object accessed by handle?

2020-03-06 Thread wjoe via Digitalmars-d-learn
On Thursday, 5 March 2020 at 18:33:41 UTC, Adam D. Ruppe wrote: On Thursday, 5 March 2020 at 14:24:33 UTC, wjoe wrote: [...] template opDispatch(string name) { auto opDispatch(T, Args...)(Args args) { ... } } [...] NOTE: opDispatch suppresses internal compile errors, it will

Re: How to dispatch a class function for an object accessed by handle?

2020-03-05 Thread wjoe via Digitalmars-d-learn
eply:) I don't need an alias at all. I was trying to figure something out with opDispatch first but something like __traits(getMember, obj, name)(args); never occurred to me. Awesome! The handle knows whether or not it's valid and where to find the object and it only makes sense in the context

Re: How to dispatch a class function for an object accessed by handle?

2020-03-05 Thread wjoe via Digitalmars-d-learn
On Thursday, 5 March 2020 at 14:46:24 UTC, Steven Schveighoffer wrote: On 3/5/20 9:24 AM, wjoe wrote: but how can I call fn in the context of an object instance? You could do it with delegates. But it's ugly: import std.stdio; class C { void foo() { writeln("Yup");} }

Re: How to dispatch a class function for an object accessed by handle?

2020-03-05 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 5 March 2020 at 14:24:33 UTC, wjoe wrote: Implement this for free functions i would do something like this void dispatch(alias fn, ARGS...)(Handle handle, ARGS args) Why do you need an `alias fn` like that? My suggestion would be to just use the `opDispatch` magic method that

Re: spawn a function with object as arg?

2020-03-05 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 5 March 2020 at 18:10:11 UTC, Martin Brezel wrote: Unfortunately the documentation page for core.thread is currently not available. the official docs are lame, use my fork doc website instead: http://dpldocs.info/experimental-docs/core.thread.html

Re: spawn a function with object as arg?

2020-03-05 Thread Martin Brezel via Digitalmars-d-learn
On Thursday, 5 March 2020 at 03:04:10 UTC, Adam D. Ruppe wrote: You can also not use `spawn` and instead give `new Thread` a try from core.thread. Thanks for the hint, I didn't notice core.thread at all. I will definitely try it out. Unfortunately the documentation page for core.thread is

Re: How to dispatch a class function for an object accessed by handle?

2020-03-05 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/5/20 9:24 AM, wjoe wrote: but how can I call fn in the context of an object instance? You could do it with delegates. But it's ugly: import std.stdio; class C { void foo() { writeln("Yup");} } void main() { alias f = C.foo; auto c = new C; void del

How to dispatch a class function for an object accessed by handle?

2020-03-05 Thread wjoe via Digitalmars-d-learn
Consider a Factory that creates instances of various different resource object instances, all of which have a common interface, and returns a handle to them. class Factory { struct Handle{} Handle create(R: Resource, ARGS...)(ARGS args) { auto r = new R(args

Re: spawn a function with object as arg?

2020-03-04 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 4 March 2020 at 23:37:00 UTC, Martin Brezel wrote: The documentation for spawn() states: "all arguments to fn must either be shared or immutable or have no pointer indirection." The easiest thing to do is to just cast import std.concurrency; import std.socket; void main() {

spawn a function with object as arg?

2020-03-04 Thread Martin Brezel via Digitalmars-d-learn
I want to create a Client, which receives and handles received data in background while the Client can send via the same socket. My first idea was something like this: class Client { private Socket socket; private Tid receiverTid; this(Socket socket) {

Re: How to copy const object?

2020-02-27 Thread Simen Kjærås via Digitalmars-d-learn
On Thursday, 27 February 2020 at 11:28:11 UTC, Mitacha wrote: I've a const struct object and I'd like to make a mutable copy of it. Struct definition contains string and an array of structs. ``` struct A { string a; B[] b; } struct B { string a; string b; } ``` As far as I can

How to copy const object?

2020-02-27 Thread Mitacha via Digitalmars-d-learn
I've a const struct object and I'd like to make a mutable copy of it. Struct definition contains string and an array of structs. ``` struct A { string a; B[] b; } struct B { string a; string b; } ``` As far as I can tell copy constructor isn't generated for struct `A` because

Re: Object "A" inherited object "B". And you need to return the object link "B".

2020-02-06 Thread Steven Schveighoffer via Digitalmars-d-learn
On 2/6/20 10:11 AM, Steven Schveighoffer wrote b.step(); // virtual call, calls B.step I meant, calls A.step; -Steve

Re: Object "A" inherited object "B". And you need to return the object link "B".

2020-02-06 Thread Steven Schveighoffer via Digitalmars-d-learn
. So the a.B syntax is not necessary. To illustrate further: A a = new A; // note, instances by default are null, you need to new them B b = a; // implicit cast assert(a is b); // they are the same object b.step(); // virtual call, calls B.step assert(a.a != 0); // note, protected allows access

Re: Object "A" inherited object "B". And you need to return the object link "B".

2020-02-06 Thread Mihail Lorenko via Digitalmars-d-learn
On Thursday, 6 February 2020 at 12:37:01 UTC, Adam D. Ruppe wrote: On Thursday, 6 February 2020 at 12:15:17 UTC, Mihail Lorenko wrote: B* b; A pointer to a class is a rare thing in B since they are already automatic references. Just use `B b;` and ten `b = a` will just work. Thanks

Re: Object "A" inherited object "B". And you need to return the object link "B".

2020-02-06 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 6 February 2020 at 12:15:17 UTC, Mihail Lorenko wrote: B* b; A pointer to a class is a rare thing in B since they are already automatic references. Just use `B b;` and ten `b = a` will just work.

Object "A" inherited object "B". And you need to return the object link "B".

2020-02-06 Thread Mihail Lorenko via Digitalmars-d-learn
Hello! Interested in a question. Object "A" inherited object "B". And you need to return the object link "B". Is this possible in this language? Here is an example: class B { protected int a; public void step() {}; } class A : B { public over

Re: /usr/bin/ld.gold: error: failed to find object -lz

2019-08-15 Thread Dukc via Digitalmars-d-learn
On Thursday, 15 August 2019 at 12:02:00 UTC, kinke wrote: That's the library you need. You may have messed things up by installing a non-dev package from Fedora (!). Fortunately it's written in red at YAST, because it's not from the official repos. I can easily find it to get rid of it when I

Re: /usr/bin/ld.gold: error: failed to find object -lz

2019-08-15 Thread kinke via Digitalmars-d-learn
On Thursday, 15 August 2019 at 11:28:35 UTC, Dukc wrote: > https://software.opensuse.org/package/zlib-devel-static An error when installing, apparently internal. That's the library you need. You may have messed things up by installing a non-dev package from Fedora (!).

Re: /usr/bin/ld.gold: error: failed to find object -lz

2019-08-15 Thread Dukc via Digitalmars-d-learn
Investigated this matter further. The most likely reason seems to be that the required library -zlib- (Yes, ld.gold was getting the arguments in correct form despite what I said. Sorry.) is installed only in dynamic form (.so), but ld.gold finds only static libraries (.a). Not 100% sure yet,

Re: /usr/bin/ld.gold: error: failed to find object -lz

2019-08-07 Thread Dukc via Digitalmars-d-learn
Taking the LDC2 invocation and removing `-lz` and `-lresolv` seems to work around the problem. A bad long-term solution though.

Re: /usr/bin/ld.gold: error: failed to find object -lz

2019-08-07 Thread Dukc via Digitalmars-d-learn
On Wednesday, 7 August 2019 at 02:47:11 UTC, ?boing? wrote: On Tuesday, 6 August 2019 at 12:39:08 UTC, Dukc wrote: On Tuesday, 6 August 2019 at 11:41:25 UTC, kinke wrote: LDC definitely doesn't add that. zlib shouldn't be necessary, as Phobos contains an (IIRC, outdated) version of it.

Re: /usr/bin/ld.gold: error: failed to find object -lz

2019-08-07 Thread Dukc via Digitalmars-d-learn
On Wednesday, 7 August 2019 at 02:47:11 UTC, ?boing? wrote: On Tuesday, 6 August 2019 at 12:39:08 UTC, Dukc wrote: On Tuesday, 6 August 2019 at 11:41:25 UTC, kinke wrote: LDC definitely doesn't add that. zlib shouldn't be necessary, as Phobos contains an (IIRC, outdated) version of it.

Re: /usr/bin/ld.gold: error: failed to find object -lz

2019-08-06 Thread ?boing? via Digitalmars-d-learn
On Tuesday, 6 August 2019 at 12:39:08 UTC, Dukc wrote: On Tuesday, 6 August 2019 at 11:41:25 UTC, kinke wrote: LDC definitely doesn't add that. zlib shouldn't be necessary, as Phobos contains an (IIRC, outdated) version of it. Anyway, you should be able to please the linker by installing a

Re: /usr/bin/ld.gold: error: failed to find object -lz

2019-08-06 Thread Dukc via Digitalmars-d-learn
On Tuesday, 6 August 2019 at 11:41:25 UTC, kinke wrote: LDC definitely doesn't add that. zlib shouldn't be necessary, as Phobos contains an (IIRC, outdated) version of it. Anyway, you should be able to please the linker by installing a zlib package, such as `zlib1g` on Debian/Ubuntu.

Re: /usr/bin/ld.gold: error: failed to find object -lz

2019-08-06 Thread kinke via Digitalmars-d-learn
On Tuesday, 6 August 2019 at 11:25:29 UTC, Dukc wrote: I did notice that according to the above, `-lz` argument apparently is due to an attempt by dub or ldc to pass `-z` to the linker, but I'm just not getting ideas of how to troubleshoot that further. Any ideas? LDC definitely doesn't add

Re: Any easy way to check if an object have inherited an interface?

2019-07-23 Thread XavierAP via Digitalmars-d-learn
On Monday, 22 July 2019 at 21:34:18 UTC, solidstate1991 wrote: It seems that I've to write my own function that searches in the given object's classinfo.interfaces since I couldn't find anything related in Phobos. Do you mean...? interface I {} class C : I {} void main() { C c1;

Re: Any easy way to check if an object have inherited an interface?

2019-07-22 Thread rikki cattermole via Digitalmars-d-learn
On 23/07/2019 9:34 AM, solidstate1991 wrote: It seems that I've to write my own function that searches in the given object's classinfo.interfaces since I couldn't find anything related in Phobos. if (Foo foo = cast(Bar)bar) { }

Any easy way to check if an object have inherited an interface?

2019-07-22 Thread solidstate1991 via Digitalmars-d-learn
It seems that I've to write my own function that searches in the given object's classinfo.interfaces since I couldn't find anything related in Phobos.

Re: Is there any way to define an interface that can implicitly convert to Object?

2019-07-10 Thread Basile B. via Digitalmars-d-learn
On Wednesday, 10 July 2019 at 08:03:30 UTC, Nathan S. wrote: I want to be able to do things like: --- bool isSame(Object a, Object b) { return a is b; } interface SomeInterface { int whatever(); } bool failsToCompile(SomeInterface a, SomeInterface b) { return isSame(a, b); } --- Error

Is there any way to define an interface that can implicitly convert to Object?

2019-07-10 Thread Nathan S. via Digitalmars-d-learn
I want to be able to do things like: --- bool isSame(Object a, Object b) { return a is b; } interface SomeInterface { int whatever(); } bool failsToCompile(SomeInterface a, SomeInterface b) { return isSame(a, b); } --- Error: function isSame(Object a, Object b) is not callable using

Re: How to use template Object in interface?

2019-06-26 Thread zoujiaqing via Digitalmars-d-learn
On Tuesday, 25 June 2019 at 12:11:47 UTC, zoujiaqing wrote: hunt-cache current version use template implemention adapter changes. I want use Interface to define Adapter, this master code unable to comple. How to do it? D programming language design flaws? ```bash git clone

Re: How to use template Object in interface?

2019-06-25 Thread zoujiaqing via Digitalmars-d-learn
On Tuesday, 25 June 2019 at 12:11:47 UTC, zoujiaqing wrote: hunt-cache current version use template implemention adapter changes. I want use Interface to define Adapter, this master code unable to comple. How to do it? D programming language design flaws? ```bash git clone

How to use template Object in interface?

2019-06-25 Thread zoujiaqing via Digitalmars-d-learn
hunt-cache current version use template implemention adapter changes. I want use Interface to define Adapter, this master code unable to comple. How to do it? D programming language design flaws? ```bash git clone https://github.com/huntlabs/hunt-cache cd hunt-cache/example dub run -v ...

Re: Create object from a library's Class returns Null

2019-05-29 Thread dangbinghoo via Digitalmars-d-learn
change gwlib buildtype to sourceLibrary solves the problem, but it should work for static or shared library.

Re: Create object from a library's Class returns Null

2019-05-28 Thread dangbinghoo via Digitalmars-d-learn
On Wednesday, 29 May 2019 at 05:04:54 UTC, dangbinghoo wrote: On Wednesday, 29 May 2019 at 02:42:23 UTC, Adam D. Ruppe wrote: Object.factory is pretty unreliable and has few supporters among the developers. I wouldn't suggest relying on it and instead building your own factory functions. oh,

Re: Create object from a library's Class returns Null

2019-05-28 Thread dangbinghoo via Digitalmars-d-learn
On Wednesday, 29 May 2019 at 02:42:23 UTC, Adam D. Ruppe wrote: Object.factory is pretty unreliable and has few supporters among the developers. I wouldn't suggest relying on it and instead building your own factory functions. oh, that's bad news, but the hibernated library is using this

Re: Create object from a library's Class returns Null

2019-05-28 Thread Adam D. Ruppe via Digitalmars-d-learn
Object.factory is pretty unreliable and has few supporters among the developers. I wouldn't suggest relying on it and instead building your own factory functions.

Re: Create object from a library's Class returns Null

2019-05-28 Thread dangbinghoo via Digitalmars-d-learn
On Tuesday, 28 May 2019 at 14:24:30 UTC, dangbinghoo wrote: On Tuesday, 28 May 2019 at 14:16:44 UTC, Nick Treleaven wrote: On Tuesday, 28 May 2019 at 09:25:51 UTC, dangbinghoo wrote: yeah, I made a typo mistake in the forum post, but the code in github repo is really with no typo problem.

Re: Create object from a library's Class returns Null

2019-05-28 Thread dangbinghoo via Digitalmars-d-learn
On Tuesday, 28 May 2019 at 14:16:44 UTC, Nick Treleaven wrote: On Tuesday, 28 May 2019 at 09:25:51 UTC, dangbinghoo wrote: class NSconf { String name; ... } Does this class have a non-default constructor? yes, I didn't provide constructor, as Class will have a

Re: Create object from a library's Class returns Null

2019-05-28 Thread Nick Treleaven via Digitalmars-d-learn
On Tuesday, 28 May 2019 at 09:25:51 UTC, dangbinghoo wrote: class NSconf { String name; ... } Does this class have a non-default constructor?

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