Re: Strange rbtree behaviour

2016-07-07 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, July 07, 2016 05:13:56 Ali Çehreli via Digitalmars-d-learn wrote: > On 07/07/2016 02:57 AM, Jonathan M Davis via Digitalmars-d-learn wrote: > > then you should probably use a factory function. e.g. > > And name that function "opCall" and you have a non-constructor that > supports the

Re: Typesafe variadic functions requiring at least one argument

2016-07-07 Thread pineapple via Digitalmars-d-learn
On Thursday, 7 July 2016 at 03:52:40 UTC, Jonathan M Davis wrote: However, it looks like you can combine those two types of variadic functions to get more or less what you want (albeit more verbosely). e.g. template isInt(T) { enum isInt = is(std.traits.Unqual!T == int); } void

Re: Endiannes & Splitting Values

2016-07-07 Thread Gary Willoughby via Digitalmars-d-learn
On Thursday, 7 July 2016 at 10:48:56 UTC, Lodovico Giaretta wrote: On Thursday, 7 July 2016 at 10:45:12 UTC, Gary Willoughby wrote: On Thursday, 7 July 2016 at 08:21:53 UTC, Lodovico Giaretta wrote: Are you sure that this works in both big-endian and little-endian systems? It shouldn't

Re: local const functions - bug ?

2016-07-07 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, July 07, 2016 10:33:39 Basile B. via Digitalmars-d-learn wrote: > this compiles without error: > > > struct Foo > { > int i; > void bar() > { > void foo() const > { > i = 1; > } > foo; > } > } > > In this case

Re: Get class name of C++ class at runtime

2016-07-07 Thread Jacob Carlborg via Digitalmars-d-learn
On 07/07/16 12:31, Namespace wrote: Maybe with a template? void class_name(T)(T obj) if (is(T == class)) { writeln(T.stringof); } I want the string of the runtime type, the most derived type. -- /Jacob Carlborg

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: Get class name of C++ class at runtime

2016-07-07 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/7/16 9:02 AM, Jacob Carlborg wrote: On 07/07/16 12:31, Namespace wrote: Maybe with a template? void class_name(T)(T obj) if (is(T == class)) { writeln(T.stringof); } I want the string of the runtime type, the most derived type. Is this what you are looking for? I

Re: Endiannes & Splitting Values

2016-07-07 Thread Gary Willoughby via Digitalmars-d-learn
On Wednesday, 6 July 2016 at 21:44:37 UTC, BitGuy wrote: I'm trying to implement a feistel cipher that'll give the same results regardless of the endianness of the machine it runs on. To make the cipher I need to split a 64bit value into two 32bit values, mess with them, and then put them back

Re: Asynchronous Programming and Eventhandling in D

2016-07-07 Thread O/N/S via Digitalmars-d-learn
On Tuesday, 5 July 2016 at 20:38:53 UTC, Eugene Wissner wrote: On Tuesday, 5 July 2016 at 08:24:43 UTC, O/N/S wrote: Hi ("Grüss Gott") I like the asynchronous events in Javascript. Is something similar possible in D? Found Dragos Carp's asynchronous library

Re: Endiannes & Splitting Values

2016-07-07 Thread Lodovico Giaretta via Digitalmars-d-learn
On Thursday, 7 July 2016 at 08:14:40 UTC, Gary Willoughby wrote: What about something like: import std.stdio; union Value { ulong full; static struct Bits { uint high; uint low; } Bits bits; alias bits this; this(ulong value) {

Re: local const functions - bug ?

2016-07-07 Thread ag0aep6g via Digitalmars-d-learn
On 07/07/2016 12:33 PM, Basile B. wrote: Do you think it's a bug ? Yes.

Re: Endiannes & Splitting Values

2016-07-07 Thread Lodovico Giaretta via Digitalmars-d-learn
On Thursday, 7 July 2016 at 10:45:12 UTC, Gary Willoughby wrote: On Thursday, 7 July 2016 at 08:21:53 UTC, Lodovico Giaretta wrote: Are you sure that this works in both big-endian and little-endian systems? It shouldn't matter. You're just interested in the high and low 4 byte chunks (which

Re: Endiannes & Splitting Values

2016-07-07 Thread Gary Willoughby via Digitalmars-d-learn
On Thursday, 7 July 2016 at 08:21:53 UTC, Lodovico Giaretta wrote: Are you sure that this works in both big-endian and little-endian systems? It shouldn't matter. You're just interested in the high and low 4 byte chunks (which are to be interpreted as an int) which will return in the

Re: Strange rbtree behaviour

2016-07-07 Thread Lodovico Giaretta via Digitalmars-d-learn
On Thursday, 7 July 2016 at 09:33:38 UTC, Arafel wrote: Hi! I am seeing what it seems to me a very strange behavior with rbtrees: --- import std.stdio; import std.container.rbtree; public struct A { public int i; public this (int _i) { this.i = _i;

Get class name of C++ class at runtime

2016-07-07 Thread Jacob Carlborg via Digitalmars-d-learn
Is it possible to get the name of a C++ class, "extern(C++) class Foo {}", at runtime just as it's possible to do the same for a D class, like "object.classinfo.name"? -- /Jacob Carlborg

Strange rbtree behaviour

2016-07-07 Thread Arafel via Digitalmars-d-learn
Hi! I am seeing what it seems to me a very strange behavior with rbtrees: --- import std.stdio; import std.container.rbtree; public struct A { public int i; public this (int _i) { this.i = _i; } } public struct B { public auto col =

Re: Strange rbtree behaviour

2016-07-07 Thread Lodovico Giaretta via Digitalmars-d-learn
On Thursday, 7 July 2016 at 09:40:57 UTC, Lodovico Giaretta wrote: Initially it looks very surprising, but then if you add `writeln(B.init.col[]);` you can easily find out what's going on. And I'm quite sure it's expected behaviour. An RBTree is just a pointer to the memory containing the

Re: Strange rbtree behaviour

2016-07-07 Thread Arafel via Digitalmars-d-learn
On Thursday, 7 July 2016 at 09:46:25 UTC, Lodovico Giaretta wrote: On Thursday, 7 July 2016 at 09:40:57 UTC, Lodovico Giaretta wrote: Initially it looks very surprising, but then if you add `writeln(B.init.col[]);` you can easily find out what's going on. And I'm quite sure it's expected

Re: Strange rbtree behaviour

2016-07-07 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, July 07, 2016 09:33:38 Arafel via Digitalmars-d-learn wrote: > public struct B { > public auto col = new RedBlackTree!(A,"a.i < b.i"); > } If you default-initialize a member of a struct, then every instance of that struct gets that exact same value. In the case of a value type,

Re: Get class name of C++ class at runtime

2016-07-07 Thread Namespace via Digitalmars-d-learn
On Thursday, 7 July 2016 at 09:59:23 UTC, Jacob Carlborg wrote: Is it possible to get the name of a C++ class, "extern(C++) class Foo {}", at runtime just as it's possible to do the same for a D class, like "object.classinfo.name"? Maybe with a template? void class_name(T)(T obj) if

local const functions - bug ?

2016-07-07 Thread Basile B. via Digitalmars-d-learn
this compiles without error: struct Foo { int i; void bar() { void foo() const { i = 1; } foo; } } In this case "const" seems to be a noop. Do you think it's a bug ? Shouldn't "const" be applied, despite of foo() inaccessibility ?

Re: Get class name of C++ class at runtime

2016-07-07 Thread Jacob Carlborg via Digitalmars-d-learn
On 07/07/16 15:19, Steven Schveighoffer wrote: Is this what you are looking for? I don't think you can do this in D-land, but you can probably hook it from C++: http://en.cppreference.com/w/cpp/language/typeid Yeah, that works, thanks. -- /Jacob Carlborg

Re: Strange rbtree behaviour

2016-07-07 Thread Ali Çehreli via Digitalmars-d-learn
On 07/07/2016 02:57 AM, Jonathan M Davis via Digitalmars-d-learn wrote: > then you should probably use a factory function. e.g. And name that function "opCall" and you have a non-constructor that supports the default-constructor syntax. :p static B opCall() { // ... }

Re: local const functions - bug ?

2016-07-07 Thread Edwin van Leeuwen via Digitalmars-d-learn
On Thursday, 7 July 2016 at 10:33:39 UTC, Basile B. wrote: this compiles without error: struct Foo { int i; void bar() { void foo() const { i = 1; } foo; } } In this case "const" seems to be a noop. Do you think it's a bug ?

Re: local const functions - bug ?

2016-07-07 Thread Basile B. via Digitalmars-d-learn
On Thursday, 7 July 2016 at 12:24:08 UTC, Edwin van Leeuwen wrote: On Thursday, 7 July 2016 at 10:33:39 UTC, Basile B. wrote: this compiles without error: struct Foo { int i; void bar() { void foo() const { i = 1; } foo; } } In this

Second class pointers

2016-07-07 Thread Nicholas Wilson via Digitalmars-d-learn
So as part of my effort to get D running on GPUs I need to make a "second class" pointer type that I can alter in the backend of LDC to the correct address space. to that end I have made the following module dcompute.types.pointer; enum Private = 0; enum Global = 1; enum Shared = 2; enum