Re: How build DCD on Windows?

2021-01-11 Thread evilrat via Digitalmars-d-learn
On Tuesday, 12 January 2021 at 00:35:41 UTC, Marcone wrote: Hi, Someone can Help me build exe dcd server and client on WIndows? Step by step? Becouse the informations disponible is very hard to undestand. Are you serious? It's on the first page of their repo under the Setup section https://cod

Re: Member variables in method are null when called as delegate from thread

2021-01-11 Thread tsbockman via Digitalmars-d-learn
On Monday, 11 January 2021 at 00:43:00 UTC, Tim wrote: When MessageService calls the delegate for start, db is null. If I call start() in the Foo constructor it works just fine. Am I missing something here? Do delegates get called outside of their class context? I know I could just pass the db

How build DCD on Windows?

2021-01-11 Thread Marcone via Digitalmars-d-learn
Hi, Someone can Help me build exe dcd server and client on WIndows? Step by step? Becouse the informations disponible is very hard to undestand.

Re: Member variables in method are null when called as delegate from thread

2021-01-11 Thread Paul Backus via Digitalmars-d-learn
On Monday, 11 January 2021 at 16:10:49 UTC, Steven Schveighoffer wrote: There are some... odd rules. struct S { [...] immutable int e = 5; // stored in data segment, not per instance! Are you sure? struct S { immutable int n = 123; this(int n) { this.n = n; } } void main() {

Re: How can I directly reffer literal element itself inside [] slice?

2021-01-11 Thread Marcone via Digitalmars-d-learn
On Monday, 11 January 2021 at 21:01:57 UTC, Paul Backus wrote: On Monday, 11 January 2021 at 15:45:51 UTC, Marcone wrote: I can reffer length of literal string using $. "Hello World"[0..$] But I want make like it witout use variable name. "Hello World"[0..?.indexOf("o")] The exact syntax y

Re: How can I directly reffer literal element itself inside [] slice?

2021-01-11 Thread Paul Backus via Digitalmars-d-learn
On Monday, 11 January 2021 at 15:45:51 UTC, Marcone wrote: I can reffer length of literal string using $. "Hello World"[0..$] But I want make like it witout use variable name. "Hello World"[0..?.indexOf("o")] The exact syntax you want is impossible. The closest you can get is to use an `en

Re: I want to create my own Tuple type

2021-01-11 Thread Ola Fosheim Grøstad via Digitalmars-d-learn
On Monday, 11 January 2021 at 20:52:25 UTC, Paul Backus wrote: All of what you're saying applies equally well to any struct type as it does to tuples. Sure. It sounds like what you really want is for D *in general* to have head-const, for all types. So there's no reason to force it on tuples

Re: I want to create my own Tuple type

2021-01-11 Thread Paul Backus via Digitalmars-d-learn
On Monday, 11 January 2021 at 20:36:30 UTC, Ola Fosheim Grøstad wrote: On Monday, 11 January 2021 at 19:25:06 UTC, Paul Backus wrote: I agree that immutability has benefits, but I don't see why tuples should be singled out for special treatment in this regard. Oh, and another reason is that s

Re: I want to create my own Tuple type

2021-01-11 Thread Ola Fosheim Grøstad via Digitalmars-d-learn
On Monday, 11 January 2021 at 19:25:06 UTC, Paul Backus wrote: I agree that immutability has benefits, but I don't see why tuples should be singled out for special treatment in this regard. Oh, and another reason is that scalars can usually be passed by value with impunity, but you might want

Re: I want to create my own Tuple type

2021-01-11 Thread Ola Fosheim Grøstad via Digitalmars-d-learn
On Monday, 11 January 2021 at 19:25:06 UTC, Paul Backus wrote: On Monday, 11 January 2021 at 18:02:19 UTC, Ola Fosheim Grøstad wrote: On Monday, 11 January 2021 at 17:48:13 UTC, Paul Backus wrote: Why? I'd say that an `immutable(Tuple)` should be immutable, and a `Tuple` should be mutable, as i

Re: Easy way to accept X and immutable X in parameters without overloading?

2021-01-11 Thread Paul Backus via Digitalmars-d-learn
On Monday, 11 January 2021 at 18:51:04 UTC, Jack wrote: alias Callback = void function(const C, int); void main() { auto l = SList!Callback(); auto a = (C c, int d) { }; auto b = (C c, int d) { }; auto c = (const C c, int d) { }; l.insert(a); l.insert(b); l.insert(c);

Re: Easy way to accept X and immutable X in parameters without overloading?

2021-01-11 Thread ag0aep6g via Digitalmars-d-learn
On Monday, 11 January 2021 at 18:51:04 UTC, Jack wrote: Here's what I'm trying to make to work: import std.container : SList; class C { static immutable Foo = new C(); // } alias Callback = void function(const C, int); void main() { auto l = SList!Callback(); auto a = (C c

Re: I want to create my own Tuple type

2021-01-11 Thread Paul Backus via Digitalmars-d-learn
On Monday, 11 January 2021 at 18:02:19 UTC, Ola Fosheim Grøstad wrote: On Monday, 11 January 2021 at 17:48:13 UTC, Paul Backus wrote: Why? I'd say that an `immutable(Tuple)` should be immutable, and a `Tuple` should be mutable, as is the case with literally every other type in D. Tuples are u

Re: Easy way to accept X and immutable X in parameters without overloading?

2021-01-11 Thread Jack via Digitalmars-d-learn
On Monday, 11 January 2021 at 18:37:58 UTC, ag0aep6g wrote: On Monday, 11 January 2021 at 18:12:17 UTC, Jack wrote: thanks! now, how would I add const here? import std.container : SList; auto l = SList!Callabck(); doesn't work: auto l = SList!(const(Callabck())); auto l = SList!(const Callabc

Re: Easy way to accept X and immutable X in parameters without overloading?

2021-01-11 Thread ag0aep6g via Digitalmars-d-learn
On Monday, 11 January 2021 at 18:12:17 UTC, Jack wrote: thanks! now, how would I add const here? import std.container : SList; auto l = SList!Callabck(); doesn't work: auto l = SList!(const(Callabck())); auto l = SList!(const Callabck()); You said you want the callbacks to accept both mutabl

Re: Easy way to accept X and immutable X in parameters without overloading?

2021-01-11 Thread Jack via Digitalmars-d-learn
On Monday, 11 January 2021 at 16:56:05 UTC, ag0aep6g wrote: On Monday, 11 January 2021 at 16:40:01 UTC, Jack wrote: let's say a I have this: void f(X foo) { } but I'd like to make f() accept immutable X too so instead of cast away everywhere in the code where immutable(X) is passed to f() or

Re: I want to create my own Tuple type

2021-01-11 Thread Ola Fosheim Grøstad via Digitalmars-d-learn
On Monday, 11 January 2021 at 17:48:13 UTC, Paul Backus wrote: Why? I'd say that an `immutable(Tuple)` should be immutable, and a `Tuple` should be mutable, as is the case with literally every other type in D. Tuples are usually immutable, it brings more correctness.

Re: I want to create my own Tuple type

2021-01-11 Thread Paul Backus via Digitalmars-d-learn
On Monday, 11 January 2021 at 14:51:29 UTC, Ola Fosheim Grøstad wrote: Basically, the tuple itself should be immutable, but not the objects being referenced. I guess I could run over the types and add const if they are not references? Why? I'd say that an `immutable(Tuple)` should be immutable

Re: Member variables in method are null when called as delegate from thread

2021-01-11 Thread Arafel via Digitalmars-d-learn
On 11/1/21 17:10, Steven Schveighoffer wrote: A shared member is a sharable member of the class. It does not put the item in global storage. There are some... odd rules. struct S {    static int a; // TLS    shared static int b; // shared data storage    shared int c; // local variable, but

Re: Parameter with indetermined tuple elements type?

2021-01-11 Thread oddp via Digitalmars-d-learn
On 11.01.21 16:27, Marcone via Digitalmars-d-learn wrote: function [...] without template. And why don't you want to use templates for that? It's as easy as that: import std; auto foo(T)(T tup) if (isTuple!T) { // statically introspect tuple here ... return tup; } void main() { w

Re: Easy way to accept X and immutable X in parameters without overloading?

2021-01-11 Thread ag0aep6g via Digitalmars-d-learn
On Monday, 11 January 2021 at 16:40:01 UTC, Jack wrote: let's say a I have this: void f(X foo) { } but I'd like to make f() accept immutable X too so instead of cast away everywhere in the code where immutable(X) is passed to f() or make a overload for this, are there any way to accept both

Re: properly passing strings to functions? (C++ vs D)

2021-01-11 Thread Ola Fosheim Grøstad via Digitalmars-d-learn
On Monday, 11 January 2021 at 16:40:53 UTC, Ali Çehreli wrote: Yes. Earlier C++ string implementations used reference counting, which caused multi-threading complications; so, many implementations switched to copying. Ah, I guess I've never used std::string for anything that requires speed. T

Re: How can I directly reffer literal element itself inside [] slice?

2021-01-11 Thread Marcone via Digitalmars-d-learn
On Monday, 11 January 2021 at 16:41:03 UTC, oddp wrote: On 11.01.21 16:45, Marcone via Digitalmars-d-learn wrote: "Hello World"[0..?.indexOf("o")] Does until [1] do the trick? "Hello World".until("o") // => "Hell" [1] https://dlang.org/library/std/algorithm/searching/until.html I want more

Re: properly passing strings to functions? (C++ vs D)

2021-01-11 Thread IGotD- via Digitalmars-d-learn
On Monday, 11 January 2021 at 14:12:57 UTC, zack wrote: D: void myPrint(string text){ ... } void myPrintRef(ref string text) { ... } In D strings are immutable so there will be no copying when passing as function parameters. Strings are essentially like slices when passing them. I usually

Re: properly passing strings to functions? (C++ vs D)

2021-01-11 Thread Ali Çehreli via Digitalmars-d-learn
On 1/11/21 8:22 AM, zack wrote: On Monday, 11 January 2021 at 15:25:58 UTC, Ola Fosheim Grøstad wrote: I meant allocation... The following prints "1", so no allocation. Just tried on Windows with Visual Studio, it prints "0". So I guess this is platform/compiler dependent. Yes. Earlier C++

Easy way to accept X and immutable X in parameters without overloading?

2021-01-11 Thread Jack via Digitalmars-d-learn
let's say a I have this: void f(X foo) { } but I'd like to make f() accept immutable X too so instead of cast away everywhere in the code where immutable(X) is passed to f() or make a overload for this, are there any way to accept both in same function? those function are callback-like functi

Re: How can I directly reffer literal element itself inside [] slice?

2021-01-11 Thread oddp via Digitalmars-d-learn
On 11.01.21 16:45, Marcone via Digitalmars-d-learn wrote: "Hello World"[0..?.indexOf("o")] Does until [1] do the trick? "Hello World".until("o") // => "Hell" [1] https://dlang.org/library/std/algorithm/searching/until.html

Re: Parameter with indetermined tuple elements type?

2021-01-11 Thread Ali Çehreli via Digitalmars-d-learn
On 1/11/21 7:27 AM, Marcone wrote: I want to create a function that receive a tuple (need be a tuple) with indetermined length and indetermined elements type without template. The argument need be a tuple, but length and elements types indetermineds. How can I make it? With isIntanceOf in a t

Re: opCast / operator overloading with additional template arguments

2021-01-11 Thread Ali Çehreli via Digitalmars-d-learn
On 1/10/21 7:27 PM, Paul wrote: > On Monday, 11 January 2021 at 02:37:24 UTC, Ali Çehreli wrote: >> >> T opCast(T)() const if (is(T : Vec!(size, S2), S2)) { > >> The is expression can be so complicated that I used a different >> approach below. > >> if (isInstanceOfVec!T && >> T.init.

Re: properly passing strings to functions? (C++ vs D)

2021-01-11 Thread zack via Digitalmars-d-learn
On Monday, 11 January 2021 at 15:25:58 UTC, Ola Fosheim Grøstad wrote: I meant allocation... The following prints "1", so no allocation. Just tried on Windows with Visual Studio, it prints "0". So I guess this is platform/compiler dependent.

Re: Member variables in method are null when called as delegate from thread

2021-01-11 Thread Steven Schveighoffer via Digitalmars-d-learn
On 1/11/21 10:42 AM, Arafel wrote: On 11/1/21 14:42, Steven Schveighoffer wrote: That isn't exactly true. Member variables are members of the object. If the object is shared, the member variables are shared. If the object is local the variables are local. Thread local really only applies to

How can I directly reffer literal element itself inside [] slice?

2021-01-11 Thread Marcone via Digitalmars-d-learn
I can reffer length of literal string using $. "Hello World"[0..$] But I want make like it witout use variable name. "Hello World"[0..?.indexOf("o")]

Re: How can I directly reffer literal element itself inside [] slice?

2021-01-11 Thread Marcone via Digitalmars-d-learn
I am using it: // Tipo Nulo. class None {} // Função slice() auto slice(T1, T2, T3 = None)(T1 conteudo, T2 inicio, T3 fim = T3.init) { int start, end, startlen; static if (is(T2 == int)) {inicio = inicio < 0 ? conteudo.length + inicio : inicio;} static if (is(T3 == int)) {fim = fim

Re: Member variables in method are null when called as delegate from thread

2021-01-11 Thread Arafel via Digitalmars-d-learn
On 11/1/21 14:42, Steven Schveighoffer wrote: That isn't exactly true. Member variables are members of the object. If the object is shared, the member variables are shared. If the object is local the variables are local. Thread local really only applies to *static* variables, such as globals

Re: I want to create my own Tuple type

2021-01-11 Thread Ola Fosheim Grøstad via Digitalmars-d-learn
On Monday, 11 January 2021 at 14:53:08 UTC, Ola Fosheim Grøstad wrote: On Monday, 11 January 2021 at 14:51:29 UTC, Ola Fosheim Grøstad wrote: On Monday, 11 January 2021 at 14:03:39 UTC, Paul Backus wrote: alias expand this; Hm... this does not allow me protect the fields from being chang

How can I use file from resource .res without copy it to hard disc?

2021-01-11 Thread Marcone via Digitalmars-d-learn
I want use file direct from resource .res without copy it to hard disc. How can I make it?

Re: DMD support for Apples new silicon

2021-01-11 Thread Christian Köstlin via Digitalmars-d-learn
On 10.01.21 17:29, Guillaume Piolat wrote: On Sunday, 10 January 2021 at 16:03:53 UTC, Christian Köstlin wrote: Good news! I was hoping for support in ldc, but dmds super fast compile times would be very welcome. I guess it's more work to put an ARM backend there. Kind regards, Christian

Parameter with indetermined tuple elements type?

2021-01-11 Thread Marcone via Digitalmars-d-learn
I want to create a function that receive a tuple (need be a tuple) with indetermined length and indetermined elements type without template. The argument need be a tuple, but length and elements types indetermineds. How can I make it?

Re: properly passing strings to functions? (C++ vs D)

2021-01-11 Thread Ola Fosheim Grøstad via Digitalmars-d-learn
On Monday, 11 January 2021 at 15:23:23 UTC, Ola Fosheim Grøstad wrote: On Monday, 11 January 2021 at 14:12:57 UTC, zack wrote: A beginner question: How to pass strings properly to functions in D? Is there any allocation going on if just use a function as "myPrint"? In C++ I have often seen call

Re: properly passing strings to functions? (C++ vs D)

2021-01-11 Thread Ola Fosheim Grøstad via Digitalmars-d-learn
On Monday, 11 January 2021 at 14:12:57 UTC, zack wrote: A beginner question: How to pass strings properly to functions in D? Is there any allocation going on if just use a function as "myPrint"? In C++ I have often seen calls where one just passes a reference/const reference to a string to avoi

Re: I want to create my own Tuple type

2021-01-11 Thread Ola Fosheim Grøstad via Digitalmars-d-learn
On Monday, 11 January 2021 at 14:03:39 UTC, Paul Backus wrote: alias expand this; Hm... this does not allow me protect the fields from being changed. I also cannot use const since it is transitive and would make it impossible to return two references to mutable objects? Basically, the t

Re: I want to create my own Tuple type

2021-01-11 Thread Ola Fosheim Grøstad via Digitalmars-d-learn
On Monday, 11 January 2021 at 14:51:29 UTC, Ola Fosheim Grøstad wrote: On Monday, 11 January 2021 at 14:03:39 UTC, Paul Backus wrote: alias expand this; Hm... this does not allow me protect the fields from being changed. I also cannot use const since it is transitive and would make it im

Re: I want to create my own Tuple type

2021-01-11 Thread Ola Fosheim Grøstad via Digitalmars-d-learn
On Monday, 11 January 2021 at 14:03:39 UTC, Paul Backus wrote: On Monday, 11 January 2021 at 09:42:39 UTC, Ola Fosheim Grøstad wrote: On Monday, 11 January 2021 at 05:59:03 UTC, Paul Backus wrote: You can just fall back to `alias expand this` like Phobos's Tuple does in this case. No compiler m

Re: properly passing strings to functions? (C++ vs D)

2021-01-11 Thread rikki cattermole via Digitalmars-d-learn
On 12/01/2021 3:12 AM, zack wrote: A beginner question: How to pass strings properly to functions in D? Is there any allocation going on if just use a function as "myPrint"? In C++ I have often seen calls where one just passes a reference/const reference to a string to avoid allocation. C++:

properly passing strings to functions? (C++ vs D)

2021-01-11 Thread zack via Digitalmars-d-learn
A beginner question: How to pass strings properly to functions in D? Is there any allocation going on if just use a function as "myPrint"? In C++ I have often seen calls where one just passes a reference/const reference to a string to avoid allocation. C++: void myPrintCPP(const std::string& i

Re: I want to create my own Tuple type

2021-01-11 Thread Paul Backus via Digitalmars-d-learn
On Monday, 11 January 2021 at 09:42:39 UTC, Ola Fosheim Grøstad wrote: On Monday, 11 January 2021 at 05:59:03 UTC, Paul Backus wrote: You can just fall back to `alias expand this` like Phobos's Tuple does in this case. No compiler modification needed. I though maybe it would be nice in general

Re: Member variables in method are null when called as delegate from thread

2021-01-11 Thread Steven Schveighoffer via Digitalmars-d-learn
On 1/11/21 3:21 AM, Arafel wrote: On 11/1/21 1:43, Tim wrote: Hi there, I have something like this: class Foo{ MongoClient db; this(){ db = connectMongoDB("127.0.0.1"); void delegate()[string] commands = ["start": &this.start];  MessageService messenger = new M

Re: I want to create my own Tuple type

2021-01-11 Thread Ola Fosheim Grøstad via Digitalmars-d-learn
On Monday, 11 January 2021 at 09:42:39 UTC, Ola Fosheim Grøstad wrote: I though maybe it would be nice in general to be able to create static indexed type by having a special field name pattern, but I will have a another look at staticMap (I don't really want the full staticMap into object.d th

Re: Member variables in method are null when called as delegate from thread

2021-01-11 Thread Tim via Digitalmars-d-learn
On Monday, 11 January 2021 at 08:21:21 UTC, Arafel wrote: It's also possible that you'll have to make Foo itself `shared`, or at least convert your constructor into a `shared this ()` to get a shared instance that you can pass to a different thread, but I'm not sure how function pointers / del

Re: I want to create my own Tuple type

2021-01-11 Thread Ola Fosheim Grøstad via Digitalmars-d-learn
On Monday, 11 January 2021 at 05:59:03 UTC, Paul Backus wrote: static if (allSameType) { auto opIndex(size_t i) { switch (i) { static foreach (j; 0 .. Types.length) { case j: return this.expand[j]; } default: assert(0); // or throw R

Re: Developing and running D GUI app on Android

2021-01-11 Thread evilrat via Digitalmars-d-learn
On Monday, 11 January 2021 at 07:38:00 UTC, Elronnd wrote: On Monday, 11 January 2021 at 06:26:41 UTC, evilrat wrote: Android itself is just linux under the hood, however the launcher starts java process that fires up your activity class (main in native languages) from there you just call your

Re: Member variables in method are null when called as delegate from thread

2021-01-11 Thread Arafel via Digitalmars-d-learn
On 11/1/21 1:43, Tim wrote: Hi there, I have something like this: class Foo{     MongoClient db;     this(){     db = connectMongoDB("127.0.0.1");     void delegate()[string] commands = ["start": &this.start]; MessageService messenger = new MessageService(8081, commands);