Is there a way to identfy Windows version?

2016-11-21 Thread Bauss via Digitalmars-d-learn
Is there a way to identify the Windows version? Such as if it's XP, Vista, 7, 8 or 10? Either some way to tweak with version flags or something in the standard library.

Re: Is there a way to identfy Windows version?

2016-11-21 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, November 21, 2016 08:57:11 Bauss via Digitalmars-d-learn wrote: > Is there a way to identify the Windows version? Such as if it's > XP, Vista, 7, 8 or 10? Either some way to tweak with version > flags or something in the standard library. Phobos doesn't have anything like that, but you

null this

2016-11-21 Thread Satoshi via Digitalmars-d-learn
Hello, how can calling method on local struct throw "null this"? struct is initialized by .init and have default values. struct Foo { Bar bar; static struct Bar { float x, y, z; } Bar getBar() { return bar; } } then Foo foo = Foo.init; auto b = foo.getBar(); // throw "null t

Re: null this

2016-11-21 Thread Satoshi via Digitalmars-d-learn
cast(ulong)&foo but is not null. It won't work just in special cases what I cannot reproduce easily.

Re: null this

2016-11-21 Thread rikki cattermole via Digitalmars-d-learn
On 21/11/2016 11:25 PM, Satoshi wrote: Hello, how can calling method on local struct throw "null this"? struct is initialized by .init and have default values. struct Foo { Bar bar; static struct Bar { float x, y, z; } Bar getBar() { return bar; } } then Foo foo = Foo.init;

Re: Memory allocation failed. Why?

2016-11-21 Thread ag0aep6g via Digitalmars-d-learn
On 11/21/2016 08:27 AM, Stefan Koch wrote: Someone could still be hanging on to an old Reference of buf. Who could "someone" be? It's a self-contained example, and buf doesn't leave the test function.

Re: null this

2016-11-21 Thread Satoshi via Digitalmars-d-learn
On Monday, 21 November 2016 at 10:25:17 UTC, Satoshi wrote: Hello, how can calling method on local struct throw "null this"? struct is initialized by .init and have default values. struct Foo { Bar bar; static struct Bar { float x, y, z; } Bar getBar() { return bar; } } the

Re: the best language I have ever met(?)

2016-11-21 Thread Patric Dexheimer via Digitalmars-d-learn
On Saturday, 19 November 2016 at 00:47:00 UTC, ketmar wrote: On Saturday, 19 November 2016 at 00:28:36 UTC, Stefan Koch wrote: Please don't post non-d. it slipped accidentally, sorry. ;-) for OP: `uint[2] a = [42, 69];` is the correct syntax. "uint[$] a = [42, 69];" haha for a moment I thou

Re: the best language I have ever met(?)

2016-11-21 Thread ZombineDev via Digitalmars-d-learn
On Monday, 21 November 2016 at 12:08:30 UTC, Patric Dexheimer wrote: On Saturday, 19 November 2016 at 00:47:00 UTC, ketmar wrote: On Saturday, 19 November 2016 at 00:28:36 UTC, Stefan Koch wrote: Please don't post non-d. it slipped accidentally, sorry. ;-) for OP: `uint[2] a = [42, 69];` is t

Re: the best language I have ever met(?)

2016-11-21 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, November 21, 2016 12:08:30 Patric Dexheimer via Digitalmars-d- learn wrote: > On Saturday, 19 November 2016 at 00:47:00 UTC, ketmar wrote: > > On Saturday, 19 November 2016 at 00:28:36 UTC, Stefan Koch > > > > wrote: > >> Please don't post non-d. > > > > it slipped accidentally, sorry. ;

Re: the best language I have ever met(?)

2016-11-21 Thread Namespace via Digitalmars-d-learn
On Monday, 21 November 2016 at 12:44:47 UTC, Jonathan M Davis wrote: On Monday, November 21, 2016 12:08:30 Patric Dexheimer via Digitalmars-d- learn wrote: No. D doesn't have that, though it's easy enough to do the same thing with a helper template. However, Ketmar seems to like to use his own

Enumerate CTFE bug...

2016-11-21 Thread Paolo Invernizzi via Digitalmars-d-learn
I'm not sure if it's the same as #15064 bug: import std.array, std.range, std.algorithm; immutable static foo = ["a", "b", "c"]; auto bar(R)(R r) { string s = r[1]; return s; } immutable static res = foo.enumerate.map!bar().array; std/typecons.d(526): Error: reinterpreting

RDMD can't eval code because of missing cstream module

2016-11-21 Thread Meta via Digitalmars-d-learn
I'm having trouble evaluating basic code with rdmd. It's complaining that std/cstream.d does not exist. I checked, and surely enough, it doesn't. My question is why is it looking for cstream.d? Is rdmd out of date, or is there a problem with my dmd install? I am on OSX 10.12.1 (Sierra) and inst

Re: Enumerate CTFE bug...

2016-11-21 Thread Stefan Koch via Digitalmars-d-learn
On Monday, 21 November 2016 at 13:22:57 UTC, Paolo Invernizzi wrote: I'm not sure if it's the same as #15064 bug: import std.array, std.range, std.algorithm; immutable static foo = ["a", "b", "c"]; auto bar(R)(R r) { string s = r[1]; return s; } immutable static res = foo.

Re: the best language I have ever met(?)

2016-11-21 Thread ketmar via Digitalmars-d-learn
On Monday, 21 November 2016 at 12:42:34 UTC, ZombineDev wrote: That was a proposal for D that was rejected in the last moment by Andrei. My guess is that ketmar's modified dmd has that feature implemented. exactly. it is handy feature, so i used to it. and it slept into code (i usually test m

Why don't Function Lambdas Cast to Delegate?

2016-11-21 Thread Q. Schroll via Digitalmars-d-learn
Why don't lambdas cast to a delegate if they are of type R function(Args)? I don't see any reason to that; a lambda should be a delegate type by default, and a function only as a special guarantee/optimization. It just makes them cumbersome to use with toDelegate. Probably there is a good reaso

Re: Why don't Function Lambdas Cast to Delegate?

2016-11-21 Thread Steven Schveighoffer via Digitalmars-d-learn
On 11/21/16 11:24 AM, Q. Schroll wrote: Why don't lambdas cast to a delegate if they are of type R function(Args)? I don't see any reason to that; a lambda should be a delegate type by default, and a function only as a special guarantee/optimization. It just makes them cumbersome to use with toDe

Re: Memory allocation failed. Why?

2016-11-21 Thread Kagamin via Digitalmars-d-learn
On Monday, 21 November 2016 at 11:22:40 UTC, ag0aep6g wrote: Who could "someone" be? It's a self-contained example, and buf doesn't leave the test function. Anything in .data and .bss sections and stack. See https://issues.dlang.org/show_bug.cgi?id=15723 As for GC compaction: https://issues

Re: Why don't Function Lambdas Cast to Delegate?

2016-11-21 Thread Rene Zwanenburg via Digitalmars-d-learn
On Monday, 21 November 2016 at 16:24:38 UTC, Q. Schroll wrote: Why don't lambdas cast to a delegate if they are of type R function(Args)? I don't see any reason to that; a lambda should be a delegate type by default, and a function only as a special guarantee/optimization. It just makes them cu

Re: RDMD can't eval code because of missing cstream module

2016-11-21 Thread Kagamin via Digitalmars-d-learn
https://github.com/dlang/tools/commit/5ed4f176f41b7559c64cf525c07ccf13ca3a5160 this?

Re: Memory allocation failed. Why?

2016-11-21 Thread ag0aep6g via Digitalmars-d-learn
On Monday, 21 November 2016 at 16:37:32 UTC, Kagamin wrote: Anything in .data and .bss sections and stack. See https://issues.dlang.org/show_bug.cgi?id=15723 Ok, not an actual reference then, but a false pointer.

Converting all enum members to a string fails with version 2.0.72.0

2016-11-21 Thread Stefan via Digitalmars-d-learn
Before 2.0.72.0: import std.algorithm : map, joiner; import std.uni : toUpper; import std.traits : EnumMembers; import std.stdio : writeln; import std.conv: to; private enum Color : string { RED = "red", BLUE = "blue", YELLOW = "yellow" } void main(string[] args) { writeln( [ E

Re: Converting all enum members to a string fails with version 2.0.72.0

2016-11-21 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, November 21, 2016 17:01:56 Stefan via Digitalmars-d-learn wrote: > Before 2.0.72.0: > > import std.algorithm : map, joiner; > import std.uni : toUpper; > import std.traits : EnumMembers; > import std.stdio : writeln; > import std.conv: to; > > private enum Color : string { > RED = "

Re: RDMD can't eval code because of missing cstream module

2016-11-21 Thread Meta via Digitalmars-d-learn
On Monday, 21 November 2016 at 16:44:34 UTC, Kagamin wrote: https://github.com/dlang/tools/commit/5ed4f176f41b7559c64cf525c07ccf13ca3a5160 this? That seems like a probable cause, but where is cstream being referenced? I did github search for cstream and all it came up with were references fr

Re: RDMD can't eval code because of missing cstream module

2016-11-21 Thread Meta via Digitalmars-d-learn
On Monday, 21 November 2016 at 17:35:14 UTC, Meta wrote: On Monday, 21 November 2016 at 16:44:34 UTC, Kagamin wrote: https://github.com/dlang/tools/commit/5ed4f176f41b7559c64cf525c07ccf13ca3a5160 this? That seems like a probable cause, but where is cstream being referenced? I did github sear

Re: Converting all enum members to a string fails with version 2.0.72.0

2016-11-21 Thread Basile B. via Digitalmars-d-learn
On Monday, 21 November 2016 at 17:26:37 UTC, Jonathan M Davis wrote: On Monday, November 21, 2016 17:01:56 Stefan via Digitalmars-d-learn wrote: [...] [...] there was an overload for toUpper that took string as an optimization but that inadvertently meant that types that implicitly converted

Re: Converting all enum members to a string fails with version 2.0.72.0

2016-11-21 Thread Stefan via Digitalmars-d-learn
On Monday, 21 November 2016 at 17:26:37 UTC, Jonathan M Davis wrote: [...] Thanks Jonathan for the explanation. The cast works fine but feels "unsafe". I will wait for the next version. Stefan

How to muldiv in D?

2016-11-21 Thread Kagamin via Digitalmars-d-learn
Can't find a function for it.

implementing --version?

2016-11-21 Thread mab-on via Digitalmars-d-learn
I would like to implement a "--version" switch for a command line application. Is there a clever way to do that without using the brain on every build? :) A dub-solution would be nice - but i didnt find it.

A simplification of the RvalueRef idiom

2016-11-21 Thread Ali Çehreli via Digitalmars-d-learn
First, a reminder that we have this great resource of D idioms: https://p0nce.github.io/d-idioms/#Rvalue-references:-Understanding-auto-ref-and-then-not-using-it The link above has an idiom of mixing in a byRef() member function to a struct. I think I've simplified the template by moving typeo

Re: implementing --version?

2016-11-21 Thread Karabuta via Digitalmars-d-learn
On Monday, 21 November 2016 at 19:33:54 UTC, mab-on wrote: I would like to implement a "--version" switch for a command line application. Is there a clever way to do that without using the brain on every build? :) A dub-solution would be nice - but i didnt find it. There is a package in the

Re: implementing --version?

2016-11-21 Thread mab-on via Digitalmars-d-learn
On Monday, 21 November 2016 at 20:56:41 UTC, Karabuta wrote: There is a package in the dub registry called commando (https://code.dlang.org/packages/commando) for that. Hm.. maybe i explained it wrong. My problem is not to pass a argument to the application. What i want is a clever mechanism

Re: How to muldiv in D?

2016-11-21 Thread Ali Çehreli via Digitalmars-d-learn
On 11/21/2016 11:16 AM, Kagamin wrote: Can't find a function for it. Here is a draft adapted from the following page http://stackoverflow.com/questions/14872499/is-there-an-equivalent-to-muldiv-for-linux This draft works for signed types: T mulDiv(T)(T number, T numerator, T denominator) {

Re: implementing --version?

2016-11-21 Thread Basile B. via Digitalmars-d-learn
On Monday, 21 November 2016 at 21:32:16 UTC, mab-on wrote: What i want is a clever mechanism to store the SemVer (or Commit-ID) in the binary at compiletime - automatically. Otherwise i have to think to update a const in the code every time i build a new Version. enum versionData = import

Re: the best language I have ever met(?)

2016-11-21 Thread burjui via Digitalmars-d-learn
On Monday, 21 November 2016 at 12:44:47 UTC, Jonathan M Davis wrote: Someone could create a DIP for it though and argue for it. If they did that convincingly enough, maybe it would become a feature. I suspect that the response will be though that since it's easy enough to just create a template

Re: implementing --version?

2016-11-21 Thread Basile B. via Digitalmars-d-learn
On Monday, 21 November 2016 at 23:46:41 UTC, Basile B. wrote: On Monday, 21 November 2016 at 21:32:16 UTC, mab-on wrote: What i want is a clever mechanism to store the SemVer (or Commit-ID) in the binary at compiletime - automatically. Otherwise i have to think to update a const in the code eve

Re: shared arrray problem

2016-11-21 Thread Charles Hixson via Digitalmars-d-learn
On 11/20/2016 12:41 PM, ag0aep6g via Digitalmars-d-learn wrote: On 11/20/2016 09:09 PM, Charles Hixson via Digitalmars-d-learn wrote: Thinking it over a bit more, the item returned would need to be a struct, but the struct wouldn't contain the array, it would just contain a reference to the arra

Re: the best language I have ever met(?)

2016-11-21 Thread ketmar via Digitalmars-d-learn
On Monday, 21 November 2016 at 23:49:27 UTC, burjui wrote: Though I would argue that it's better to use '_' instead of '$' to denote deduced fixed size, it seems more obvious to me: int[_] array = [ 1, 2, 3 ]; alas, `_` is valid identifier, so `enum _ = 42; int[_] a;` is perfectly valid. dol

Re: the best language I have ever met(?)

2016-11-21 Thread ketmar via Digitalmars-d-learn
On Monday, 21 November 2016 at 12:44:47 UTC, Jonathan M Davis wrote: (it might have even had a PR which was rejected), and presumably, Ketmar added it to his own compiler, because he liked the feature. exactly. it is the old patch from Kenji. the patch even survived C++ -> D transition, 'cause

Re: the best language I have ever met(?)

2016-11-21 Thread Daniel Kozak via Digitalmars-d-learn
Dne 21.11.2016 v 13:44 Jonathan M Davis via Digitalmars-d-learn napsal(a): ... it's easy enough to just create a template to do the same thing, it's not worth adding to the language. That's a problem. I belive there is a lot of things which are easy to add by some kind of magic (template or mix

Re: implementing --version?

2016-11-21 Thread Meta via Digitalmars-d-learn
On Monday, 21 November 2016 at 21:32:16 UTC, mab-on wrote: On Monday, 21 November 2016 at 20:56:41 UTC, Karabuta wrote: There is a package in the dub registry called commando (https://code.dlang.org/packages/commando) for that. Hm.. maybe i explained it wrong. My problem is not to pass a arg

Re: implementing --version?

2016-11-21 Thread Meta via Digitalmars-d-learn
On Tuesday, 22 November 2016 at 00:41:42 UTC, Meta wrote: You could write a little script to generate an increasing version and save it in a file. Then with Dub you can use a pre-build or pre-generate command to call that script, and in your D code do `enum version = import("version.txt");`. Yo

Re: Memory allocation failed. Why?

2016-11-21 Thread thedeemon via Digitalmars-d-learn
On Sunday, 20 November 2016 at 17:47:50 UTC, MGW wrote: core.exception.OutOfMemoryError@src\core\exception.d(693): Memory allocation failed Simple program and error. Why? Windows 7 (32) dmd 2.072.0 Making a 100 million bytes array by appending one byte at

Re: implementing --version?

2016-11-21 Thread Jacob Carlborg via Digitalmars-d-learn
On 2016-11-21 22:32, mab-on wrote: On Monday, 21 November 2016 at 20:56:41 UTC, Karabuta wrote: There is a package in the dub registry called commando (https://code.dlang.org/packages/commando) for that. Hm.. maybe i explained it wrong. My problem is not to pass a argument to the application.