function default parameters lost

2015-06-24 Thread Paul D Anderson via Digitalmars-d-learn
I'm trying to pass a function pointer while keeping the default parameter values intact. Given the following: import std.traits; import std.stdio; int foo(int a, int b = 1) { return a; } alias FOOP = int function(int, int = 1); struct ST(POOF) { FOOP fctn; this(POOF fctn) { this.

Re: Template mixin can not introduce overloads

2015-06-24 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 25 June 2015 at 03:49:04 UTC, Tofu Ninja wrote: Is this intended or is it a bug? Intended, the mixin template works on the basis of names. This means that you can override methods from the mixin by writing a member with the same name - very useful thing - but also means no overl

Template mixin can not introduce overloads

2015-06-24 Thread Tofu Ninja via Digitalmars-d-learn
Is this intended or is it a bug? void main(string[] args) { Test a; a.foo(5); // Fails to compile } struct Test { mixin testMix; void foo(string y){} } mixin template testMix() { void foo(int x){} }

Re: Compiles but does not link

2015-06-24 Thread Paul D Anderson via Digitalmars-d-learn
On Thursday, 25 June 2015 at 00:24:23 UTC, Paul D Anderson wrote: The code snippet below compiles but the linker fails with Error 42: Symbol undefined. What am I doing wrong? void main() { int foo(int a); alias FP = int delegate(int); FP fp = &foo; } Paul Uh, never m

Compiles but does not link

2015-06-24 Thread Paul D Anderson via Digitalmars-d-learn
The code snippet below compiles but the linker fails with Error 42: Symbol undefined. What am I doing wrong? void main() { int foo(int a); alias FP = int delegate(int); FP fp = &foo; } Paul

Re: core.exception.InvalidMemoryOperationError@(0) on File Reading.

2015-06-24 Thread David DeWitt via Digitalmars-d-learn
On Tuesday, 23 June 2015 at 18:49:59 UTC, David DeWitt wrote: On Monday, 22 June 2015 at 20:30:40 UTC, David DeWitt wrote: I am getting an core.exception.InvalidMemoryOperationError@(0) auto recs = f // Open for reading .byLineCopy();

Re: Casting from an enum type to another enum type

2015-06-24 Thread Roland Hadinger via Digitalmars-d-learn
On Wednesday, 24 June 2015 at 18:16:42 UTC, Meta wrote: std.conv.to really should be able to do this, but I guess not many people have needed to do this. You can write an "extension" to `to` which does it for you: import std.traits; auto to(To, From)(From f) if (is(From == enum) && is(To == e

Re: Casting from an enum type to another enum type

2015-06-24 Thread Meta via Digitalmars-d-learn
Note that this is a very simple example. You need to check in the function that a valid StyleColor will actually be produced. Otherwise, it'll happily produce a StyleColor that's invalid.

Re: Casting from an enum type to another enum type

2015-06-24 Thread Meta via Digitalmars-d-learn
On Wednesday, 24 June 2015 at 15:29:03 UTC, Roland Hadinger wrote: Hi! What is the straightest way to safely cast from one enum type A to another enum type B, when B, in terms of values as well as identifiers, is a strict subset of A? Ideally, that should be as simple as "to!B(a)". So far I'

Re: Check if template has been passed a reference type or value type?

2015-06-24 Thread sigod via Digitalmars-d-learn
On Sunday, 7 June 2015 at 15:39:17 UTC, Marc Schütz wrote: On Sunday, 7 June 2015 at 15:17:27 UTC, 1967 wrote: I've got a template that takes in a type. Sometimes the type is a class, sometimes a struct, sometimes just an int. It doesn't much matter what it is, but if it's a reference type I n

Re: Filtering Associative Array Key-Values the D way

2015-06-24 Thread Ali Çehreli via Digitalmars-d-learn
On 06/24/2015 09:08 AM, David DeWitt wrote: I'm trying to understand filtering an Associative Array the D way. I have the code below (Using while readln cause problem failing on Debian using byLineCopy()). When the byKeyValue().filter evaluates to reduce the number of Keys:Values to only the on

Re: Suggested enhancements/changes to D

2015-06-24 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 24 June 2015 at 16:44:06 UTC, DLearner wrote: Is there a place where these should be posted for discussion? The general forum: http://forum.dlang.org/group/general

Suggested enhancements/changes to D

2015-06-24 Thread DLearner via Digitalmars-d-learn
Is there a place where these should be posted for discussion?

Re: Program exited with code -11

2015-06-24 Thread weaselcat via Digitalmars-d-learn
On Wednesday, 24 June 2015 at 07:52:10 UTC, Charles Hawkins wrote: On Wednesday, 24 June 2015 at 06:54:57 UTC, weaselcat wrote: On Tuesday, 23 June 2015 at 06:50:28 UTC, Charles Hawkins wrote: [...] you can instruct dub to use other compilers with the --compiler option valid options include

Filtering Associative Array Key-Values the D way

2015-06-24 Thread David DeWitt via Digitalmars-d-learn
I'm trying to understand filtering an Associative Array the D way. I have the code below (Using while readln cause problem failing on Debian using byLineCopy()). When the byKeyValue().filter evaluates to reduce the number of Keys:Values to only the ones in the filtered header, what is the bes

Casting from an enum type to another enum type

2015-06-24 Thread Roland Hadinger via Digitalmars-d-learn
Hi! What is the straightest way to safely cast from one enum type A to another enum type B, when B, in terms of values as well as identifiers, is a strict subset of A? Ideally, that should be as simple as "to!B(a)". So far I've tried a couple of things, and one way I found was to first cast

Re: kill and thisProcessID

2015-06-24 Thread nkpm via Digitalmars-d-learn
On Wednesday, 24 June 2015 at 11:39:51 UTC, Nordlöw wrote: I have a process that shall suspend itself using SIGTSTP or SIGSTOP. My current plan is import std.process: thisProcessID, kill, Pid; import core.sys.posix.signal: SIGKILL, SIGSTOP, SIGTSTP; const thisPid = thisProcessID;

Re: kill and thisProcessID

2015-06-24 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/24/15 7:39 AM, "Nordlöw" wrote: I have a process that shall suspend itself using SIGTSTP or SIGSTOP. My current plan is import std.process: thisProcessID, kill, Pid; import core.sys.posix.signal: SIGKILL, SIGSTOP, SIGTSTP; const thisPid = thisProcessID; // some call to

Re: kill and thisProcessID

2015-06-24 Thread Nordlöw
On Wednesday, 24 June 2015 at 11:39:51 UTC, Nordlöw wrote: What to do? I believe the best solution is to add a new function Pid thisProcessPid() to std.process and refer to this from kill(Pid). Should I do PR?

Re: kill and thisProcessID

2015-06-24 Thread via Digitalmars-d-learn
On Wednesday, 24 June 2015 at 11:39:51 UTC, Nordlöw wrote: What to do? See also: Discussion at http://dlang.org/library/std/process/kill.html

kill and thisProcessID

2015-06-24 Thread Nordlöw
I have a process that shall suspend itself using SIGTSTP or SIGSTOP. My current plan is import std.process: thisProcessID, kill, Pid; import core.sys.posix.signal: SIGKILL, SIGSTOP, SIGTSTP; const thisPid = thisProcessID; // some call to kill() but kill() needs a `Pid` so

Re: Problem with map, reduce, ..

2015-06-24 Thread Stefan via Digitalmars-d-learn
On Wednesday, 24 June 2015 at 09:35:35 UTC, Adrian Matoga wrote: On Wednesday, 24 June 2015 at 08:58:10 UTC, Stefan wrote: On Wednesday, 24 June 2015 at 08:33:29 UTC, Adrian Matoga wrote: [...] Thanks! That does it! Any idea how to make the 'ugly' reduce step more 'pleasant'? I.e. make it a

Re: Problem with map, reduce, ..

2015-06-24 Thread Adrian Matoga via Digitalmars-d-learn
On Wednesday, 24 June 2015 at 08:58:10 UTC, Stefan wrote: On Wednesday, 24 June 2015 at 08:33:29 UTC, Adrian Matoga wrote: On Wednesday, 24 June 2015 at 08:30:29 UTC, Adrian Matoga wrote: input.byLine() yields char[]'s as range elements, while props is (correctly) indexed by strings, i.e. immut

Re: Problem with map, reduce, ..

2015-06-24 Thread Stefan via Digitalmars-d-learn
On Wednesday, 24 June 2015 at 08:33:29 UTC, Adrian Matoga wrote: On Wednesday, 24 June 2015 at 08:30:29 UTC, Adrian Matoga wrote: input.byLine() yields char[]'s as range elements, while props is (correctly) indexed by strings, i.e. immutable(char)[]. Ooops, more precisely it's because of the s

Re: Problem with map, reduce, ..

2015-06-24 Thread Adrian Matoga via Digitalmars-d-learn
On Wednesday, 24 June 2015 at 08:30:29 UTC, Adrian Matoga wrote: input.byLine() yields char[]'s as range elements, while props is (correctly) indexed by strings, i.e. immutable(char)[]. Ooops, more precisely it's because of the second argument of add() being string, but the solution above stil

Re: Problem with map, reduce, ..

2015-06-24 Thread Adrian Matoga via Digitalmars-d-learn
On Wednesday, 24 June 2015 at 08:18:52 UTC, Stefan wrote: I tried to refactor some existing code to use more of the functional patterns/style (map, filter, reduce, ..). The task is to read in some sort of a simple property file and present the result as an associative array. My attempt is: imp

Problem with map, reduce, ..

2015-06-24 Thread Stefan via Digitalmars-d-learn
I tried to refactor some existing code to use more of the functional patterns/style (map, filter, reduce, ..). The task is to read in some sort of a simple property file and present the result as an associative array. My attempt is: import std.stdio; import std.algorithm.iteration : filter, map

Re: Program exited with code -11

2015-06-24 Thread Charles Hawkins via Digitalmars-d-learn
On Wednesday, 24 June 2015 at 06:54:57 UTC, weaselcat wrote: On Tuesday, 23 June 2015 at 06:50:28 UTC, Charles Hawkins wrote: On Tuesday, 23 June 2015 at 03:31:37 UTC, weaselcat wrote: On Tuesday, 23 June 2015 at 03:29:14 UTC, Charles Hawkins wrote: [...] Try to compile with either ldc or gd