Re: Field Initialiser Reused Across Object Instances

2021-01-01 Thread Adam via Digitalmars-d-learn
That's a fantastic answer! Thank you. I was not aware that initializers were always compile time, that was the missing piece in my understanding. It's a shame that I can't use the nicer (IMO) syntax, but the reasoning is sound.

Field Initialiser Reused Across Object Instances

2021-01-01 Thread Adam via Digitalmars-d-learn
Consider the following: class A { int x; } class B { A a = new A; // I would expect this to be called for each "new B". } void main() { import std.stdio; auto c = new B; writeln("c ", c.a.x); c.a.x++; writeln("c ", c.a.x); writeln; auto d = new B; wri

Template Oriented Programming

2015-09-17 Thread Adam via Digitalmars-d-learn
I'm not sure if "Template Oriented Programming" seems to be the way to go in D, but I've got my head mainly stuck around OOP. I'm a bit confused about how to dive into it. With OOP, we create interfaces, which provide a contract that all implementers of the interface have to abide by. Delegati

Re: Splitting a range into a range of tuples

2015-06-01 Thread Adam via Digitalmars-d-learn
Everything is fine until I try to instantiate Tuples with my arrays. Then I get an error that says none of the overloads of the constructor are callable with these arguments. But I see this: http://dlang.org/phobos/std_typecons.html#.Tuple.this.2 , which makes me think it should work. Am I do

Re: Splitting a range into a range of tuples

2015-06-01 Thread Adam via Digitalmars-d-learn
auto result = input .splitter(',') .map!splitter .joiner .map!(to!int) .chunks(2) .map!array .array .sort() .retro; Thanks for th

Splitting a range into a range of tuples

2015-06-01 Thread Adam via Digitalmars-d-learn
Hi, I have a string of pairs of integers, where pairs are delimited from each other by commas, and members of the pair are delimited by a space. I'd like to end up with something like a range of 2-tuples, which I can then sort with a lambda. I'm running into problems trying to do this, after