Find on sorted range slower?

2015-08-06 Thread Tofu Ninja via Digitalmars-d-learn
void main() { auto a = new int[100*1024*1024]; for(int i = 0; i 100*1024*1024; i++) { a[i] = i; } enum f = 100*1024*1000; StopWatch sw; { sw.start(); auto temp = assumeSorted(a).find(f);

Re: Find on sorted range slower?

2015-08-06 Thread Tofu Ninja via Digitalmars-d-learn
On Friday, 7 August 2015 at 01:26:51 UTC, John Colvin wrote: As usual, which compiler, which compiler version, which compilation flags? dmd v2.067.1 -O -release -w -inline -boundscheck=off

Re: Yes or No Options

2015-07-27 Thread Tofu Ninja via Digitalmars-d-learn
On Monday, 27 July 2015 at 16:48:00 UTC, Alex wrote: Okay. By pure trying I found out what I did wrong: Apparently by typing Y I entered the shift key. Could that have been the problem? I changed it to a small y and it at least jumped back to the commandline instead of just being stuck. And

Re: Manually allocate delegate?

2015-07-13 Thread Tofu Ninja via Digitalmars-d-learn
On Sunday, 12 July 2015 at 12:56:17 UTC, Adam D. Ruppe wrote: 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. [...] This seems like a reasonable solution, even though

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

Function pointer array slice?

2015-07-11 Thread Tofu Ninja via Digitalmars-d-learn
So simple syntax question, how do I make an array slice of function pointers? I just have no idea where to put the [] on something like void function() nothrow pure @nogc @safe arrayName; Or should I just alias it and make an array of the alias? alias f = void function() nothrow

Re: Function pointer array slice?

2015-07-11 Thread Tofu Ninja via Digitalmars-d-learn
On Saturday, 11 July 2015 at 10:54:45 UTC, ketmar wrote: On Sat, 11 Jul 2015 09:54:40 +, tcak wrote: On Saturday, 11 July 2015 at 09:30:43 UTC, Tofu Ninja wrote: So simple syntax question, how do I make an array slice of function pointers? I just have no idea where to put the [] on

Re: Pure delegate not quite pure?

2015-07-01 Thread Tofu Ninja via Digitalmars-d-learn
On Wednesday, 1 July 2015 at 12:34:35 UTC, Steven Schveighoffer wrote: immutable is probably incorrect without a cast, since immutable cannot be applied implicitly to non-immutable data, and if the data is all immutable already, no sense in tagging it immutable. I really see use in allowing

Re: Static constructors guaranteed to run?

2015-06-30 Thread Tofu Ninja via Digitalmars-d-learn
On Monday, 29 June 2015 at 11:36:42 UTC, ketmar wrote: it doesn't, afair, but it's quite natural. if user type was throwed out as unused, it would be very strange to insist on keeping it's initialization code. Personally I would be kinda pissed if the compiler did this, I expect the static

Re: Pure delegate not quite pure?

2015-06-30 Thread Tofu Ninja via Digitalmars-d-learn
On Wednesday, 1 July 2015 at 00:13:36 UTC, Jesse Phillips wrote: On Tuesday, 30 June 2015 at 22:23:40 UTC, Tofu Ninja wrote: On Tuesday, 30 June 2015 at 22:05:43 UTC, Steven Schveighoffer wrote: Have you tried placing const on the function signature? i.e.: pure int delegate() const d = ()

Re: Pure delegate not quite pure?

2015-06-30 Thread Tofu Ninja via Digitalmars-d-learn
On Tuesday, 30 June 2015 at 22:23:40 UTC, Tofu Ninja wrote: On Tuesday, 30 June 2015 at 22:05:43 UTC, Steven Schveighoffer wrote: Have you tried placing const on the function signature? i.e.: pure int delegate() const d = () const {... That's how you'd do it (I think, didn't test) if the

Re: Pure delegate not quite pure?

2015-06-30 Thread Tofu Ninja via Digitalmars-d-learn
On Tuesday, 30 June 2015 at 22:05:43 UTC, Steven Schveighoffer wrote: Have you tried placing const on the function signature? i.e.: pure int delegate() const d = () const {... That's how you'd do it (I think, didn't test) if the delegate context pointer was a class/struct. -Steve Nah,

Re: Static constructors guaranteed to run?

2015-06-30 Thread Tofu Ninja via Digitalmars-d-learn
On Monday, 29 June 2015 at 02:07:57 UTC, ketmar wrote: On Sat, 27 Jun 2015 22:49:13 +, Tofu Ninja wrote: On Saturday, 27 June 2015 at 22:20:40 UTC, ketmar wrote: 2. no. Hmm... any reason why? if instantiated template was not used in any code that makes into compiled binary, compiler

Re: Static constructors guaranteed to run?

2015-06-30 Thread Tofu Ninja via Digitalmars-d-learn
On Monday, 29 June 2015 at 02:31:18 UTC, ketmar wrote: yes. it doesn't do that now, afair, but i can't see any sense in running code that obviously does nothing, as it's owner is not used. module ctors was designed for such things -- i.e. to run some code on startup. if someone is doing some

Re: Pure delegate not quite pure?

2015-06-30 Thread Tofu Ninja via Digitalmars-d-learn
On Sunday, 28 June 2015 at 10:19:05 UTC, anonymous wrote: [...] Is there any way to annotate the context as const?

Pure delegate not quite pure?

2015-06-28 Thread Tofu Ninja via Digitalmars-d-learn
module main; import std.stdio; void main(string[] args) { auto d = foo(); writeln(d()); // prints 25 } auto foo() { int x = 4; pure int delegate() d = delegate() { return x*x; }; writeln(d()); // prints 16 x = 5;

Re: Static constructors guaranteed to run?

2015-06-27 Thread Tofu Ninja via Digitalmars-d-learn
On Saturday, 27 June 2015 at 22:20:40 UTC, ketmar wrote: 2. no. Hmm... any reason why?

Static constructors guaranteed to run?

2015-06-26 Thread Tofu Ninja via Digitalmars-d-learn
Are static constructors guaranteed to run if the module is imported? Also are static constructors in templated types guaranteed to run for every instantiation? Even if the instantiation is never actually used outside of compile time code, like in an alias or in a UDA?

Template mixin can not introduce overloads

2015-06-24 Thread Tofu Ninja via Digitalmars-d-learn
Is this intended or is it a bug? void main(string[] args) { Test a; a.foo(5); // Fails to compile } struct Test { mixin testMix; void foo(string y){} } mixin template testMix() { void foo(int x){} }

Call-ie return on behalf of caller?

2015-06-03 Thread Tofu Ninja via Digitalmars-d-learn
Is there a way other than exceptions for a called function to force the caller to return? Specifically, I know the return type of the caller(its always bool) and under certain circumstances I would like the caller to just give up and return false if the called function fails. With as little

Re: Lazy variadic not working, any alternatives?

2015-05-26 Thread Tofu Ninja via Digitalmars-d-learn
On Tuesday, 26 May 2015 at 05:54:11 UTC, John Colvin wrote: Something like this appears to work: import std.typetuple : allSatisfy; enum implicityConvertibleToBool(T) = is(T : bool); bool tok_and(Args...)(lazy Args terms) if(allSatisfy!(implicitlyConvertibleToBool, Args)) { auto

Re: Lazy variadic not working, any alternatives?

2015-05-25 Thread Tofu Ninja via Digitalmars-d-learn
On Tuesday, 26 May 2015 at 05:22:26 UTC, Tofu Ninja wrote: Actually the code seems to compile on 2.067.1 but definitely does not work as expected. Another example of Lazy variadic to show how it works... void main(string[] args) { test(a(), b(), c()); } bool a() { writeln(a);

Re: Lazy variadic not working, any alternatives?

2015-05-25 Thread Tofu Ninja via Digitalmars-d-learn
On Tuesday, 26 May 2015 at 05:43:59 UTC, Tofu Ninja wrote: On Tuesday, 26 May 2015 at 05:22:26 UTC, Tofu Ninja wrote: Actually the code seems to compile on 2.067.1 but definitely does not work as expected. ... I guess it stems from the fact that its lazy (bool[]) Wish I could do (lazy

Lazy variadic not working, any alternatives?

2015-05-25 Thread Tofu Ninja via Digitalmars-d-learn
So I was writing a simple parser and I wanted a functionality that was basically try list of tokens in order and if any of them fail, rewind input. I tried using a lazy variadic function: bool tok_and(lazy bool[] terms ...) { auto backup = getInputLocation(); for(int i = 0; i

Re: Duplicate another function's parameters in a template function

2015-04-20 Thread Tofu Ninja via Digitalmars-d-learn
On Monday, 20 April 2015 at 23:20:07 UTC, Justin Whear wrote: See std.functional.forward: http://dlang.org/phobos/std_functional.html#.forward Sweet beans, thanks

Duplicate another function's parameters in a template function

2015-04-20 Thread Tofu Ninja via Digitalmars-d-learn
I am trying to write a template function that can take another function as an alias template argument and duplicate its parameters for it self. For example, something like this... void foo(ref int x){x = 7;} auto pass(alias f)(/* ??? */) { // other stuff... return f( /* ??? */ ); }

Re: Undefined symbol?

2015-02-21 Thread Tofu Ninja via Digitalmars-d-learn
On Saturday, 21 February 2015 at 17:08:56 UTC, Joakim wrote: On Wednesday, 18 February 2015 at 08:55:51 UTC, Tofu Ninja wrote: When I compile my project in release dmd suddenly starts complains about missing symbols that look like they are from phobos. Symbol Undefined

Undefined symbol?

2015-02-18 Thread Tofu Ninja via Digitalmars-d-learn
When I compile my project in release dmd suddenly starts complains about missing symbols that look like they are from phobos. Symbol Undefined _D3std9exception134__T12errnoEnforceTbVAyaa50_433a5c445c646d64325c77696e646f77735c62696e5c2e2e5cA7E6C89DF0A958C3336C905AF5DE Any idea what is

Re: Undefined symbol?

2015-02-18 Thread Tofu Ninja via Digitalmars-d-learn
On Wednesday, 18 February 2015 at 10:47:50 UTC, John Colvin wrote: On Wednesday, 18 February 2015 at 08:55:51 UTC, Tofu Ninja wrote: When I compile my project in release dmd suddenly starts complains about missing symbols that look like they are from phobos. Symbol Undefined

Struct destructor in a with block

2015-02-02 Thread Tofu Ninja via Digitalmars-d-learn
module main; import std.stdio; void main(string[] args) { with(test()) { foo(); } } struct test { void foo() { writeln(foo); } ~this() { writeln(destoy); } } prints:

Re: Struct destructor in a with block

2015-02-02 Thread Tofu Ninja via Digitalmars-d-learn
On Tuesday, 3 February 2015 at 05:09:55 UTC, Ali Çehreli wrote: Yes, it's a known bug that has been fixed on git head but I can't find the bug report. :-/ Ok cool, good to know. The new output: foo destoy Yes, without the 'r'. ;) Ali Yeah, i noticed the typo right after I posted...

Check if type is from specific template?

2015-01-29 Thread Tofu Ninja via Digitalmars-d-learn
Basically what the title says, how do I check if a type T is an instantiation of a specific template?

Re: Check if type is from specific template?

2015-01-29 Thread Tofu Ninja via Digitalmars-d-learn
On Thursday, 29 January 2015 at 12:10:41 UTC, bearophile wrote: Tofu Ninja: Basically what the title says, how do I check if a type T is an instantiation of a specific template? If you have an updated Phobos std.traits.isInstanceOf could be what you look for. Bye, bearophile Yep,

Get vars in current scope at compile time?

2014-12-19 Thread Tofu Ninja via Digitalmars-d-learn
Is there some way to get a list of the variables that are in the current scope via traits? Some things like allMembers? I would like to be able to call this from a mixin to grab the locals in the scope that the mixin is being dropped into.

Easy way to monitor gc activity?

2014-11-12 Thread Tofu Ninja via Digitalmars-d-learn
Basicly what the title said. What is an easy way to monitor gc activity? I am finding it hard to know when and where the gc is running and how much. Preferably I would like a way to do it in app so I can make adjustments based on gc load. Also I would prefer to not have to recompile the

Re: Easy way to monitor gc activity?

2014-11-12 Thread Tofu Ninja via Digitalmars-d-learn
On Wednesday, 12 November 2014 at 11:29:01 UTC, thedeemon wrote: On Wednesday, 12 November 2014 at 10:43:32 UTC, Tofu Ninja wrote: What is an easy way to monitor gc activity? Here's mine: https://bitbucket.org/infognition/dstuff/src/ A little module that allows you to track all GC

Function parameters from TypeTuple

2014-10-17 Thread Tofu Ninja via Digitalmars-d-learn
Basicly what I am trying to do is have a function template that will generate its parameters to be arrays of the types of a type tuple. So for instance the parameters of f!(int, char) would be (int[], char[])... No matter what I try, the compiler vomits all over me...

Re: Function parameters from TypeTuple

2014-10-17 Thread Tofu Ninja via Digitalmars-d-learn
On Friday, 17 October 2014 at 17:44:48 UTC, Tofu Ninja wrote: Not sure if what I wrote made sense, instead I will just post the code that is vomiting on me... template arrayType(T) { alias arrayType = T[]; } template multiAccess(Args ...) { auto multiAccess(int i,

Re: Function parameters from TypeTuple

2014-10-17 Thread Tofu Ninja via Digitalmars-d-learn
On Friday, 17 October 2014 at 17:55:14 UTC, Ali Çehreli wrote: Yeah.. I dont think I was clear the first time...

Re: Function parameters from TypeTuple

2014-10-17 Thread Tofu Ninja via Digitalmars-d-learn
On Friday, 17 October 2014 at 17:57:58 UTC, Tofu Ninja wrote: Also my inability to get this working is probably rooted in my lack of understanding of the differences between tuple vs Tuple vs TypeTuple vs expression tuples ...

Re: Function parameters from TypeTuple

2014-10-17 Thread Tofu Ninja via Digitalmars-d-learn
On Friday, 17 October 2014 at 18:22:12 UTC, ketmar via Digitalmars-d-learn wrote: On Fri, 17 Oct 2014 17:57:57 + Tofu Ninja via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: On Friday, 17 October 2014 at 17:44:48 UTC, Tofu Ninja wrote: Not sure if what I wrote made sense

Re: Function parameters from TypeTuple

2014-10-17 Thread Tofu Ninja via Digitalmars-d-learn
On Friday, 17 October 2014 at 19:03:42 UTC, anonymous wrote: On Friday, 17 October 2014 at 17:57:58 UTC, Tofu Ninja wrote: On Friday, 17 October 2014 at 17:44:48 UTC, Tofu Ninja wrote: Not sure if what I wrote made sense, instead I will just post the code that is vomiting on me... You

Re: Function parameters from TypeTuple

2014-10-17 Thread Tofu Ninja via Digitalmars-d-learn
On Friday, 17 October 2014 at 19:32:40 UTC, anonymous wrote: On Friday, 17 October 2014 at 19:18:29 UTC, Tofu Ninja wrote: I had the imports, I just didn't post them. My problem is most likely that I used Tuple! instead of tuple... which is probably because the differences between the like

<    1   2