Re: D --> C++ --> D

2016-03-31 Thread MGW via Digitalmars-d-learn
On Thursday, 31 March 2016 at 11:47:34 UTC, MGW wrote: -- Help me to optimize this source code. How to apply here delegates and generally whether possibly to make it here

Re: Direntries seems to on other drives. (windows)

2016-03-31 Thread rikki cattermole via Digitalmars-d-learn
On 01/04/2016 3:05 PM, Taylor Hillegeist wrote: SO i have a maximum scope depth tool, that i just put together it is super simple. but when i use it in a drive other that C:\ i get an error. Even though i just checked for a valid path. Any ideas?

Direntries seems to on other drives. (windows)

2016-03-31 Thread Taylor Hillegeist via Digitalmars-d-learn
SO i have a maximum scope depth tool, that i just put together it is super simple. but when i use it in a drive other that C:\ i get an error. Even though i just checked for a valid path. Any ideas? C:\Users\taylor.hillegeist\Documents\CodeSync\D projects\Toys\TOOLS>NestCheck.exe

Re: Solution to "statement is not reachable" depending on template variables?

2016-03-31 Thread Walter Bright via Digitalmars-d-learn
On 3/16/2016 4:18 AM, Johan Engelen wrote: I've found discussions, but not an actual "recommended" solution for the problem of "statement is not reachable" warnings in templates with early returns, e.g.: ``` bool nobool(T...)() { foreach (i, U; T) { static if (is(U == bool)) {

Re: How can convert the folowing to D.

2016-03-31 Thread Ali Çehreli via Digitalmars-d-learn
On 03/31/2016 05:34 PM, learner wrote: Hi, I have the following code in C++. rectangles.erase(rectangles.begin() + index); where rectangles is: std::vector rectangles; how can I do something similar in D. Learner. import std.stdio; void main() { int[] a = [ 1, 2, 3, 4, 5 ];

How can convert the folowing to D.

2016-03-31 Thread learner via Digitalmars-d-learn
Hi, I have the following code in C++. rectangles.erase(rectangles.begin() + index); where rectangles is: std::vector rectangles; how can I do something similar in D. Learner.

Re: Can i get a array Slicing where the top from?and how?

2016-03-31 Thread Ali Çehreli via Digitalmars-d-learn
On 03/30/2016 11:39 PM, Dsby wrote: > Like this: > > ubyte[] fun() > { > ubyte[] str = cast(ubyte[])"hello world"; > ubyte[] by = Mallocator.instance.allocate(str.length); > by[] = str[]; > return by[5..$]; > } > > void mian() > { > ubyte[] aa = fun(); > // i want

Re: Async read an output stream but how many bytes ?

2016-03-31 Thread Basile B. via Digitalmars-d-learn
On Thursday, 31 March 2016 at 13:48:46 UTC, Steven Schveighoffer wrote: stdio.readf is buffered. It does not deal with async io properly I think. -Steve Yes, I must use core.sys.posix.unistd.read, which was actually what A.D.Ruppe suggested, I think.

Re: std.format.formattedRead docs example does not work with a string literal as input, why?

2016-03-31 Thread ParticlePeter via Digitalmars-d-learn
On Thursday, 31 March 2016 at 18:25:45 UTC, H. S. Teoh wrote: On Thu, Mar 31, 2016 at 06:23:21PM +, ParticlePeter via Digitalmars-d-learn wrote: Example from docs: string s = "hello!124:34.5"; string a; int b; double c; formattedRead(s, "%s!%s:%s", , , ); assert(a == "hello" && b == 124 &&

Re: trying to implement lock-free fixedsize queue

2016-03-31 Thread MrSmith via Digitalmars-d-learn
On Thursday, 31 March 2016 at 18:25:46 UTC, jacob wrote: I try to implement chunk (something like lock-free fixedsize queue) ... Check out this implementation https://github.com/MartinNowak/lock-free/blob/master/src/lock_free/rwqueue.d

Re: std.format.formattedRead docs example does not work with a string literal as input, why?

2016-03-31 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Mar 31, 2016 at 06:23:21PM +, ParticlePeter via Digitalmars-d-learn wrote: > Example from docs: > string s = "hello!124:34.5"; > string a; > int b; > double c; > formattedRead(s, "%s!%s:%s", , , ); > assert(a == "hello" && b == 124 && c == 34.5); > > now changing the first

trying to implement lock-free fixedsize queue

2016-03-31 Thread jacob via Digitalmars-d-learn
I try to implement chunk (something like lock-free fixedsize queue) -- import core.atomic; shared struct Chunk(T, uint N) { shared T[N] data; shared uint count; shared uint queueCounter; @property uint capacity() { return N; } @property uint count() {

std.format.formattedRead docs example does not work with a string literal as input, why?

2016-03-31 Thread ParticlePeter via Digitalmars-d-learn
Example from docs: string s = "hello!124:34.5"; string a; int b; double c; formattedRead(s, "%s!%s:%s", , , ); assert(a == "hello" && b == 124 && c == 34.5); now changing the first formattedRead argument to a string literal: formattedRead("hello!124:34.5", "%s!%s:%s", , , ); results in this

Re: Issue Turning Template into Variadic Template

2016-03-31 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Mar 31, 2016 at 07:43:38PM +0200, ag0aep6g via Digitalmars-d-learn wrote: > On 30.03.2016 20:12, jmh530 wrote: > >I wrote a version of cartesianProduct that will return the cartesian > >product when the some of the types are not ranges. The original code > >is below. > > > >My issue is

Re: Issue Turning Template into Variadic Template

2016-03-31 Thread ag0aep6g via Digitalmars-d-learn
On 30.03.2016 20:12, jmh530 wrote: I wrote a version of cartesianProduct that will return the cartesian product when the some of the types are not ranges. The original code is below. My issue is that I can't figure out how to turn it into a variadic template. The latest thing I tried is: auto

Re: const(int) cannot be sent as int message

2016-03-31 Thread Meta via Digitalmars-d-learn
On Thursday, 31 March 2016 at 13:47:25 UTC, Steven Schveighoffer wrote: Bug, but probably of the enhancement variety I think (I don't think this is a small project). Receive should canonicalize the input and requested receive type. That is, receiveOnly!(const(int)) should really call

Re: pure opApply

2016-03-31 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/31/16 10:30 AM, Q. Schroll wrote: On Thursday, 31 March 2016 at 13:51:00 UTC, Steven Schveighoffer wrote: I think it's a bug. foreach and opApply are specially coded in the compiler I think, so there's bound to be inconsistencies between them and normal overload rules. I have never

Re: pure opApply

2016-03-31 Thread Q. Schroll via Digitalmars-d-learn
On Thursday, 31 March 2016 at 13:51:00 UTC, Steven Schveighoffer wrote: I think it's a bug. foreach and opApply are specially coded in the compiler I think, so there's bound to be inconsistencies between them and normal overload rules. -Steve I have never filed a bug report. Should this be

Re: foreach UFCS

2016-03-31 Thread ixid via Digitalmars-d-learn
On Thursday, 31 March 2016 at 13:48:27 UTC, Adam D. Ruppe wrote: It is trying to look up a name i in global scope, and calling writeln on it. This is why the .name syntax exists: so you can bypass local variables with the same name when trying to access a global. It would compile if you put

Re: pure opApply

2016-03-31 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/31/16 6:23 AM, Q. Schroll wrote: Simple as that, shouldn't this work? struct X { int opApply(int delegate(string) dg) { return dg("impure"); } int opApply(int delegate(string) pure dg) pure { return dg("pure"); } } void main() { X x;

Re: foreach UFCS

2016-03-31 Thread Q. Schroll via Digitalmars-d-learn
On Thursday, 31 March 2016 at 13:39:25 UTC, ixid wrote: What is going on with UFCS and foreach? foreach(i;0..5).writeln; This is not UFCS; it is calling writeln on module scope. See http://dlang.org/spec/module.html#module_scope_operators Your code is semantically identical with foreach

Re: Async read an output stream but how many bytes ?

2016-03-31 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/30/16 10:06 PM, Basile B. wrote: On Thursday, 31 March 2016 at 01:12:50 UTC, Adam D. Ruppe wrote: On Thursday, 31 March 2016 at 00:50:16 UTC, Basile B. wrote: There should be a way to know how many bytes are available ? You are already using poll()... I'd just use read() directly on the

Re: foreach UFCS

2016-03-31 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 31 March 2016 at 13:39:25 UTC, ixid wrote: What is going on with UFCS and foreach? There's no such thing as UFCS on foreach. UFCS only works on variables, not a foreach statement. foreach(i;0..5).writeln; You can add a line break and optional braces there to see what it

Re: foreach UFCS

2016-03-31 Thread Rene Zwanenburg via Digitalmars-d-learn
On Thursday, 31 March 2016 at 13:39:25 UTC, ixid wrote: What is going on with UFCS and foreach? foreach(i;0..5).writeln; This prints five line breaks. foreach(i;0..5).i.writeln; This will not compile. foreach(i;0..5).writeln(i); This writes out 1 to 4 on separate lines. Is this supposed to

Re: const(int) cannot be sent as int message

2016-03-31 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/30/16 8:01 PM, Ali Çehreli wrote: As expected, the following trivial case works: void main() { auto func = delegate(int i) {}; // expects int func(const(int)(42));// passes const(int) } The following concurrency program fails at runtime: import core.thread;

foreach UFCS

2016-03-31 Thread ixid via Digitalmars-d-learn
What is going on with UFCS and foreach? foreach(i;0..5).writeln; This prints five line breaks. foreach(i;0..5).i.writeln; This will not compile. foreach(i;0..5).writeln(i); This writes out 1 to 4 on separate lines. Is this supposed to work? I thought a.b would be rewritten to b(a) with

Re: char array weirdness

2016-03-31 Thread Jack Stouffer via Digitalmars-d-learn
On Thursday, 31 March 2016 at 12:49:57 UTC, ag0aep6g wrote: I get theses timings then: auto-decoding 642 ms, 969 μs, and 1 hnsec byCodeUnit 84 ms, 980 μs, and 3 hnsecs And 643 / 85 ≅ 8. Ok, so not as bad as 100x, but still not great by any means. I think I

Re: char array weirdness

2016-03-31 Thread ag0aep6g via Digitalmars-d-learn
On 31.03.2016 07:40, Jack Stouffer wrote: $ ldc2 -O3 -release -boundscheck=off test.d $ ./test auto-decoding1 sec, 757 ms, and 946 μs byCodeUnit87 ms, 731 μs, and 8 hnsecs byGrapheme14 secs, 769 ms, 796 μs, and 6 hnsecs So the auto-decoding version takes about twenty

Re: Issue Turning Template into Variadic Template

2016-03-31 Thread jmh530 via Digitalmars-d-learn
On Thursday, 31 March 2016 at 10:27:41 UTC, Artur Skawina wrote: auto mixedCartesianProduct(T...)(T x) { import std.range, std.algorithm : cartesianProduct; return mixin(`cartesianProduct(`~iota(T.length).map!`"conditionalOnly(x["~text(a)~"])"`().join(",")~`)`); }

Re: Continuous integral range predicate

2016-03-31 Thread Nordlöw via Digitalmars-d-learn
On Thursday, 31 March 2016 at 11:41:17 UTC, Rene Zwanenburg wrote: std.algorithm.findAdjacent!((a, b) => a != b+1)(range).empty; Correction: Should be: std.algorithm.findAdjacent!((a, b) => a+1 != b)(range).empty; Thanks!

D --> C++ --> D

2016-03-31 Thread MGW via Digitalmars-d-learn
I for myself write Qt-5 wrapper. I use calls from Qt (C ++) as extern (C) calls. Prompt how to write this code well and with use of abilities to integrate D and C ++ -- // ex4.d - Concepts of QAction.QtE5 // compile - // dmd ex4 qte5 import core.runtime; import

Re: Continuous integral range predicate

2016-03-31 Thread Rene Zwanenburg via Digitalmars-d-learn
On Thursday, 31 March 2016 at 11:33:36 UTC, Nordlöw wrote: Is there a function in Phobos to check if a range of integral elements is adjacent, that is x[i+1] == x[i] + 1 where x[i] is the i:th element of the range. (untested) std.algorithm.findAdjacent!((a, b) => a !=

Continuous integral range predicate

2016-03-31 Thread Nordlöw via Digitalmars-d-learn
Is there a function in Phobos to check if a range of integral elements is adjacent, that is x[i+1] == x[i] + 1 where x[i] is the i:th element of the range.

Re: Is there anybody who used FireBird DB?

2016-03-31 Thread Suliman via Digitalmars-d-learn
On Thursday, 31 March 2016 at 08:53:46 UTC, Kagamin wrote: AFAIK when you request a string, whatever value is there gets converted to string. Or you can just add code to extract blobs, that would be less effort than writing everything from scratch. I have contact with it's developer. Hope for

Re: Issue Turning Template into Variadic Template

2016-03-31 Thread Artur Skawina via Digitalmars-d-learn
On 03/30/16 20:12, jmh530 via Digitalmars-d-learn wrote: > I wrote a version of cartesianProduct that will return the cartesian product > when the some of the types are not ranges. The original code is below. > > My issue is that I can't figure out how to turn it into a variadic template. >

pure opApply

2016-03-31 Thread Q. Schroll via Digitalmars-d-learn
Simple as that, shouldn't this work? struct X { int opApply(int delegate(string) dg) { return dg("impure"); } int opApply(int delegate(string) pure dg) pure { return dg("pure"); } } void main() { X x; string result; x.opApply(

Re: Is there anybody who used FireBird DB?

2016-03-31 Thread Kagamin via Digitalmars-d-learn
AFAIK when you request a string, whatever value is there gets converted to string. Or you can just add code to extract blobs, that would be less effort than writing everything from scratch.

Can i get a array Slicing where the top from?and how?

2016-03-31 Thread Dsby via Digitalmars-d-learn
Like this: ubyte[] fun() { ubyte[] str = cast(ubyte[])"hello world"; ubyte[] by = Mallocator.instance.allocate(str.length); by[] = str[]; return by[5..$]; } void mian() { ubyte[] aa = fun(); // i want free the aa's momeny. //Mallocator.instance.deallocate(aa);// it is