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 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

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: DUB Different Library Name

2015-07-12 Thread serh via Digitalmars-d-learn
On Sunday, 12 July 2015 at 05:18:24 UTC, Mike Parker wrote: This has nothing to do with DMD, DUB, or linking :) Derelict loads the shared libraries at runtime through the system API (LoadLibrary on Windows and dlopen elsewhere). Each package has a default set of library names it looks for. I

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 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

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

Manually allocate delegate?

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

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

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

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

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 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 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

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

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

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 the

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(assuming not a

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: 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.

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: 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)

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

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