Postblit segfault.

2020-05-31 Thread MaoKo via Digitalmars-d-learn
Hello, I don't understand why this code segfault on Linux/FreeBSD: import std.stdio; struct _Poc { this(this) { writeln("_Poc.this(this)"); } } void main() { _Poc[1] valueArray = [ _Poc() ]; writeln(valueArray); } I've just defined the postblit function in _Poc to see how much it's invoke

Re: Logging best practices

2020-05-31 Thread Luis via Digitalmars-d-learn
On Sunday, 31 May 2020 at 20:04:11 UTC, mw wrote: Thanks. For the colored console logger, I'm using this one: https://code.dlang.org/packages/colored-logger so far so good. (I prefer to use library, instead of reinvent my own wheels :-). I dind't know that exists. đź‘Ť

Re: how to achieve C's Token Pasting (##) Operator to generate variable name in D?

2020-05-31 Thread Ali Çehreli via Digitalmars-d-learn
On 5/31/20 1:00 PM, mw wrote:> On Sunday, 31 May 2020 at 09:37:24 UTC, Ali Çehreli wrote: > One question: in Sebastiaan's solution opDispatch is performed at > run-time Templates don't exist at run time. They are used for generating code at compile time and that's it. opDispatch is a templat

Re: Logging best practices

2020-05-31 Thread mw via Digitalmars-d-learn
On Sunday, 31 May 2020 at 07:49:01 UTC, Luis wrote: On Saturday, 30 May 2020 at 18:17:21 UTC, mw wrote: A related question: how to log to multiple destinations? e.g. both console & log file? any examples? Thanks. ```D auto multiLogger = new MultiLogger(); multiLogger.insertLogger("console"

Re: how to achieve C's Token Pasting (##) Operator to generate variable name in D?

2020-05-31 Thread mw via Digitalmars-d-learn
On Sunday, 31 May 2020 at 09:37:24 UTC, Ali Çehreli wrote: On 5/31/20 2:26 AM, Ali Çehreli wrote: Ok, I solved that too with a very convoluted "eponymous mixin template opDispatch." :) struct RW(T) { template opDispatch(string name) { static codeImpl() { import std.format;

Re: Garbage Collection Issue

2020-05-31 Thread Steven Schveighoffer via Digitalmars-d-learn
On 5/30/20 9:51 PM, Marius Cristian Baciu wrote: I am encountering a strange problem with the GC on a specific platform: at the first attempt to clear the current memory pool to make room for a new allocation, the GC considers that the page in which the main thread resides (the one created in t

Re: how to achieve C's Token Pasting (##) Operator to generate variable name in D?

2020-05-31 Thread Ali Çehreli via Digitalmars-d-learn
On 5/31/20 2:26 AM, Ali Çehreli wrote: Unfortunately, I could not reach the following cleaner syntax with a mixin template:   mixin RW!int.x; Ok, I solved that too with a very convoluted "eponymous mixin template opDispatch." :) struct RW(T) { template opDispatch(string name) { sta

Re: how to achieve C's Token Pasting (##) Operator to generate variable name in D?

2020-05-31 Thread Ali Çehreli via Digitalmars-d-learn
On 5/30/20 11:28 PM, mw wrote: On Sunday, 31 May 2020 at 00:46:09 UTC, Paul Backus wrote: You can simplify this considerably using a mixin template [1]: --- mixin template RW(T, string name) {     private T var;     public T get() { return var; }     public typeof(this) set(T val) { var = val;

Re: how to achieve C's Token Pasting (##) Operator to generate variable name in D?

2020-05-31 Thread Sebastiaan Koppe via Digitalmars-d-learn
On Saturday, 30 May 2020 at 23:39:31 UTC, mw wrote: Am I doing the right thing in D? any improvement you'd suggest? e.g. I don't quite like have to put the type and var name in the quotes as string: mixin(RW!("int", "x")); Is there a better way to achieve this? esp. for the type `int`,

Re: Logging best practices

2020-05-31 Thread Luis via Digitalmars-d-learn
On Saturday, 30 May 2020 at 18:17:21 UTC, mw wrote: A related question: how to log to multiple destinations? e.g. both console & log file? any examples? Thanks. ```D auto multiLogger = new MultiLogger(); multiLogger.insertLogger("console", new FileLogger(stdout, LogLevel.all)); multiLogger