reduce a BitArray[]

2015-12-29 Thread Alex via Digitalmars-d-learn
Hi there, a silly question from me for the turn of the year... I apparently missing the forest through the trees. The first part of the code works as expected: [code] int[] arr8 = [1,2,3,4,5]; int sum = 0; foreach(int summand; arr8) { sum += summand; } writeln("

Is stdout.flush() unsafe?

2015-12-29 Thread tsbockman via Digitalmars-d-learn
Trying to compile this: void main() @safe { import std.stdio; stdout.flush(); } Fails with this message: Error: safe function 'main' cannot access __gshared data 'stdout' Is this necessary? If so, what are the synchronization requirements for access to `stdout`?

Re: reduce a BitArray[]

2015-12-29 Thread Alex Parrill via Digitalmars-d-learn
On Tuesday, 29 December 2015 at 09:26:31 UTC, Alex wrote: The problem is, that the last line with the reduce does not compile. Why? If you get an error, it is imperative that you tell us what it is. For the record, this code: import std.bitmanip; import std.stdio; impo

Re: reduce a BitArray[]

2015-12-29 Thread Daniel Kozak via Digitalmars-d-learn
V Tue, 29 Dec 2015 17:42:26 + Alex Parrill via Digitalmars-d-learn napsáno: > On Tuesday, 29 December 2015 at 09:26:31 UTC, Alex wrote: > > The problem is, that the last line with the reduce does not > > compile. Why? > > If you get an error, it is imperative that you tell us what it is.

virtual destructor in C++ integration: bug or me being stupid?

2015-12-29 Thread Atila Neves via Digitalmars-d-learn
cpp.cpp: class Oops { public: virtual ~Oops() {} virtual int number() const { return 42; } }; Oops* newOops() { return new Oops; } d.d: import std.stdio; extern(C++) { interface Oops { int number() const; } Oops newOops(); } void main() { auto oops = new

Re: virtual destructor in C++ integration: bug or me being stupid?

2015-12-29 Thread Adam D. Ruppe via Digitalmars-d-learn
On Tuesday, 29 December 2015 at 18:32:23 UTC, Atila Neves wrote: The problem here is that I don't know what the workaround is. The one I used (well, last time I tried this) was to just put a dummy function in the D interface that is a placeholder for it. interface C++Class { // at the sam

Re: Is stdout.flush() unsafe?

2015-12-29 Thread Steven Schveighoffer via Digitalmars-d-learn
On 12/29/15 4:57 AM, tsbockman wrote: Trying to compile this: void main() @safe { import std.stdio; stdout.flush(); } Fails with this message: Error: safe function 'main' cannot access __gshared data 'stdout' Is this necessary? If so, what are the synchronization requirements for a

Unexpected ' ' when converting from type string to type int

2015-12-29 Thread Michael S via Digitalmars-d-learn
Hello, thanks for stopping in. I am fuddling through some exercises on a certain website, and I have come across a very frustrating bug I can't seem to fix. The Problem: Given a square matrix of size N×N, calculate the absolute difference between the sums of its diagonals. Sample Input: 3 1

Re: Unexpected ' ' when converting from type string to type int

2015-12-29 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 30 December 2015 at 01:36:56 UTC, Michael S wrote: auto matrix_size = readln; Change that to auto matrix_size = readln.strip; and you should be in business. readln() returns any leading spaces and the newline character at the end of the line too, which is why to is throwi

Re: Unexpected ' ' when converting from type string to type int

2015-12-29 Thread Michael S via Digitalmars-d-learn
On Wednesday, 30 December 2015 at 01:38:32 UTC, Adam D. Ruppe wrote: On Wednesday, 30 December 2015 at 01:36:56 UTC, Michael S wrote: auto matrix_size = readln; Change that to auto matrix_size = readln.strip; and you should be in business. readln() returns any leading spaces and the ne

pragma(inline)

2015-12-29 Thread Ilya via Digitalmars-d-learn
Hi, Does `pragma(inline, true)` force DMD compiler to inline function when `-inline` was _not_ defined? I am failing to get a good disassembled code with obj2asm/otool :-( Best, Ilya