Re: Making an .exe that executes source file inside itself.

2018-04-26 Thread IntegratedDimensions via Digitalmars-d-learn
On Thursday, 26 April 2018 at 06:18:25 UTC, BoQsc wrote: On Wednesday, 25 April 2018 at 20:44:10 UTC, u0_a183 wrote: On Wednesday, 25 April 2018 at 19:54:26 UTC, BoQsc wrote: On Wednesday, 25 April 2018 at 19:43:31 UTC, Jonathan M Davis wrote: On Wednesday, April 25, 2018 19:19:58 BoQsc via

Re: readonly member (but assignable at constructor time)

2018-04-26 Thread Jonathan M Davis via Digitalmars-d-learn
On Friday, April 27, 2018 02:59:16 Dr.No via Digitalmars-d-learn wrote: > In C# you can have a readonly member assignable either at > declaration or constructor time, like this: > > class C > { >readonly myClass mc; > >this() >{ > mc = new myClass(); >} > > >void

readonly member (but assignable at constructor time)

2018-04-26 Thread Dr.No via Digitalmars-d-learn
In C# you can have a readonly member assignable either at declaration or constructor time, like this: class C { readonly myClass mc; this() { mc = new myClass(); } void doSomething() { mc = new myClass(); // wrong! result in compiler error, mc is readonly } } Does D

bitfields comparison in opEquals

2018-04-26 Thread Per Nordlöw via Digitalmars-d-learn
I have a struct with a mixin(bitfields) containing many small bitfields. I also have a class member in the struct. And because I want the class member to compare by using `is` I need to define bool opEquals(const scope typeof(this) that) const @safe pure nothrow @nogc {

Re: Arguments of function as an array.

2018-04-26 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, April 26, 2018 21:28:27 Jonathan via Digitalmars-d-learn wrote: > Is there a way in D to take past arguments as an array? A like a > normal Variadic function. All the arguments should be of the > same type just as an array. > > Basically I want to allow a function like this to be

Re: Arguments of function as an array.

2018-04-26 Thread ag0aep6g via Digitalmars-d-learn
On 04/26/2018 11:28 PM, Jonathan wrote: Is there a way in D to take past arguments as an array?  A like a normal Variadic function.  All the arguments should be of the same type just as an array. Basically I want to allow a function like this to be called without square brackets. void

Arguments of function as an array.

2018-04-26 Thread Jonathan via Digitalmars-d-learn
Is there a way in D to take past arguments as an array? A like a normal Variadic function. All the arguments should be of the same type just as an array. Basically I want to allow a function like this to be called without square brackets. void fun(int[] intArray) { //... } void main()

Idiomatic way to add examples to dub package

2018-04-26 Thread FreeSlave via Digitalmars-d-learn
Most dub packages are libraries and should provide runnable examples. What's the current idiomatic way to add examples? I used sub-packages with dependency on the library and "*" as version and running them as dub run :examplename Now I've noticed vibed uses a different scheme - examples are

Re: What's wrong with this alias?

2018-04-26 Thread Ali Çehreli via Digitalmars-d-learn
On 04/26/2018 10:56 AM, Dr.No wrote: > class C > { > > void error(A...)(string fmt, A args) > { > import report : error; > reportedAnyError = true; > error(fmt, args); > } > alias warning = report.warning; > } > > > I got this: > > Error: undefined

What's wrong with this alias?

2018-04-26 Thread Dr.No via Digitalmars-d-learn
consider this: module report; // output an error message on stderr void error(A...)(string fmt, A args) { import colorize : fg, color, cwriteln, cwritefln, cwrite; stderr.cwrite("error: ".color(fg.yellow)); cwritefln(fmt.color(fg.yellow), args); } void

Re: Get files from directory sorted by name

2018-04-26 Thread Dr.No via Digitalmars-d-learn
On Wednesday, 25 April 2018 at 19:25:11 UTC, Jesse Phillips wrote: On Wednesday, 25 April 2018 at 17:34:41 UTC, Dr.No wrote: Is there something implemented already to get the files from directory by name using D or I'm on my own and I have to write it myself? I didn't find how do that with

Re: Get files from directory sorted by name

2018-04-26 Thread Dr.No via Digitalmars-d-learn
On Wednesday, 25 April 2018 at 18:06:07 UTC, Jonathan M Davis wrote: On Wednesday, April 25, 2018 17:34:41 Dr.No via Digitalmars-d-learn wrote: Is there something implemented already to get the files from directory by name using D or I'm on my own and I have to write it myself? I didn't find

Re: Template to retrieve compile-time enum member from run-time enum member?

2018-04-26 Thread Simen Kjærås via Digitalmars-d-learn
On Thursday, 26 April 2018 at 16:10:16 UTC, Timoses wrote: Is it possible to use a template to place the "static foreach" looping to find the correct enum value into? Like I am trying in the initial "draft" GetMenum? As the compiler says, the value of `e` is not known at compile-time. In

Template to retrieve compile-time enum member from run-time enum member?

2018-04-26 Thread Timoses via Digitalmars-d-learn
The following should depict what I'm trying to achieve: ``` import std.stdio; enum menum { A, B, C } void main() { foo(menum.B); } void foo(menum e) { // Not possible // run time variable 'e' in conjunction with template 'Temp' writeln(Temp!(GetMenum(e))); } static int i

Re: Troubles with template constraints on string and static if

2018-04-26 Thread Alex via Digitalmars-d-learn
On Thursday, 26 April 2018 at 15:06:49 UTC, sungal wrote: I have this piece of code and I can't understand why the `static if` conditionals are always false. ``` import std.digest.sha; import std.file; import std.stdio; void main() { auto hash1 = produceHash!string("prova.d"); auto

Troubles with template constraints on string and static if

2018-04-26 Thread sungal via Digitalmars-d-learn
I have this piece of code and I can't understand why the `static if` conditionals are always false. ``` import std.digest.sha; import std.file; import std.stdio; void main() { auto hash1 = produceHash!string("prova.d"); auto hash2 = produceHash!File(File("./prova.d")); } string

Re: Making an .exe that executes source file inside itself.

2018-04-26 Thread JN via Digitalmars-d-learn
On Wednesday, 25 April 2018 at 19:19:58 UTC, BoQsc wrote: So there has been idea I've got for around few months now: making a software which executable would contain a source file. A software that anyone could modify by opening an executable and quickly change a few lines of it, rerun an

Re: Using an external Assembler with D

2018-04-26 Thread Stefan Koch via Digitalmars-d-learn
On Wednesday, 25 April 2018 at 20:31:46 UTC, solidstate1991 wrote: On Wednesday, 25 April 2018 at 15:25:42 UTC, Stefan Koch wrote: Pass stuff on the stack ;) and use extern (C) functions. Thanks! What about extern (D)? Is there a big chaos in the D ABI under x86? I think the D abi is not

Re: Making an .exe that executes source file inside itself.

2018-04-26 Thread BoQsc via Digitalmars-d-learn
On Wednesday, 25 April 2018 at 20:44:10 UTC, u0_a183 wrote: On Wednesday, 25 April 2018 at 19:54:26 UTC, BoQsc wrote: On Wednesday, 25 April 2018 at 19:43:31 UTC, Jonathan M Davis wrote: On Wednesday, April 25, 2018 19:19:58 BoQsc via Digitalmars-d-learn wrote: So there has been idea I've got