Re: static arrays at runtime with templates ?

2019-02-05 Thread Emil via Digitalmars-d-learn
On Monday, 4 February 2019 at 22:48:10 UTC, XavierAP wrote: ... If there is something you want to solve in a program of yours, there may be another way, as H.S. Teoh suggests. If you're just trying out stuff it's also fine, :) there's still more. Since August last year I try to read or write

Re: static arrays at runtime with templates ?

2019-02-04 Thread Emil via Digitalmars-d-learn
On Monday, 4 February 2019 at 16:08:38 UTC, XavierAP wrote: Static arrays are always allocated at run-time. It's the size of the array that must be known at compile-time (in this case via a template parameter). What's the advantage (or the essential difference) of auto data =

Re: static arrays at runtime with templates ?

2019-02-03 Thread Emil via Digitalmars-d-learn
On Sunday, 3 February 2019 at 16:36:30 UTC, Paul Backus wrote: ... This is actually already in the standard library: https://dlang.org/phobos/std_array.html#staticArray thank you either I already read that and forgot or finally I'm starting to get the feel of the language :)

static arrays at runtime with templates ?

2019-02-03 Thread Emil via Digitalmars-d-learn
I tried this on a whim and it appears to work: auto static_array(T, size_t data_size)() { T[data_size] data; return data; } void main() { import std.stdio: writeln; import std.traits: isStaticArray; auto data = static_array!(int, 5)(3); writeln(data); static

contracts in interfaces: do they work, do I have to do something to enable checking of contracts ?

2018-10-01 Thread Emil via Digitalmars-d-learn
I am trying my hand at contracts and they work fine in plain functions and in methods, but I can't make them work in interfaces. https://dlang.org/spec/interface.html#interface-contracts $ dmd --version DMD64 D Compiler v2.081.1 Copyright (C) 1999-2018 by The D Language Foundation, All Rights

Re: capture stdout or stderr

2017-02-02 Thread Emil via Digitalmars-d-learn
On Wednesday, 1 February 2017 at 14:38:18 UTC, angel wrote: On Wednesday, 1 February 2017 at 01:08:19 UTC, Emil wrote: is it possible to intercept the STDOUT or STDERR and capture the output into a variable ? . writeln(output_buffer); # prints '["test 1","test 2"]' No. Please keep in

capture stdout or stderr

2017-01-31 Thread Emil via Digitalmars-d-learn
is it possible to intercept the STDOUT or STDERR and capture the output into a variable ? some pseudocode to explain what I mean string[] output_buffer; stdout.capture_to(output_buffer); writeln("test 1"); # not printed writeln("test 2"); # not printed stdout.release(output_buffer);