Re: Forwarding varadic function arguments

2016-03-03 Thread Nicholas Wilson via Digitalmars-d-learn
On Friday, 4 March 2016 at 01:13:37 UTC, Ali Çehreli wrote: On 03/03/2016 04:50 PM, Nicholas Wilson wrote: > [...] I think so. Also noting that C-style varargs can only work with fundamental types (Am I correct there? I am carrying this assumption from C++.), you may be happier with a templat

Re: Forwarding varadic function arguments

2016-03-03 Thread Ali Çehreli via Digitalmars-d-learn
On 03/03/2016 04:50 PM, Nicholas Wilson wrote: > //f is a File* > void fwrite(int line = __LINE__)(...) > { > f.write("/*",line,"*/ "); > f.write(_argptr); //prints e.g 7FFF5B055440 > } > basically i want > fwrite("1 ","2\t","3\n"); > to print > /*7*/ 1 23 > > do I have to it

Forwarding varadic function arguments

2016-03-03 Thread Nicholas Wilson via Digitalmars-d-learn
//f is a File* void fwrite(int line = __LINE__)(...) { f.write("/*",line,"*/ "); f.write(_argptr); //prints e.g 7FFF5B055440 } basically i want fwrite("1 ","2\t","3\n"); to print /*7*/ 1 23 do I have to iterate through _argptr

Re: Is it safe to use 'is' to compare types?

2016-03-03 Thread Yuxuan Shui via Digitalmars-d-learn
On Thursday, 3 March 2016 at 23:58:39 UTC, Yuxuan Shui wrote: On Thursday, 3 March 2016 at 23:51:16 UTC, Adam D. Ruppe wrote: On Thursday, 3 March 2016 at 23:46:50 UTC, Yuxuan Shui wrote: Will typeid(a) is typeid(b) yield different results than typeid(a) == typeid(b)? No. Indeed, opEquals on

Re: Is it safe to use 'is' to compare types?

2016-03-03 Thread Yuxuan Shui via Digitalmars-d-learn
On Thursday, 3 March 2016 at 23:51:16 UTC, Adam D. Ruppe wrote: On Thursday, 3 March 2016 at 23:46:50 UTC, Yuxuan Shui wrote: Will typeid(a) is typeid(b) yield different results than typeid(a) == typeid(b)? No. Indeed, opEquals on TypeInfo just calls is itself. But opEquals also has extra co

Re: Is it safe to use 'is' to compare types?

2016-03-03 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 3 March 2016 at 23:46:50 UTC, Yuxuan Shui wrote: Will typeid(a) is typeid(b) yield different results than typeid(a) == typeid(b)? No. Indeed, opEquals on TypeInfo just calls is itself.

Is it safe to use 'is' to compare types?

2016-03-03 Thread Yuxuan Shui via Digitalmars-d-learn
Will typeid(a) is typeid(b) yield different results than typeid(a) == typeid(b)?

Re: Error with associative array initializer DMD32 D Compiler v2.070.0

2016-03-03 Thread Ali Çehreli via Digitalmars-d-learn
On 03/03/2016 05:17 AM, Andrew Edwards wrote: > On 3/3/16 7:01 PM, MGW wrote: >> immutable long[string] aa = [ >> "foo": 5, >> "bar": 10, >> "baz": 2000 >> ]; > > The only way this can be done outside the body of a function is if it is > a manifest constant. This works: > > enum long[s

Re: Empty Associative Aarray Literal

2016-03-03 Thread Ali Çehreli via Digitalmars-d-learn
On 03/03/2016 02:06 PM, Jack Stouffer wrote: This doesn't work either string func(int a, int[int] b = int[int].init) { Parentheses around int[int] works though. I don't know whether it's a bug. string func(int a, int[int] b = (int[int]).init) { Ali

Re: Empty Associative Aarray Literal

2016-03-03 Thread cym13 via Digitalmars-d-learn
On Thursday, 3 March 2016 at 22:06:54 UTC, Jack Stouffer wrote: I want to have one of the parameters on a function be optional. The problem is, is that it's a AA and D does not seem to support empty AA literals. Observe: string func(int a, int[int] b = []) { return "mem1"; } void main() {

Empty Associative Aarray Literal

2016-03-03 Thread Jack Stouffer via Digitalmars-d-learn
I want to have one of the parameters on a function be optional. The problem is, is that it's a AA and D does not seem to support empty AA literals. Observe: string func(int a, int[int] b = []) { return "mem1"; } void main() { func(1); } $ dmd test test.d(8): Error: cannot implicitly c

Re: Unable to instantiate template with same name as function

2016-03-03 Thread ag0aep6g via Digitalmars-d-learn
On 03.03.2016 07:12, Shriramana Sharma wrote: string ta(string s) { return s ~ "1"; } template ta(string s) { enum ta = ta(s); } In `ta(s)` here, `ta` is the enum itself again. It's similar to `int x = x;`. Can't do that, of course. Add a leading dot to refer to the module level `ta` symbols

Re: std.range: Lockstep vs. Zip

2016-03-03 Thread Alex Parrill via Digitalmars-d-learn
On Wednesday, 2 March 2016 at 08:51:07 UTC, Manuel Maier wrote: Hi there, I was wondering why I should ever prefer std.range.lockstep over std.range.zip. In my (very limited) tests std.range.zip offered the same functionality as std.range.lockstep, i.e. I was able to iterate using `foreach(ke

Re: Unable to instantiate template with same name as function

2016-03-03 Thread cym13 via Digitalmars-d-learn
On Thursday, 3 March 2016 at 08:58:25 UTC, Shriramana Sharma wrote: Hello people and thanks for your replies. Jonathan M Davis via Digitalmars-d-learn wrote: You can't overload a function and an eponymous template like that. They need to have distinct names. Why is it not possible for the ov

Re: Error with associative array initializer DMD32 D Compiler v2.070.0

2016-03-03 Thread Andrew Edwards via Digitalmars-d-learn
On 3/3/16 7:01 PM, MGW wrote: immutable long[string] aa = [ "foo": 5, "bar": 10, "baz": 2000 ]; The only way this can be done outside the body of a function is if it is a manifest constant. This works: enum long[string] aa = [ "foo": 5, "bar": 10, "baz": 2000 ];

Re: Template mixins and struct constructors

2016-03-03 Thread Adrian Matoga via Digitalmars-d-learn
On Wednesday, 2 March 2016 at 20:39:57 UTC, Adam D. Ruppe wrote: On Wednesday, 2 March 2016 at 12:27:04 UTC, Adrian Matoga wrote: Is it by design or is it a bug? And, if it is by design, what is the reason for that? That's by design. It allows you to override names from a template mixin like

Re: Unable to instantiate template with same name as function

2016-03-03 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, March 03, 2016 14:28:25 Shriramana Sharma via Digitalmars-d-learn wrote: > Hello people and thanks for your replies. > > Jonathan M Davis via Digitalmars-d-learn wrote: > > You can't overload a function and an eponymous template like that. They > > need to have distinct names. > > Why

Re: Error with associative array initializer DMD32 D Compiler v2.070.0

2016-03-03 Thread mahdi via Digitalmars-d-learn
On Thursday, 3 March 2016 at 10:35:50 UTC, MGW wrote: The citation from https://dlang.org/spec/hash-map.html Static Initialization of AAs immutable long[string] aa = [ "foo": 5, "bar": 10, "baz": 2000 ]; unittest { assert(aa["foo"] == 5); assert(aa["b

Re: Error with associative array initializer DMD32 D Compiler v2.070.0

2016-03-03 Thread asdf via Digitalmars-d-learn
On Thursday, 3 March 2016 at 10:35:50 UTC, MGW wrote: The citation from https://dlang.org/spec/hash-map.html Static Initialization of AAs immutable long[string] aa = [ "foo": 5, "bar": 10, "baz": 2000 ]; unittest { assert(aa["foo"] == 5); assert(aa["b

Re: Error with associative array initializer DMD32 D Compiler v2.070.0

2016-03-03 Thread MGW via Digitalmars-d-learn
The citation from https://dlang.org/spec/hash-map.html Static Initialization of AAs immutable long[string] aa = [ "foo": 5, "bar": 10, "baz": 2000 ]; unittest { assert(aa["foo"] == 5); assert(aa["bar"] == 10); assert(aa["baz"] == 2000); } Judging

Re: Error with associative array initializer DMD32 D Compiler v2.070.0

2016-03-03 Thread asdf via Digitalmars-d-learn
On Thursday, 3 March 2016 at 10:01:47 UTC, MGW wrote: immutable long[string] aa = [ "foo": 5, "bar": 10, "baz": 2000 ]; ... Error: non-constant expression ["foo":5L, "bar":10L, "baz":2000L] D associative arrays are a dynamic runtime feature, thus can't be initialized without runtime

Re: Error with associative array initializer DMD32 D Compiler v2.070.0

2016-03-03 Thread Anonymouse via Digitalmars-d-learn
On Thursday, 3 March 2016 at 10:01:47 UTC, MGW wrote: immutable long[string] aa = [ "foo": 5, "bar": 10, "baz": 2000 ]; ... Error: non-constant expression ["foo":5L, "bar":10L, "baz":2000L] I'm not sure there's a way around this except by initialising it at runtime. So you can't get

Error with associative array initializer DMD32 D Compiler v2.070.0

2016-03-03 Thread MGW via Digitalmars-d-learn
immutable long[string] aa = [ "foo": 5, "bar": 10, "baz": 2000 ]; ... Error: non-constant expression ["foo":5L, "bar":10L, "baz":2000L]

Re: Unable to instantiate template with same name as function

2016-03-03 Thread Daniel Kozak via Digitalmars-d-learn
Dne 3.3.2016 v 09:58 Shriramana Sharma via Digitalmars-d-learn napsal(a): Hello people and thanks for your replies. Jonathan M Davis via Digitalmars-d-learn wrote: You can't overload a function and an eponymous template like that. They need to have distinct names. Why is it not possible for

Re: Unable to instantiate template with same name as function

2016-03-03 Thread Shriramana Sharma via Digitalmars-d-learn
Hello people and thanks for your replies. Jonathan M Davis via Digitalmars-d-learn wrote: > You can't overload a function and an eponymous template like that. They > need to have distinct names. Why is it not possible for the overload to happen? After all, the compiler should be able to identi

Re: Installing DUB on OSX

2016-03-03 Thread Joel via Digitalmars-d-learn
On Thursday, 3 March 2016 at 07:07:55 UTC, Jacob Carlborg wrote: On 2016-03-02 23:41, Joel wrote: I don't seem to have a folder 'build' there. It all seems writable. Hmm, that's really weird. I guess that's the folder it fails to write. Is it running as a different user. What if you change