Re: How to abort compilation

2015-07-12 Thread Rikki Cattermole via Digitalmars-d-learn
On 13/07/2015 6:36 p.m., tcak wrote: To keep the story short (if necessary, I can explain the use-case), if there any way to abort compilation with a message. I would use "static if" or "version" to check a situation, and "pragma msg" to show a message. But I couldn't have found any "proper" way

How to abort compilation

2015-07-12 Thread tcak via Digitalmars-d-learn
To keep the story short (if necessary, I can explain the use-case), if there any way to abort compilation with a message. I would use "static if" or "version" to check a situation, and "pragma msg" to show a message. But I couldn't have found any "proper" way to abort compilation.

Re: Understanding Safety of Function Pointers vs. Addresses of Functions

2015-07-12 Thread Laeeth Isharc via Digitalmars-d-learn
I don't know what exactly you're after, but you can use foreach on a whatever-they're-called-now tuple (there's been a discussion about the name which I haven't followed; I mean the kind you get from a TemplateTupleParameter): void f1() {} void f2() {} void callThemAll(functions ...)() {

Re: Understanding Safety of Function Pointers vs. Addresses of Functions

2015-07-12 Thread jmh530 via Digitalmars-d-learn
On Sunday, 12 July 2015 at 22:26:44 UTC, anonymous wrote: You don't need the lambda, do you? -> return x.map!fun.array; You're right. I don't know what exactly you're after, but you can use foreach on a whatever-they're-called-now tuple (there's been a discussion about the name which I h

if you fancy stressing your json implementation, string processing, allocation etc with some real data...

2015-07-12 Thread Laeeth Isharc via Digitalmars-d-learn
https://www.reddit.com/r/datasets/comments/3bxlg7/i_have_every_publicly_available_reddit_comment/

Re: Understanding Safety of Function Pointers vs. Addresses of Functions

2015-07-12 Thread anonymous via Digitalmars-d-learn
On Sunday, 12 July 2015 at 21:07:34 UTC, jmh530 wrote: private template givemeabettername(alias fun) { T givemeabettername(T : U[], U)(T x) if (isArray!(T)) { return x.map!(a => fun(a)).array; You don't need the lambda, do you? -> return x.map!fun.array; } } Very

Re: Understanding Safety of Function Pointers vs. Addresses of Functions

2015-07-12 Thread jmh530 via Digitalmars-d-learn
On Sunday, 12 July 2015 at 20:31:20 UTC, jmh530 wrote: On Sunday, 12 July 2015 at 17:11:04 UTC, anonymous wrote: And personally, I'd probably just type out `x.map!fun.array` every time. [1] http://dlang.org/hijack.html Thanks for the comments. After thinking it over, I think you're absol

Re: Understanding Safety of Function Pointers vs. Addresses of Functions

2015-07-12 Thread jmh530 via Digitalmars-d-learn
On Sunday, 12 July 2015 at 17:11:04 UTC, anonymous wrote: And personally, I'd probably just type out `x.map!fun.array` every time. [1] http://dlang.org/hijack.html Thanks for the comments.

Re: opApply compilation woes

2015-07-12 Thread Gary Willoughby via Digitalmars-d-learn
On Sunday, 12 July 2015 at 17:33:50 UTC, anonymous wrote: On Sunday, 12 July 2015 at 17:25:17 UTC, Gary Willoughby wrote: Why does the following code fail to compile if the `writeln(value);` line is present? The error message (formatted to be a little more readable): Error: function test2

Re: opApply compilation woes

2015-07-12 Thread anonymous via Digitalmars-d-learn
On Sunday, 12 July 2015 at 17:25:17 UTC, Gary Willoughby wrote: Why does the following code fail to compile if the `writeln(value);` line is present? The error message (formatted to be a little more readable): Error: function test2.__unittestL6_1.Foo.opApply (int delegate(ref string) not

opApply compilation woes

2015-07-12 Thread Gary Willoughby via Digitalmars-d-learn
Why does the following code fail to compile if the `writeln(value);` line is present? public template ForeachAggregate(T) { alias ForeachAggregate = int delegate(ref T) nothrow; } unittest { import std.stdio; class Foo { private string[] _data =

Re: socket server help

2015-07-12 Thread Adwelean via Digitalmars-d-learn
Finally, I decide to use https://github.com/etcimon/libasync and now it work well. Thank you for your answers.

Re: Understanding Safety of Function Pointers vs. Addresses of Functions

2015-07-12 Thread anonymous via Digitalmars-d-learn
On Sunday, 12 July 2015 at 16:34:17 UTC, jmh530 wrote: I've been playing around with this a little more. I wrote this function to encapsulate a simple operation on arrays. U array_fun(T, U)(T fp, U x) if (isFunctionPointer!(T) && isArray!(U)) { return x.map!(a => fp(a)).array; }

Re: Understanding Safety of Function Pointers vs. Addresses of Functions

2015-07-12 Thread jmh530 via Digitalmars-d-learn
On Wednesday, 8 July 2015 at 18:31:00 UTC, Steven Schveighoffer wrote: You can use a function lambda: auto fp = (real a) => cos(a); Note, I had to put (real a) even though I would have expected "a => cos(a)" to work. -Steve I've been playing around with this a little more. I wrote this f

Re: Manually allocate delegate?

2015-07-12 Thread Adam D. Ruppe via Digitalmars-d-learn
On Sunday, 12 July 2015 at 08:38:01 UTC, Tofu Ninja wrote: Is it even possible? Yes, though you need to use an entirely different approach for closures: make a struct. Remember that delegates can come from local variable use or a `this` object being used and work the same way to the outside

Re: Manually allocate delegate?

2015-07-12 Thread Adam D. Ruppe via Digitalmars-d-learn
On Sunday, 12 July 2015 at 11:42:09 UTC, ketmar wrote: nope. there is no way to overload context allocation function, afaik. at least without patching druntime, and i still don't know what one have to patch. ;-) _d_allocmemory

Re: Manually allocate delegate?

2015-07-12 Thread Tofu Ninja via Digitalmars-d-learn
On Sunday, 12 July 2015 at 11:42:09 UTC, ketmar wrote: On Sun, 12 Jul 2015 09:03:24 +, Tofu Ninja wrote: On Sunday, 12 July 2015 at 08:47:37 UTC, ketmar wrote: On Sun, 12 Jul 2015 08:38:00 +, Tofu Ninja wrote: Is it even possible? what do you mean? Sorry, thought the title was en

Re: Manually allocate delegate?

2015-07-12 Thread Tofu Ninja via Digitalmars-d-learn
On Sunday, 12 July 2015 at 11:22:41 UTC, Baz wrote: At least now your Question is clearer and understandable...but sorry goodbye. I don't feel good vibes here. See ya ^^. Sorry if I came off as rude, didn't mean to... >.>

Re: Manually allocate delegate?

2015-07-12 Thread ketmar via Digitalmars-d-learn
On Sun, 12 Jul 2015 09:03:24 +, Tofu Ninja wrote: > On Sunday, 12 July 2015 at 08:47:37 UTC, ketmar wrote: >> On Sun, 12 Jul 2015 08:38:00 +, Tofu Ninja wrote: >> >>> Is it even possible? >> >> what do you mean? > > Sorry, thought the title was enough. > > The context for a delegate(assu

Re: Manually allocate delegate?

2015-07-12 Thread Baz via Digitalmars-d-learn
On Sunday, 12 July 2015 at 10:39:44 UTC, Tofu Ninja wrote: On Sunday, 12 July 2015 at 10:19:02 UTC, Baz wrote: [...] That is not manually allocating a delegate context, and & in that instance does not even allocate. For delegates to class methods, the context is just the "this" pointer of th

Re: Manually allocate delegate?

2015-07-12 Thread Tofu Ninja via Digitalmars-d-learn
On Sunday, 12 July 2015 at 10:19:02 UTC, Baz wrote: You can copy a delegate in a GC-free chunk but so far i think that the simple fact to get a delegate with "&" will allocate from the GC. By the way i'd be interested to see the runtime function that creates a delegate. i see nothing in drun

Re: Manually allocate delegate?

2015-07-12 Thread Baz via Digitalmars-d-learn
On Sunday, 12 July 2015 at 09:03:25 UTC, Tofu Ninja wrote: On Sunday, 12 July 2015 at 08:47:37 UTC, ketmar wrote: On Sun, 12 Jul 2015 08:38:00 +, Tofu Ninja wrote: Is it even possible? what do you mean? Sorry, thought the title was enough. The context for a delegate(assuming not a met

Re: Manually allocate delegate?

2015-07-12 Thread Tofu Ninja via Digitalmars-d-learn
On Sunday, 12 July 2015 at 08:47:37 UTC, ketmar wrote: On Sun, 12 Jul 2015 08:38:00 +, Tofu Ninja wrote: Is it even possible? what do you mean? Sorry, thought the title was enough. The context for a delegate(assuming not a method delegate) is allocated by the GC. Is there any way to a

Re: Manually allocate delegate?

2015-07-12 Thread ketmar via Digitalmars-d-learn
On Sun, 12 Jul 2015 08:38:00 +, Tofu Ninja wrote: > Is it even possible? what do you mean? signature.asc Description: PGP signature

Manually allocate delegate?

2015-07-12 Thread Tofu Ninja via Digitalmars-d-learn
Is it even possible?