Re: How to know if opSlice is defined for a type (including built-in types)?

2016-01-20 Thread chardetm via Digitalmars-d-learn
On Wednesday, 20 January 2016 at 15:25:10 UTC, Jonathan M Davis wrote: On Wednesday, January 20, 2016 13:06:00 chardetm via Digitalmars-d-learn wrote: Anyone who has the same problem: I found std.range.primitives.hasSlicing (https://dlang.org/phobos/std_range_primitives.html#hasSlicing) which

Re: How to know if opSlice is defined for a type (including built-in types)?

2016-01-20 Thread chardetm via Digitalmars-d-learn
On Wednesday, 20 January 2016 at 10:44:36 UTC, Rikki Cattermole wrote: template CanSlice(T) { enum CanSlice = __traits(compiles, {T t; auto v = t[0 .. 1];}) || __traits(compiles, {T t; auto v = t.opSlice();}); } Should work. Thanks it works just fine!

How to know if opSlice is defined for a type (including built-in types)?

2016-01-20 Thread chardetm via Digitalmars-d-learn
Hi everyone, I was wondering if it was possible to know at compile time if opSlice is defined for a type, including built-in types like "string". Here is the code I have: import std.stdio; struct Test { Test opSlice(size_t i, size_t j) { return this; // We don't

Re: How to know if opSlice is defined for a type (including built-in types)?

2016-01-20 Thread chardetm via Digitalmars-d-learn
Anyone who has the same problem: I found std.range.primitives.hasSlicing (https://dlang.org/phobos/std_range_primitives.html#hasSlicing) which does exactly what I want!

Re: fromStringz problem with gdc

2015-04-06 Thread chardetm via Digitalmars-d-learn
On Monday, 6 April 2015 at 17:55:42 UTC, Iain Buclaw wrote: On Monday, 6 April 2015 at 17:47:27 UTC, chardetm wrote: Hello everyone, I have a problem with the fromStringz function (std.string.fromStringz) when I try to compile with the GDC compiler (it works fine with DMD). Here is a

fromStringz problem with gdc

2015-04-06 Thread chardetm via Digitalmars-d-learn
Hello everyone, I have a problem with the fromStringz function (std.string.fromStringz) when I try to compile with the GDC compiler (it works fine with DMD). Here is a minimal code to see the error: import std.stdio, std.string, std.c.stdlib; int main () { char* s; s = cast(char*)

Re: Class inside a Struct?

2015-01-30 Thread chardetm via Digitalmars-d-learn
Thanks a lot Ali, now it works perfectly! It is quite hard to get used to D's logic, I have to stop thinking in terms of C++... Anyway, thanks again!

Class inside a Struct?

2015-01-30 Thread chardetm via Digitalmars-d-learn
Hello everyone, I am currently learning D by coding a project, but I encountered a problem with one of my structures. I managed to reduce the code to the minimum: import std.stdio; import std.container.rbtree; struct Container { private RedBlackTree!int _rbtree = new