Re: question about keeeping reference to toStringz()

2018-05-30 Thread Mike Parker via Digitalmars-d-learn
On Thursday, 31 May 2018 at 01:12:34 UTC, Dr.No wrote: is foo() is being called from a thread, how I am supposed to keep cstring "alive"? As Jonathan explained, you don't have to worry about it if foo() itself doesn't assign the pointer to anything internally. That will be the case for mos

Re: question about keeeping reference to toStringz()

2018-05-30 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, May 31, 2018 01:12:34 Dr.No via Digitalmars-d-learn wrote: > On Wednesday, 30 May 2018 at 20:43:48 UTC, Ali Çehreli wrote: > > On 05/30/2018 01:09 PM, Dr.No wrote: > > > consider a C function with this prototype: > > >> void foo(const char *baa); > > > > > > Does it means I should do:

Re: What's the purpose of the 'in' keyword ?

2018-05-30 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, May 30, 2018 22:16:28 aberba via Digitalmars-d-learn wrote: > On Sunday, 27 May 2018 at 16:00:15 UTC, Jonathan M Davis wrote: > > On Sunday, May 27, 2018 16:28:56 Russel Winder via > > > > Digitalmars-d-learn wrote: > >> On Sun, 2018-05-27 at 13:10 +, Adam D. Ruppe via > >> Digita

Re: question about keeeping reference to toStringz()

2018-05-30 Thread Dr.No via Digitalmars-d-learn
On Wednesday, 30 May 2018 at 20:43:48 UTC, Ali Çehreli wrote: On 05/30/2018 01:09 PM, Dr.No wrote: > consider a C function with this prototype: >> void foo(const char *baa); > > Does it means I should do: > >> string s = ...; >> auto cstring = s.toStringz; >> foo(cstring); > > rather just: > >>

Re: What's the purpose of the 'in' keyword ?

2018-05-30 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, May 30, 2018 15:28:53 Ali Çehreli via Digitalmars-d-learn wrote: > On 05/30/2018 03:16 PM, aberba wrote: > > On Sunday, 27 May 2018 at 16:00:15 UTC, Jonathan M Davis wrote: > >> On Sunday, May 27, 2018 16:28:56 Russel Winder via Digitalmars-d-learn > >> > >> wrote: > >>> On Sun, 2018

Re: Constructing text with astericks

2018-05-30 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 30 May 2018 at 22:57:06 UTC, aberba wrote: How will you approach this problem in D idiomatically? Well, I never bother with "idiomatically", so I can't speak to that, but a simple solution that would work is to realize that what you're basically asking for here is a bitmap. Ea

Re: Constructing text with astericks

2018-05-30 Thread Basile B. via Digitalmars-d-learn
On Wednesday, 30 May 2018 at 22:57:06 UTC, aberba wrote: I've been given a challenge to write texts using asterisks to form the letters. D happen to have an unlimited amount of idioms yet i'm out out ideas as to the simplest approach. Task is to basically take a piece of text and write them as

Re: Move and CTFE

2018-05-30 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, May 30, 2018 22:42:13 Q. Schroll via Digitalmars-d-learn wrote: > On Wednesday, 30 May 2018 at 21:02:07 UTC, Jonathan M Davis wrote: > > On Wednesday, May 30, 2018 20:42:38 Q. Schroll via > > > > Digitalmars-d-learn wrote: > >> It seems one cannot std.algorithm.mutation.move objects

Constructing text with astericks

2018-05-30 Thread aberba via Digitalmars-d-learn
I've been given a challenge to write texts using asterisks to form the letters. D happen to have an unlimited amount of idioms yet i'm out out ideas as to the simplest approach. Task is to basically take a piece of text and write them as asterisks to the console. * * * * * *

Re: Move and CTFE

2018-05-30 Thread Q. Schroll via Digitalmars-d-learn
On Wednesday, 30 May 2018 at 21:02:07 UTC, Jonathan M Davis wrote: On Wednesday, May 30, 2018 20:42:38 Q. Schroll via Digitalmars-d-learn wrote: It seems one cannot std.algorithm.mutation.move objects explicitly. Say I have a non-copyable type [...] It fails because move() cannot be executed at

Re: What's the purpose of the 'in' keyword ?

2018-05-30 Thread Ali Çehreli via Digitalmars-d-learn
On 05/30/2018 03:16 PM, aberba wrote: On Sunday, 27 May 2018 at 16:00:15 UTC, Jonathan M Davis wrote: On Sunday, May 27, 2018 16:28:56 Russel Winder via Digitalmars-d-learn wrote: On Sun, 2018-05-27 at 13:10 +, Adam D. Ruppe via Digitalmars-d-learn - Jonathan M Davis Jonathan, which fon

Re: What's the purpose of the 'in' keyword ?

2018-05-30 Thread aberba via Digitalmars-d-learn
On Sunday, 27 May 2018 at 16:00:15 UTC, Jonathan M Davis wrote: On Sunday, May 27, 2018 16:28:56 Russel Winder via Digitalmars-d-learn wrote: On Sun, 2018-05-27 at 13:10 +, Adam D. Ruppe via Digitalmars-d-learn - Jonathan M Davis Jonathan, which font were you using in your DConf powerpo

Re: Setter chaining

2018-05-30 Thread DigitalDesigns via Digitalmars-d-learn
The above idea can be emulated in code, abiet ugly and useless: https://dpaste.dzfl.pl/bd118bc1910c import std.stdio; struct CT(A,B) { A v; B t; alias v this; B opUnary(string s)() if (s == "~") { return t; } A opUnary(string s)() if

Re: no [] operator overload for type Chunks!(char[])

2018-05-30 Thread Malte via Digitalmars-d-learn
On Wednesday, 30 May 2018 at 21:27:44 UTC, Ali Çehreli wrote: On 05/30/2018 02:19 PM, Malte wrote: Why does this code complain at the last line about a missing [] operator overload? auto buffer = new char[6]; auto chunked = buffer.chunks(3); chunked[1][2] = '!'; Same happens with wchar. Dchar

Re: no [] operator overload for type Chunks!(char[])

2018-05-30 Thread Ali Çehreli via Digitalmars-d-learn
On 05/30/2018 02:19 PM, Malte wrote: Why does this code complain at the last line about a missing [] operator overload? auto buffer = new char[6]; auto chunked = buffer.chunks(3); chunked[1][2] = '!'; Same happens with wchar. Dchar and byte work as expected. UTF-8 auto decoding strikes again

no [] operator overload for type Chunks!(char[])

2018-05-30 Thread Malte via Digitalmars-d-learn
Why does this code complain at the last line about a missing [] operator overload? auto buffer = new char[6]; auto chunked = buffer.chunks(3); chunked[1][2] = '!'; Same happens with wchar. Dchar and byte work as expected.

Re: Move and CTFE

2018-05-30 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, May 30, 2018 20:42:38 Q. Schroll via Digitalmars-d-learn wrote: > It seems one cannot std.algorithm.mutation.move objects > explicitly. Say I have a non-copyable type > > struct NoCopy > { > int payload; // some payload > pure nothrow @nogc @safe @disable: >

Re: Setter chaining

2018-05-30 Thread DigitalDesigns via Digitalmars-d-learn
On Wednesday, 30 May 2018 at 15:46:36 UTC, Steven Schveighoffer wrote: On 5/30/18 10:49 AM, DigitalDesigns wrote: Does it sound good? class X {    double x;    @property X foo(double y) { x = y; return this; }    @property X bar(double y) { x = y + 5; return this; } } void main() { X

Move and CTFE

2018-05-30 Thread Q. Schroll via Digitalmars-d-learn
It seems one cannot std.algorithm.mutation.move objects explicitly. Say I have a non-copyable type struct NoCopy { int payload; // some payload pure nothrow @nogc @safe @disable: this(this); // make it non copyable } that is being used in a compile-time function

Re: question about keeeping reference to toStringz()

2018-05-30 Thread Ali Çehreli via Digitalmars-d-learn
On 05/30/2018 01:09 PM, Dr.No wrote: > consider a C function with this prototype: >> void foo(const char *baa); > > Does it means I should do: > >> string s = ...; >> auto cstring = s.toStringz; >> foo(cstring); > > rather just: > >> foo(s.toStringz); > > ? It depends. cstring method above is no

question about keeeping reference to toStringz()

2018-05-30 Thread Dr.No via Digitalmars-d-learn
The documentation says: Important Note: When passing a char* to a C function, and the C function keeps it around for any reason, make sure that you keep a reference to it in your D code. Otherwise, it may become invalid during a garbage collection cycle and cause a nasty bug when the C code t

Re: Setter chaining

2018-05-30 Thread Steven Schveighoffer via Digitalmars-d-learn
On 5/30/18 10:49 AM, DigitalDesigns wrote: Does it sound good? class X {    double x;    @property X foo(double y) { x = y; return this; }    @property X bar(double y) { x = y + 5; return this; } } void main() { X x = new X(); x.foo(3).bar(4); } It sort of emulates UFCS but I'm

Re: What's the purpose of the 'in' keyword ?

2018-05-30 Thread Q. Schroll via Digitalmars-d-learn
On Sunday, 27 May 2018 at 16:00:15 UTC, Jonathan M Davis wrote: [...] Honestly, I'd suggest that folks never use in at this point. There's zero benefit to it. [...] Exactly. If you intend const, just write const. If you intend const scope, write const scope.

Setter chaining

2018-05-30 Thread DigitalDesigns via Digitalmars-d-learn
Does it sound good? class X { double x; @property X foo(double y) { x = y; return this; } @property X bar(double y) { x = y + 5; return this; } } void main() { X x = new X(); x.foo(3).bar(4); } It sort of emulates UFCS but I'm not sure if it's more trouble than it's

Re: Build interface from abstract class

2018-05-30 Thread DigitalDesigns via Digitalmars-d-learn
On Wednesday, 30 May 2018 at 10:31:27 UTC, Simen Kjærås wrote: On Monday, 28 May 2018 at 20:13:49 UTC, DigitalDesigns wrote: I do not think this is a problem in D. Infinite recursion can always be terminated with appropriate means. 1. Use attributes. methods in class A should be marked as bei

Re: Build interface from abstract class

2018-05-30 Thread Simen Kjærås via Digitalmars-d-learn
On Monday, 28 May 2018 at 20:13:49 UTC, DigitalDesigns wrote: I do not think this is a problem in D. Infinite recursion can always be terminated with appropriate means. 1. Use attributes. methods in class A should be marked as being for the interface. When added to the interface they will not

Re: Logging inside struct?

2018-05-30 Thread biocyberman via Digitalmars-d-learn
On Wednesday, 30 May 2018 at 10:07:35 UTC, Simen Kjærås wrote: On Wednesday, 30 May 2018 at 09:58:16 UTC, biocyberman wrote: [...] This line: writeln("got num: %s, of type: %s", num, typeof(num)); [...] Problem solved. Thanks Simen!

Re: Logging inside struct?

2018-05-30 Thread Simen Kjærås via Digitalmars-d-learn
On Wednesday, 30 May 2018 at 09:58:16 UTC, biocyberman wrote: How do I add logging for this struct? https://run.dlang.io/is/9N6N4o If not possible, what's the alternative? This line: writeln("got num: %s, of type: %s", num, typeof(num)); Gives this error message: onlineapp.d(7): Er

Logging inside struct?

2018-05-30 Thread biocyberman via Digitalmars-d-learn
How do I add logging for this struct? https://run.dlang.io/is/9N6N4o If not possible, what's the alternative?

Re: CMake support for D

2018-05-30 Thread Stefan via Digitalmars-d-learn
On Tuesday, 27 February 2018 at 14:32:54 UTC, King_DuckZ wrote: ... My problem is mixing D with C and C++ ... you found already Dragos cmake-d, but not sure if you also know Dragos talk about mixing D with C/C++. If not, have a look: https://gitlab.com/dcarp/MUCplusplus/tree/master/2016.01.2

Re: string mixin output works when directly used but when generator is used D fails

2018-05-30 Thread Simen Kjærås via Digitalmars-d-learn
On Tuesday, 29 May 2018 at 21:19:01 UTC, DigitalDesigns wrote: https://dpaste.dzfl.pl/67691db19ce8 Simplified: interface A { import std.meta : AliasSeq; alias a = AliasSeq!(__traits(getMember, B, "foo")); void foo(); } class B : A { void foo() { } } It seems the compiler is l

Re: CMake support for D

2018-05-30 Thread King_Duckz via Digitalmars-d-learn
On Tuesday, 27 February 2018 at 14:32:54 UTC, King_DuckZ wrote: On Tuesday, 27 February 2018 at 09:20:21 UTC, Russel Winder wrote: [...] Right, I stand corrected about Rust, though as you say there are those who use it with CMake. About cmake-d, there's this https://github.com/dcarp/cmake-d/