Re: wth!! ctfe cannot format floating point at compile time?

2017-08-14 Thread Stefan Koch via Digitalmars-d-learn
On Monday, 14 August 2017 at 04:29:17 UTC, Johnson wrote: ``` auto valueToString(alias v)(){return v.stringof;} enum a = valueToString!(0.75); static assert(a == "0.75"); ``` Thanks! You'd think that to would do this internally automatically ;/ It only works on literals. valueToString!(a) wil

Re: Does anyone understand how to use "shared" types with concurrency send/receive functions?

2017-08-14 Thread via Digitalmars-d-learn
On Monday, 14 August 2017 at 03:59:48 UTC, Jonathan M Davis wrote: [snip] Now, the fact that the mutex objects don't handle shared correctly is another issue entirely. Having to cast away shared from mutexes is dumb, because you're obviously not going to be protecting them with a mutex, and t

Re: string hash significant speedup

2017-08-14 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/10/17 5:10 PM, Johnson Jones wrote: On Thursday, 10 August 2017 at 20:07:35 UTC, Steven Schveighoffer wrote: On 8/10/17 3:36 PM, Johnson Jones wrote: when using T[string], hashing is used. Computing the hash is slow(relatively speaking). Does D cache the hashes? Strings are immutable so

Re: string hash significant speedup

2017-08-14 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/10/17 6:30 PM, HyperParrow wrote: On Thursday, 10 August 2017 at 20:07:35 UTC, Steven Schveighoffer wrote: On 8/10/17 3:36 PM, Johnson Jones wrote: when using T[string], hashing is used. Computing the hash is slow(relatively speaking). Does D cache the hashes? Strings are immutable so th

Re: wth!! ctfe cannot format floating point at compile time?

2017-08-14 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/13/17 11:44 PM, Adam D. Ruppe wrote: On Monday, 14 August 2017 at 01:52:16 UTC, Johnson Jones wrote: pretty simply, trying to convert a floating point to a string in a ctfe function and it thinks that it is too complex to do in a ctfe, really? It uses a C function to do the conversion, w

Re: WebCam or Video in D

2017-08-14 Thread Guillaume Piolat via Digitalmars-d-learn
On Monday, 14 August 2017 at 04:41:24 UTC, brian wrote: Howdy folks. Has anyone gotten an example of using D as mechanism to read in video files, specifically from a webcam? I don't see any OpenCV libraries, and the example in the DCV library that uses FFMPEG, I can't get to work (I've raise

Re: wth!! ctfe cannot format floating point at compile time?

2017-08-14 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 14 August 2017 at 13:11:20 UTC, Steven Schveighoffer wrote: Another reasonable idea is to have the compiler call the function for you. Yeah, I was thinking that too. Heck, the compiler prolly uses it for reading source and writing errors. Perhaps just special case hack the functio

How to specify a template that uses unqualified type, like any normal function

2017-08-14 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
if I use fixed-type functions, I can do the following: uint foo(uint n) { ++n; // modify n - as this function has received a copy of n, this is always possible return 42; } uint bar(const uint n) { assert(foo(n)==42); return 17; } void main() { bar(3); } But if I try the same

Initialization of struct containing anonymous union

2017-08-14 Thread Carl Sturtivant via Digitalmars-d-learn
struct mess { union { int i; string s; } double x; } How do I cleanly initialize this, assuming it's i that I want to give an overt value to? The docs say "If there are anonymous unions in the struct, only the first member of the anonymous union can be in

Re: Initialization of struct containing anonymous union

2017-08-14 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/14/17 9:49 AM, Carl Sturtivant wrote: struct mess { union { int i; string s; } double x; } How do I cleanly initialize this, assuming it's i that I want to give an overt value to? The docs say "If there are anonymous unions in the struct, on

Re: Initialization of struct containing anonymous union

2017-08-14 Thread Carl Sturtivant via Digitalmars-d-learn
On Monday, 14 August 2017 at 14:24:40 UTC, Steven Schveighoffer wrote: I think what the docs mean is that as soon as an anonymous union is present, you can't initialize anything further than the first union field. I understood that, hence my remark that "this is not helpful". So it seems I

Re: Initialization of struct containing anonymous union

2017-08-14 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/14/17 10:36 AM, Carl Sturtivant wrote: On Monday, 14 August 2017 at 14:24:40 UTC, Steven Schveighoffer wrote: I think what the docs mean is that as soon as an anonymous union is present, you can't initialize anything further than the first union field. I understood that, hence my remar

Re: Initialization of struct containing anonymous union

2017-08-14 Thread Carl Sturtivant via Digitalmars-d-learn
On Monday, 14 August 2017 at 14:49:57 UTC, Steven Schveighoffer wrote: On 8/14/17 10:36 AM, Carl Sturtivant wrote: On Monday, 14 August 2017 at 14:24:40 UTC, Steven Schveighoffer wrote: I think what the docs mean is that as soon as an anonymous union is present, you can't initialize anything

Re: How to specify a template that uses unqualified type, like any normal function

2017-08-14 Thread Mengu via Digitalmars-d-learn
On Monday, 14 August 2017 at 13:48:36 UTC, Dominikus Dittes Scherkl wrote: if I use fixed-type functions, I can do the following: uint foo(uint n) { ++n; // modify n - as this function has received a copy of n, this is always possible return 42; } uint bar(const uint n) { assert(foo(

Re: Initialization of struct containing anonymous union

2017-08-14 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/14/17 10:57 AM, Carl Sturtivant wrote: On Monday, 14 August 2017 at 14:49:57 UTC, Steven Schveighoffer wrote: On 8/14/17 10:36 AM, Carl Sturtivant wrote: On Monday, 14 August 2017 at 14:24:40 UTC, Steven Schveighoffer wrote: I think what the docs mean is that as soon as an anonymous unio

Re: How to specify a template that uses unqualified type, like any normal function

2017-08-14 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/14/17 9:48 AM, Dominikus Dittes Scherkl wrote: if I use fixed-type functions, I can do the following: uint foo(uint n) { ++n; // modify n - as this function has received a copy of n, this is always possible return 42; } uint bar(const uint n) { assert(foo(n)==42); return

Re: Initialization of struct containing anonymous union

2017-08-14 Thread Carl Sturtivant via Digitalmars-d-learn
On Monday, 14 August 2017 at 15:11:35 UTC, Steven Schveighoffer wrote: On 8/14/17 10:57 AM, Carl Sturtivant wrote: On Monday, 14 August 2017 at 14:49:57 UTC, Steven Schveighoffer wrote: On 8/14/17 10:36 AM, Carl Sturtivant wrote: On Monday, 14 August 2017 at 14:24:40 UTC, Steven Schveighoffer

Re: How to specify a template that uses unqualified type, like any normal function

2017-08-14 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
On Monday, 14 August 2017 at 15:20:28 UTC, Steven Schveighoffer wrote: On 8/14/17 9:48 AM, Dominikus Dittes Scherkl wrote: > uint foo(T)(Unqual!T n) // first try > { > ++n; // modify should be possible > return 42; > } > Any ideas what I need to do to make this work? This isn't exactly s

Re: Does anyone understand how to use "shared" types with concurrency send/receive functions?

2017-08-14 Thread Arek via Digitalmars-d-learn
On Monday, 14 August 2017 at 03:40:26 UTC, Jonathan M Davis wrote: On Saturday, August 12, 2017 18:57:44 Arek via Digitalmars-d-learn wrote: I have the folowing problem: I like to envelope the class object in struct to control the destruction moment and then send this object to another thread/fi

Re: Does anyone understand how to use "shared" types with concurrency send/receive functions?

2017-08-14 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/13/17 11:40 PM, Jonathan M Davis via Digitalmars-d-learn wrote: On Saturday, August 12, 2017 18:57:44 Arek via Digitalmars-d-learn wrote: I have the folowing problem: I like to envelope the class object in struct to control the destruction moment and then send this object to another thread/

Re: Does anyone understand how to use "shared" types with concurrency send/receive functions?

2017-08-14 Thread Arek via Digitalmars-d-learn
On Monday, 14 August 2017 at 03:59:48 UTC, Jonathan M Davis wrote: On Sunday, August 13, 2017 16:40:03 crimaniak via Digitalmars-d-learn wrote: More of this, I think, you can't avoid __gshared for any complex work. Even mutexes from Phobos doesn't support shared, so I had to 'cowboy with __gsha

Re: Does anyone understand how to use "shared" types with concurrency send/receive functions?

2017-08-14 Thread Arek via Digitalmars-d-learn
On Monday, 14 August 2017 at 19:22:23 UTC, Steven Schveighoffer wrote: On 8/13/17 11:40 PM, Jonathan M Davis via Digitalmars-d-learn wrote: On Saturday, August 12, 2017 18:57:44 Arek via Digitalmars-d-learn wrote: I have the folowing problem: I like to envelope the class object in struct to con

Re: Does anyone understand how to use "shared" types with concurrency send/receive functions?

2017-08-14 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, August 14, 2017 15:22:23 Steven Schveighoffer via Digitalmars-d- learn wrote: > On 8/13/17 11:40 PM, Jonathan M Davis via Digitalmars-d-learn wrote: > > On Saturday, August 12, 2017 18:57:44 Arek via Digitalmars-d-learn wrote: > >> I have the folowing problem: > >> I like to envelope th

Re: How to specify a template that uses unqualified type, like any normal function

2017-08-14 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
On Monday, 14 August 2017 at 17:43:44 UTC, Dominikus Dittes Scherkl wrote: On Monday, 14 August 2017 at 15:20:28 UTC, Steven Schveighoffer wrote: What you can do, is: auto foo(T)(T n) if (is(T == Unqual!T)) { // normal implementation } auto foo(T)(T n) if (!is(T == Unqual!T) && isImplicitl

Re: Does anyone understand how to use "shared" types with concurrency send/receive functions?

2017-08-14 Thread Arek via Digitalmars-d-learn
On Monday, 14 August 2017 at 21:27:48 UTC, Jonathan M Davis wrote: On Monday, August 14, 2017 15:22:23 Steven Schveighoffer via Digitalmars-d- learn wrote: On 8/13/17 11:40 PM, Jonathan M Davis via Digitalmars-d-learn wrote: > On Saturday, August 12, 2017 18:57:44 Arek via > Digitalmars-d-learn

Re: How to specify a template that uses unqualified type, like any normal function

2017-08-14 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, August 14, 2017 17:43:44 Dominikus Dittes Scherkl via Digitalmars-d-learn wrote: > On Monday, 14 August 2017 at 15:20:28 UTC, Steven Schveighoffer > > wrote: > > On 8/14/17 9:48 AM, Dominikus Dittes Scherkl wrote: > > > uint foo(T)(Unqual!T n) // first try > > > { > > > > > > ++n; /

Re: How to specify a template that uses unqualified type, like any normal function

2017-08-14 Thread ag0aep6g via Digitalmars-d-learn
On 08/15/2017 12:14 AM, Dominikus Dittes Scherkl wrote: T foo(T)(T n) { static if(!is(Unqual!T == T)) return foo!(Unqual!T)(n); else { // normal implementation } } So it's basically 2 lines of overhead. That's acceptable. The check for isImplicitlyConvertible is not nece

Re: html fetcher/parser

2017-08-14 Thread Faux Amis via Digitalmars-d-learn
On 2017-08-13 19:51, Adam D. Ruppe wrote: On Sunday, 13 August 2017 at 15:54:45 UTC, Faux Amis wrote: Just curious, but is there a spec of sorts which defines which errors should be fixed and such? The HTML5 spec describes how you are supposed to parse various things, including the recovery p

Re: html fetcher/parser

2017-08-14 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 14 August 2017 at 23:15:13 UTC, Faux Amis wrote: (Althought following the spec would be the first step to a D html layout engine :D ) Oh, I've actually done some of that before too. https://github.com/adamdruppe/arsd/blob/master/htmlwidget.d It is pretty horrible... but managed to

Issues with std.format template function

2017-08-14 Thread LeqxLeqx via Digitalmars-d-learn
Hello! I'm having issues with the format function. My program is as follows: import std.format; import std.stdio; int main () { auto s = format!"%s is %s"("Pi", 3.14); writeln(s); // "Pi is 3.14"; } and when compiling with GDC, I'm getting this error: test.d:8: erro

Re: Issues with std.format template function

2017-08-14 Thread HyperParrow via Digitalmars-d-learn
On Tuesday, 15 August 2017 at 04:44:25 UTC, LeqxLeqx wrote: Hello! I'm having issues with the format function. My program is as follows: import std.format; import std.stdio; int main () { auto s = format!"%s is %s"("Pi", 3.14); writeln(s); // "Pi is 3.14"; } and when