How to realize isSortedRange?

2014-08-20 Thread Alexandr Druzhinin via Digitalmars-d-learn
I need to ensure that range passed to function is SortedRange to use binary search. I did something like: static if(!__traits(compiles, { ElementType!(typeof(data)) element; auto d = data.trisect(element); } )) assert(0, DataRange shall be

Re: How to realize isSortedRange?

2014-08-20 Thread Kagamin via Digitalmars-d-learn
http://dlang.org/phobos/std_traits.html#TemplateOf

Re: How to realize isSortedRange?

2014-08-20 Thread hane via Digitalmars-d-learn
On Wednesday, 20 August 2014 at 07:18:12 UTC, Kagamin wrote: http://dlang.org/phobos/std_traits.html#TemplateOf Or isInstanceOf. static if (__traits(isSame, TemplateOf!R, SortedRange)) static if (isInstanceOf!(SortedRange, R))

Re: How to realize isSortedRange?

2014-08-20 Thread Alexandr Druzhinin via Digitalmars-d-learn
Thank you!

Re: Auto attributes for functions

2014-08-20 Thread Jonathan M Davis via Digitalmars-d-learn
On Wed, 20 Aug 2014 01:38:52 + uri via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: Hi all, Bit new to D so this might be a very naive question... Can the compiler auto infer function attributes? I am often adding as many attributes as possible and use the compiler to

Re: Auto attributes for functions

2014-08-20 Thread ed via Digitalmars-d-learn
On Wednesday, 20 August 2014 at 09:13:15 UTC, Jonathan M Davis via Digitalmars-d-learn wrote: On Wed, 20 Aug 2014 01:38:52 + uri via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: Hi all, Bit new to D so this might be a very naive question... Can the compiler auto infer

delegates GC allocations

2014-08-20 Thread Etienne via Digitalmars-d-learn
I've been hearing that delegates get a context pointer which will be allocated on the GC. Is this also true for delegates which stay in scope? e.g. void addThree() { int val; void addOne() { val++; } addOne(); addOne();

Re: delegates GC allocations

2014-08-20 Thread ketmar via Digitalmars-d-learn
On Wed, 20 Aug 2014 10:44:38 -0400 Etienne via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: Will the above function allocate on the GC? no. signature.asc Description: PGP signature

Variadic parameter of length 1

2014-08-20 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
I have several times seen a construct template foo(T...) if(T.length == 1) { ... } What is that good for? Why using variadic parameter if anyway exactly one parameter is required?!?

Re: delegates GC allocations

2014-08-20 Thread Ola Fosheim Gr via Digitalmars-d-learn
non-static nested functions are effectively delegates as it needs a context pointer to parent stack frame. Only if it is recursive.

Re: delegates GC allocations

2014-08-20 Thread hane via Digitalmars-d-learn
On Wednesday, 20 August 2014 at 14:44:39 UTC, Etienne wrote: I've been hearing that delegates get a context pointer which will be allocated on the GC. Is this also true for delegates which stay in scope? e.g. void addThree() { int val; void addOne() { val++;

Re: Variadic parameter of length 1

2014-08-20 Thread monarch_dodra via Digitalmars-d-learn
On Wednesday, 20 August 2014 at 15:11:53 UTC, Dominikus Dittes Scherkl wrote: I have several times seen a construct template foo(T...) if(T.length == 1) { ... } What is that good for? Why using variadic parameter if anyway exactly one parameter is required?!? AFAIK, it's a historical

Re: Variadic parameter of length 1

2014-08-20 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
On Wednesday, 20 August 2014 at 15:26:14 UTC, monarch_dodra wrote: AFAIK, it's a historical workaround to accept T as either alias or not alias, as varargs have auto alias. EG: foo!int //OK foo!hello //OK too Ah, ok. And why historical? Is that not necessary anymore? What better solution is

Re: Variadic parameter of length 1

2014-08-20 Thread anonymous via Digitalmars-d-learn
On Wednesday, 20 August 2014 at 15:11:53 UTC, Dominikus Dittes Scherkl wrote: I have several times seen a construct template foo(T...) if(T.length == 1) { ... } What is that good for? Why using variadic parameter if anyway exactly one parameter is required?!? That's because template

Re: Variadic parameter of length 1

2014-08-20 Thread Philippe Sigaud via Digitalmars-d-learn
On Wed, Aug 20, 2014 at 5:34 PM, Dominikus Dittes Scherkl via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: On Wednesday, 20 August 2014 at 15:26:14 UTC, monarch_dodra wrote: AFAIK, it's a historical workaround to accept T as either alias or not alias, as varargs have auto

Re: Variadic parameter of length 1

2014-08-20 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
On Wednesday, 20 August 2014 at 15:37:18 UTC, Philippe Sigaud via Digitalmars-d-learn wrote: No better solution that I know of. alias template parameters (alias a) match symbols (names, user-defined types) whereas type parameter (T) match only pure types. So when we need to match anything,

How to set workDir for std.process.execute ?

2014-08-20 Thread KrzaQ via Digitalmars-d-learn
Hello, I'm trying to follow the documentation: http://dlang.org/phobos/std_process.html#.execute Unfortunately, the following code gives me a compiler error: class Probator { char[] dir; this(const char[] dir){ this.dir = dir.dup; } int

Re: How to set workDir for std.process.execute ?

2014-08-20 Thread ketmar via Digitalmars-d-learn
On Wed, 20 Aug 2014 16:07:47 + KrzaQ via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: It's as if the implementation didn't expect the last argument. try to upgrade to dmd 2.066. signature.asc Description: PGP signature

Re: How to set workDir for std.process.execute ?

2014-08-20 Thread krzaq via Digitalmars-d-learn
On Wednesday, 20 August 2014 at 16:16:03 UTC, ketmar via Digitalmars-d-learn wrote: On Wed, 20 Aug 2014 16:07:47 + KrzaQ via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: It's as if the implementation didn't expect the last argument. try to upgrade to dmd 2.066. That

Re: Variadic parameter of length 1

2014-08-20 Thread Dicebot via Digitalmars-d-learn
On Wednesday, 20 August 2014 at 15:34:30 UTC, Dominikus Dittes Scherkl wrote: And why historical? Is that not necessary anymore? What better solution is there today? Historical in a sense that distinct can be anything template parameter is probably a better approach but it is too late to

Re: Variadic parameter of length 1

2014-08-20 Thread monarch_dodra via Digitalmars-d-learn
On Wednesday, 20 August 2014 at 17:02:59 UTC, Dicebot wrote: On Wednesday, 20 August 2014 at 15:34:30 UTC, Dominikus Dittes Scherkl wrote: And why historical? Is that not necessary anymore? What better solution is there today? Historical in a sense that distinct can be anything template

Can you explain this?

2014-08-20 Thread Colin via Digitalmars-d-learn
Hi, I'm implementing some template checks on some types I'm using in a project, and went to phobos for some indications on how to use them. In std.range, I see this construct quite a bit: template isInputRange(R) { enum bool isInputRange = is(typeof( (inout int = 0) { R

Re: Can you explain this?

2014-08-20 Thread Justin Whear via Digitalmars-d-learn
On Wed, 20 Aug 2014 20:01:03 +, Colin wrote: It looks veryhacky. I see 3 distinct parts playing a role in my confusion: A) The 'is' keyword. What does it do when you have is(expression); B) typeof( expression ); whats this doing? Particularly when the expression its acting on is a

Re: Can you explain this?

2014-08-20 Thread Dicebot via Digitalmars-d-learn
On Wednesday, 20 August 2014 at 20:01:05 UTC, Colin wrote: I see 3 distinct parts playing a role in my confusion: A) The 'is' keyword. What does it do when you have is(expression); http://dlang.org/expression.html#IsExpression It is a tool for type checking. It has many options but plain

No Output with shebang.

2014-08-20 Thread Newbie via Digitalmars-d-learn
#!/usr/bin/gdc import std.stdio; void main() { writeln(Hello, world with automated script running!); } When I compile the code above normal to an a.out binary it runs like expected. But running it with shebang it does nothing. No output, especially no error message. Nothing. What do I

Re: No Output with shebang.

2014-08-20 Thread Newbie via Digitalmars-d-learn
On Wednesday, 20 August 2014 at 20:21:13 UTC, anonymous wrote: On Wednesday, 20 August 2014 at 20:17:49 UTC, Newbie wrote: #!/usr/bin/gdc import std.stdio; void main() { writeln(Hello, world with automated script running!); } When I compile the code above normal to an a.out binary it runs

Re: No Output with shebang.

2014-08-20 Thread anonymous via Digitalmars-d-learn
On Wednesday, 20 August 2014 at 20:17:49 UTC, Newbie wrote: #!/usr/bin/gdc import std.stdio; void main() { writeln(Hello, world with automated script running!); } When I compile the code above normal to an a.out binary it runs like expected. But running it with shebang it does nothing. No

Re: Can you explain this?

2014-08-20 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, 20 August 2014 at 20:12:58 UTC, Justin Whear wrote: On Wed, 20 Aug 2014 20:01:03 +, Colin wrote: It looks veryhacky. I see 3 distinct parts playing a role in my confusion: A) The 'is' keyword. What does it do when you have is(expression); B) typeof( expression ); whats

new error message in 2.066, type bool (const)

2014-08-20 Thread Paul D Anderson via Digitalmars-d-learn
Re-compiling existing code with version 2.066 generates a lot of errors complaining about implicit conversion to const. Typical is this call (inside a struct with properties 1 2): z.sign = x.sign ^ y.sign; Error: None of the overloads of 'sign' are callable using argument types bool

Re: delegates GC allocations

2014-08-20 Thread Chris Nicholson-Sauls via Digitalmars-d-learn
On Wednesday, 20 August 2014 at 15:17:52 UTC, Ola Fosheim Gr wrote: non-static nested functions are effectively delegates as it needs a context pointer to parent stack frame. Only if it is recursive. Or if it refers to any state of the parent function.

Re: No Output with shebang.

2014-08-20 Thread Philippe Sigaud via Digitalmars-d-learn
gdc just compiles the program to a.out. It doesn't run the resulting executable. You need to use something like rdmd instead of gdc. rdmd compiles to some temporary location and then runs the executable. Wow, that was fast. Thanks a lot! Can compiler switches be used with the shebang

Re: Can you explain this?

2014-08-20 Thread monarch_dodra via Digitalmars-d-learn
On Wednesday, 20 August 2014 at 20:39:42 UTC, Jonathan M Davis wrote: is(typeof(foo)) and __traits(compiles, foo) are not the same. The first tests for the existence of the symbol, whereas the second checks whether the code will actually compile. Is that even true? I mean, are you just

Re: delegates GC allocations

2014-08-20 Thread Ola Fosheim Gr via Digitalmars-d-learn
On Wednesday, 20 August 2014 at 20:48:38 UTC, Chris Nicholson-Sauls wrote: On Wednesday, 20 August 2014 at 15:17:52 UTC, Ola Fosheim Gr wrote: non-static nested functions are effectively delegates as it needs a context pointer to parent stack frame. Only if it is recursive. Or if it refers

Re: new error message in 2.066, type bool (const)

2014-08-20 Thread monarch_dodra via Digitalmars-d-learn
On Wednesday, 20 August 2014 at 20:46:20 UTC, Paul D Anderson wrote: Re-compiling existing code with version 2.066 generates a lot of errors complaining about implicit conversion to const. Typical is this call (inside a struct with properties 1 2): z.sign = x.sign ^ y.sign; Error:

Re: delegates GC allocations

2014-08-20 Thread Ola Fosheim Gr via Digitalmars-d-learn
On Wednesday, 20 August 2014 at 21:19:18 UTC, Ola Fosheim Gr wrote: On Wednesday, 20 August 2014 at 20:48:38 UTC, Chris Nicholson-Sauls wrote: On Wednesday, 20 August 2014 at 15:17:52 UTC, Ola Fosheim Gr wrote: Only if it is recursive. Or if it refers to any state of the parent function.

Re: delegates GC allocations

2014-08-20 Thread Etienne via Digitalmars-d-learn
On 2014-08-20 5:25 PM, Ola Fosheim Gr wrote: Well, I guess simple recursion could be solved easily too by having a wrapper function that puts the frame pointer in a free callee save register... So, my question inspired a new optimization? :-p

Re: Can you explain this?

2014-08-20 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, 20 August 2014 at 21:06:49 UTC, monarch_dodra wrote: On Wednesday, 20 August 2014 at 20:39:42 UTC, Jonathan M Davis wrote: is(typeof(foo)) and __traits(compiles, foo) are not the same. The first tests for the existence of the symbol, whereas the second checks whether the code

Re: delegates GC allocations

2014-08-20 Thread Ola Fosheim Gr via Digitalmars-d-learn
On Wednesday, 20 August 2014 at 21:30:41 UTC, Etienne wrote: So, my question inspired a new optimization? :-p A decent optimizing compiler would detect that the function is calling itself and save stack space by using register where possible...

Produce some COFF object with 2.066 ?

2014-08-20 Thread Baz via Digitalmars-d-learn
Hello, I've been very interested about the announce saying that DMD is able to produce COFF object files. Mostly because I'm thinking using some objects programmed in D in a software programmed in another lang, a bit like when statically linking a dll to a program but with an obj, to keep a

Re: Produce some COFF object with 2.066 ?

2014-08-20 Thread Brad Anderson via Digitalmars-d-learn
On Wednesday, 20 August 2014 at 23:56:23 UTC, Baz wrote: Hello, I've been very interested about the announce saying that DMD is able to produce COFF object files. Mostly because I'm thinking using some objects programmed in D in a software programmed in another lang, a bit like when statically

Re: Variadic parameter of length 1

2014-08-20 Thread ketmar via Digitalmars-d-learn
On Wed, 20 Aug 2014 17:47:36 + monarch_dodra via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: Yeah, what he said. It's a language artifact. by the way, it would be nice to have wiki page with such artifacts and their explanations. signature.asc Description: PGP signature

Re: No Output with shebang.

2014-08-20 Thread ketmar via Digitalmars-d-learn
On Wed, 20 Aug 2014 23:03:48 +0200 Philippe Sigaud via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: Can compiler switches be used with the shebang notation? If yes, there is certainly a GDC flag (-run?) that tells it to run the generated executable. it's possible to use

Re: new error message in 2.066, type bool (const)

2014-08-20 Thread Paul D Anderson via Digitalmars-d-learn
What changed? It ran okay with early beta versions, but not with the release. Paul It compiles in beta-5 but not beta-6. Is the list of changes in the beta testing wiki complete? None seem pertinent. monarch_dodra: Thanks for checking. I was trying to avoid tearing everything down. I

D with no druntime

2014-08-20 Thread uri via Digitalmars-d-learn
Hi All, I am playing with a small hack OS for fun and in 2066 there are these undefined refs (I have no druntime): _d_arraybounds (new to 2066) _d_assert (new to 2066) _d_unittest (new to 2066) _Dmodule_ref (also in 2065) _d_dso_registry (also in 2065) It is trivial to stub these out but it

onDispatch demo not compiling

2014-08-20 Thread Shachar via Digitalmars-d-learn
I'm trying to compile the onDispatch demo program from The D Programming Language (page 387). At first I had an import problem, but I fixed that. Now, however, when I try to call a.do_something_cool, I get an error message saying: onDispatch.d(43): Error: no property 'do_something_cool' for