Re: Linking a C program with D library

2018-08-15 Thread Joe via Digitalmars-d-learn
On Wednesday, 15 August 2018 at 06:39:50 UTC, Mike Parker wrote: String literals are implicitly convertible to const(char)* and are guaranteed to be nul-terminated like a C string, so this works: [...] Does that help? Yes, indeed. I think I possibly read about literal strings being

Re: A devil self reference

2018-08-15 Thread Alex via Digitalmars-d-learn
On Wednesday, 15 August 2018 at 21:42:11 UTC, Jonathan M Davis wrote: What are you actually trying to do? Aside from the circular reference issues, using the address of a struct like that is very risky, because if the struct is ever moved, it will change. Yeah... my functions are all ref.

Re: A devil self reference

2018-08-15 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, August 15, 2018 10:40:49 AM MDT Alex via Digitalmars-d-learn wrote: > Hi all. > Finally, I arrived at something like this: > > ´´´ > void main() > { > S!(sarr)[] sarr; > } > > struct S(alias Reference) > { > size_t id() > in > { > // not static assert, only because a

Re: Array!bool -> Chunks -> foreach: out of bounds

2018-08-15 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/15/18 2:12 PM, Steven Schveighoffer wrote: https://issues.dlang.org/show_bug.cgi?id=19171 PR: https://github.com/dlang/phobos/pull/ -Steve

Re: Array!bool -> Chunks -> foreach: out of bounds

2018-08-15 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/15/18 2:05 PM, Steven Schveighoffer wrote: On 8/15/18 12:27 PM, 0xEAB wrote: On Wednesday, 15 August 2018 at 15:13:50 UTC, Kagamin wrote: It's a bug: Is it a known one? Nope. And I figured out the problem. Will submit a fix. https://issues.dlang.org/show_bug.cgi?id=19171 -Steve

Re: Array!bool -> Chunks -> foreach: out of bounds

2018-08-15 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/15/18 12:27 PM, 0xEAB wrote: On Wednesday, 15 August 2018 at 15:13:50 UTC, Kagamin wrote: It's a bug: Is it a known one? Nope. And I figured out the problem. Will submit a fix. -Steve

Re: A devil self reference

2018-08-15 Thread Alex via Digitalmars-d-learn
On Wednesday, 15 August 2018 at 16:40:49 UTC, Alex wrote: Hi all. Finally, I arrived at something like this: ´´´ void main() { S!(sarr)[] sarr; } struct S(alias Reference) { size_t id() in { // not static assert, only because a pointer is never known in

A devil self reference

2018-08-15 Thread Alex via Digitalmars-d-learn
Hi all. Finally, I arrived at something like this: ´´´ void main() { S!(sarr)[] sarr; } struct S(alias Reference) { size_t id() in { // not static assert, only because a pointer is never known in advance assert(Reference.ptr <= ); }

Re: Array!bool -> Chunks -> foreach: out of bounds

2018-08-15 Thread 0xEAB via Digitalmars-d-learn
On Wednesday, 15 August 2018 at 15:13:50 UTC, Kagamin wrote: It's a bug: Is it a known one?

Re: Array!bool -> Chunks -> foreach: out of bounds

2018-08-15 Thread Kagamin via Digitalmars-d-learn
It's a bug: auto s=ar[]; s.popFront(); auto s1=s[0..0]; //out of bounds

Re: Convert output of map() to array of strings

2018-08-15 Thread Paul Backus via Digitalmars-d-learn
On Wednesday, 15 August 2018 at 13:53:02 UTC, Andrey wrote: Hello, I have the following code: string[] list; string text; // ... enum pattern = ctRegex!`^[0-9]+$`; list = text.split('\n').map!(line => line.matchFirst(pattern).hit); Compiler says that it can't convert result of map function

Convert output of map() to array of strings

2018-08-15 Thread Andrey via Digitalmars-d-learn
Hello, I have the following code: string[] list; string text; // ... enum pattern = ctRegex!`^[0-9]+$`; list = text.split('\n').map!(line => line.matchFirst(pattern).hit); Compiler says that it can't convert result of map function to string[]... What I want: 1. Split some text into lines

Array!bool -> Chunks -> foreach: out of bounds

2018-08-15 Thread 0xEAB via Digitalmars-d-learn
core.exception.AssertError@/src/phobos/std/container/array.d(1667): Using out of bounds indexes on an Array Should this code[1] really try to access something out of bounds and assert? Also: shouldn't this assertion[2] be perhaps inside `version(D_NoBoundsChecks){} else { ... }` block?

Re: tryTo: non-throwing variant of std.conv.to

2018-08-15 Thread Per Nordlöw via Digitalmars-d-learn
On Wednesday, 15 August 2018 at 10:38:23 UTC, Jonathan M Davis wrote: Would it be sane to add these to std.conv alongside existing std.conv.to so that underlying logic in std.conv.to can be reused? If so, AFAICT, existing std.conv.to should be implemented on Put something together to get

Re: tryTo: non-throwing variant of std.conv.to

2018-08-15 Thread Per Nordlöw via Digitalmars-d-learn
On Wednesday, 15 August 2018 at 09:26:26 UTC, Seb wrote: If so, AFAICT, existing std.conv.to should be implemented on top of std.conv.tryTo. Well, for now you can use `ifThrown` from std.exception: https://dlang.org/phobos/std_exception.html#ifThrown --- "foo".to!int.ifThrown(42) But the

Re: Concat enum of strings into one string

2018-08-15 Thread Andrey via Digitalmars-d-learn
On Tuesday, 14 August 2018 at 16:03:05 UTC, vit wrote: import std.traits : EnumMembers; import std.string : join; import std.algorithm : map; pragma(msg, [EnumMembers!Type].map!(x => cast(string)x).join(" ")); Thank you! Jonathan M Davis, I understood.

Re: is this a betterC bug ?

2018-08-15 Thread Mike Franklin via Digitalmars-d-learn
On Wednesday, 15 August 2018 at 08:14:53 UTC, Petar Kirov [ZombineDev] wrote: It's not a bug, it's all about how the type system is set up. The type of an array literal expression like `[1, 2, 3]` is `int[]` (a slice of an array of ints), so no matter if you do: auto readonly(T)(const(T)[]

Re: tryTo: non-throwing variant of std.conv.to

2018-08-15 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, August 15, 2018 3:21:29 AM MDT Per Nordlöw via Digitalmars-d- learn wrote: > Have anybody thought about non-throwing variants of std.conv.to > typically named `tryTo` > similar to what Folly > > https://github.com/facebook/folly/blob/master/folly/docs/Conv.md#non-throw >

Re: tryTo: non-throwing variant of std.conv.to

2018-08-15 Thread Seb via Digitalmars-d-learn
On Wednesday, 15 August 2018 at 09:21:29 UTC, Per Nordlöw wrote: Have anybody thought about non-throwing variants of std.conv.to typically named `tryTo` similar to what Folly https://github.com/facebook/folly/blob/master/folly/docs/Conv.md#non-throwing-interfaces does, for instance, as

tryTo: non-throwing variant of std.conv.to

2018-08-15 Thread Per Nordlöw via Digitalmars-d-learn
Have anybody thought about non-throwing variants of std.conv.to typically named `tryTo` similar to what Folly https://github.com/facebook/folly/blob/master/folly/docs/Conv.md#non-throwing-interfaces does, for instance, as tryTo(str).then([](int i) { use(i); }); ? Would it be sane to add

Re: is this a betterC bug ?

2018-08-15 Thread Petar via Digitalmars-d-learn
On Wednesday, 15 August 2018 at 08:14:53 UTC, Petar Kirov [ZombineDev] wrote: https://run.dlang.io/is/iD9ydu I made a typo in one of the comments. Here's the fixed version: https://run.dlang.io/is/HRqYcZ

Re: is this a betterC bug ?

2018-08-15 Thread Petar via Digitalmars-d-learn
On Tuesday, 14 August 2018 at 17:49:32 UTC, Mike Franklin wrote: On Tuesday, 14 August 2018 at 17:22:42 UTC, Seb wrote: FYI: staticArray will be part of 2.082, it already works with dmd-nightly: That just seems wrong. Isn't the fact that `staticArray` is needed a bug in the compiler? I

Re: Linking a C program with D library

2018-08-15 Thread Mike Parker via Digitalmars-d-learn
On Wednesday, 15 August 2018 at 02:40:22 UTC, Joe wrote: I understand that, Mike. However if I'm not mistaken given something in C like char* strs[] = { "This", "is a", "test"}; AFAIK, even with -betterC and an extern (C), the literals will still be understood by D as type "string", and