Re: Shortest way to allocate an array and initialize it with a specific value.

2015-06-10 Thread Michael Coulombe via Digitalmars-d-learn
On Wednesday, 10 June 2015 at 20:22:18 UTC, Adel Mamin wrote: ubyte[5] a = 0xAA; // Fine. Five 0xAA bytes. auto a2 = new ubyte[5]; // Fine. Five 0 bytes. Now, let's say, I want to allocate an array of a size, derived at run time, and initialize it to some non-zero value at the same time. What

Re: Print a triangle

2016-04-29 Thread Michael Coulombe via Digitalmars-d-learn
On Friday, 29 April 2016 at 12:01:19 UTC, Joel wrote: On Friday, 29 April 2016 at 11:31:51 UTC, rikki cattermole wrote: Not entirely the goal I'm guessing output wise, but this works. import std.range : repeat; foreach(line; 1 .. 11) { writeln('#'.repeat(line)); } That is shorter

Re: Static ternary if

2016-07-25 Thread Michael Coulombe via Digitalmars-d-learn
On Monday, 25 July 2016 at 22:57:05 UTC, Gorge Jingale wrote: On Monday, 25 July 2016 at 22:27:11 UTC, Cauterite wrote: On Monday, 25 July 2016 at 02:15:12 UTC, Gorge Jingale wrote: Is there a static ternary if? (A == B) ? C : D; for compile type that works like static if. You can pretty

Retreive method given object, name and arguments

2016-08-11 Thread Michael Coulombe via Digitalmars-d-learn
Is there a way to implement "getSymbolOfCall" and "getDelegateOfCall" such that doit is functionally equivalent to calling the method directly? auto doit(C, string methodName, Args...)(C c, Args args) { alias methodSymbol = getSymbolOfCall!(c, methodName, Args); pragma(msg,

Re: Variadic Tuple of Structs with Mixed Types

2016-07-15 Thread Michael Coulombe via Digitalmars-d-learn
On Friday, 15 July 2016 at 17:00:09 UTC, jmh530 wrote: I was working with the lightweight wrapper and it seemed to work for simple stuff, but then I started getting a bunch of errors when I tried to integrate it in to my project. Below is the stripped down version of what I've been working

Re: Typesafe variadic functions requiring at least one argument

2016-07-07 Thread Michael Coulombe via Digitalmars-d-learn
On Wednesday, 6 July 2016 at 19:50:11 UTC, pineapple wrote: I'd like to do something like this but it doesn't seem to be legal - void test(int[] ints...) if(ints.length){ // stuff } Not being able to specify this interferes with how I'd like to define my method overloads.

Re: SortedRange.lowerBound from FrontTransversal

2016-08-07 Thread Michael Coulombe via Digitalmars-d-learn
On Saturday, 6 August 2016 at 23:00:42 UTC, Alex wrote: Hi all... a technical question from my side... why the last line of the following gives the error? import std.stdio; import std.range; import std.algorithm; void main() { size_t[][] darr; darr.length = 2; darr[0] = [0, 1, 2,

Re: SortedRange.lowerBound from FrontTransversal

2016-08-07 Thread Michael Coulombe via Digitalmars-d-learn
On Monday, 8 August 2016 at 00:57:41 UTC, Michael Coulombe wrote: ... And looking at the source, the reason it fails when using TransverseOptions.assumeNotJagged is that it does not implement length or $. I made this into an enhancement request:

align(n) outside struct useless?

2017-02-20 Thread Michael Coulombe via Digitalmars-d-learn
I can't figure out how to set the alignment of a struct using align(n) on the outside of the struct. Only align on the fields (default or annotated) seems to work. I get the same results back to at least DMD 2.065... Is this a bug or am I using it wrong? align(32) struct A { ubyte padding; }

Re: usage of ref foreach with variadic functions fails with "cannot be ref"

2017-02-11 Thread Michael Coulombe via Digitalmars-d-learn
On Saturday, 11 February 2017 at 15:02:11 UTC, error wrote: On Saturday, 11 February 2017 at 14:43:18 UTC, rikki cattermole wrote: Try: foreach(i, v; vars) { vars[i] = ...; } Perfect! Thanks so much - I wish that hint was in the documentation for variadic functions, although I guess

Re: Mallocator and 'shared'

2017-02-10 Thread Michael Coulombe via Digitalmars-d-learn
On Friday, 10 February 2017 at 23:57:18 UTC, bitwise wrote: https://github.com/dlang/phobos/blob/cd7846eb96ea7d2fa65ccb04b4ca5d5b0d1d4a63/std/experimental/allocator/mallocator.d#L63-L65 Looking at Mallocator, the use of 'shared' doesn't seem correct to me. The logic stated in the comment

Re: Reflection: Order of fields guaranteed?

2016-10-22 Thread Michael Coulombe via Digitalmars-d-learn
On Friday, 21 October 2016 at 01:51:44 UTC, Stefan Koch wrote: On Friday, 21 October 2016 at 01:34:44 UTC, Nick Sabalausky wrote: When using reflection to obtain the fields of a class/struct, is there any guarantee that the order is the same as the order the fields are defined? Yes they

Re: Quine using strings?

2017-01-15 Thread Michael Coulombe via Digitalmars-d-learn
A quine I came up with a while ago, using q{} string notation: enum s = q{enum s = q{%s}; void main() { import std.stdio; writefln(s,s); }}; void main() { import std.stdio; writefln(s,s); }

Re: BinaryHeap crashes upon insertion if heapified with an array of length 1?

2017-04-09 Thread Michael Coulombe via Digitalmars-d-learn
On Sunday, 9 April 2017 at 00:36:00 UTC, TheGag96 wrote: I'm trying to use a binary heap initialized with one element. However, this always seems to cause a range violation for some reason. This small example will do it: import std.stdio, std.container; void main() { auto pq =

Re: Simplest multithreading example

2017-08-31 Thread Michael Coulombe via Digitalmars-d-learn
On Friday, 1 September 2017 at 01:59:07 UTC, Brian wrote: Hello, I am trying to get the most trivial example of multithreading working, but can't seem to figure it out. I want to split a task across threads, and wait for all those tasks to finish before moving to the next line of code. The

Should "a is b" compile if a and b have unrelated classes?

2018-04-10 Thread Michael Coulombe via Digitalmars-d-learn
I had a bug in my code that was messing me up for a while, and it boiled down to an identity check between two Object references with unrelated static types, like below: class A {} class B {} void main() { A a = new A; B b = new B; if (a is b) {} // compiles } I was surprised that