Re: to auto or not to auto ( in foreach )

2016-07-16 Thread cym13 via Digitalmars-d-learn
On Saturday, 16 July 2016 at 21:39:42 UTC, cym13 wrote: A variable definition in a foreach -> A variable definition *with auto* in a foreach

Re: to auto or not to auto ( in foreach )

2016-07-16 Thread cym13 via Digitalmars-d-learn
On Saturday, 16 July 2016 at 20:00:39 UTC, Seb wrote: On Saturday, 16 July 2016 at 14:11:34 UTC, cym13 wrote: On Saturday, 16 July 2016 at 14:00:56 UTC, dom wrote: foreach(auto v; msg) writeln(v); gives an error that a basic type is expected foreach(v; msg) writeln(v); works .. but why

Re: to auto or not to auto ( in foreach )

2016-07-16 Thread Seb via Digitalmars-d-learn
On Saturday, 16 July 2016 at 20:00:39 UTC, Seb wrote: On Saturday, 16 July 2016 at 14:11:34 UTC, cym13 wrote: [...] It's not arbitrary. It keeps the language simple and easy to read. After all the entire auto keyword is just there, because the compiler needs a keyword and in loops it's

Re: to auto or not to auto ( in foreach )

2016-07-16 Thread Seb via Digitalmars-d-learn
On Saturday, 16 July 2016 at 14:11:34 UTC, cym13 wrote: On Saturday, 16 July 2016 at 14:00:56 UTC, dom wrote: foreach(auto v; msg) writeln(v); gives an error that a basic type is expected foreach(v; msg) writeln(v); works .. but why? Arbitrary limitation. If you want to say how

Re: to auto or not to auto ( in foreach )

2016-07-16 Thread ketmar via Digitalmars-d-learn
On Saturday, 16 July 2016 at 14:00:56 UTC, dom wrote: .. but why? because. i've lost that fight too.

Re: to auto or not to auto ( in foreach )

2016-07-16 Thread cym13 via Digitalmars-d-learn
On Saturday, 16 July 2016 at 14:00:56 UTC, dom wrote: foreach(auto v; msg) writeln(v); gives an error that a basic type is expected foreach(v; msg) writeln(v); works .. but why? Arbitrary limitation. If you want to say how surprising and uselessly limiting it is wait at the end

Re: to auto or not to auto ( in foreach )

2016-07-16 Thread Dennis Ritchie via Digitalmars-d-learn
On Saturday, 16 July 2016 at 14:00:56 UTC, dom wrote: foreach(auto v; msg) writeln(v); gives an error that a basic type is expected foreach(v; msg) writeln(v); works .. but why? `Note: The ForeachTypeAttribute is implicit, and when a type is not specified, it is inferred

to auto or not to auto ( in foreach )

2016-07-16 Thread dom via Digitalmars-d-learn
foreach(auto v; msg) writeln(v); gives an error that a basic type is expected foreach(v; msg) writeln(v); works .. but why?

Re: Way to use var instead of auto?

2016-07-03 Thread Jack Stouffer via Digitalmars-d-learn
On Sunday, 3 July 2016 at 22:00:39 UTC, MMJones wrote: I like the term var better than auto. Is there a way to alias auto? If you're thinking of var as in JS's var, they're not the same thing. Even if you could alias it I would advise against doing something like that; assume your code

Re: Way to use var instead of auto?

2016-07-03 Thread ag0aep6g via Digitalmars-d-learn
On 07/04/2016 12:00 AM, MMJones wrote: I like the term var better than auto. Is there a way to alias auto? no

Way to use var instead of auto?

2016-07-03 Thread MMJones via Digitalmars-d-learn
I like the term var better than auto. Is there a way to alias auto?

Re: template auto instantiation when parameters empty

2016-05-08 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, May 05, 2016 19:09:01 Steven Schveighoffer via Digitalmars-d- learn wrote: > On 5/5/16 6:50 PM, Erik Smith wrote: > > Alias works at the cost of adding a 2nd type name: > > > > alias Res = Resource!(); > > auto res = Res.create > > > > The oth

Re: template auto instantiation when parameters empty

2016-05-05 Thread Steven Schveighoffer via Digitalmars-d-learn
On 5/5/16 6:50 PM, Erik Smith wrote: Alias works at the cost of adding a 2nd type name: alias Res = Resource!(); auto res = Res.create The other problem is that the alias definition by itself instantiates, which I can't afford. I have createResource() now, it just doesn't fit well

Re: template auto instantiation when parameters empty

2016-05-05 Thread Erik Smith via Digitalmars-d-learn
On Thursday, 5 May 2016 at 16:12:40 UTC, Steven Schveighoffer wrote: On 5/5/16 12:10 AM, Erik Smith wrote: I want to have a struct template auto instantiate when the template parameters are defaulted or missing. Example: struct Resource(T=int) { static auto create() {return Resource

Re: template auto instantiation when parameters empty

2016-05-05 Thread Steven Schveighoffer via Digitalmars-d-learn
On 5/5/16 12:10 AM, Erik Smith wrote: I want to have a struct template auto instantiate when the template parameters are defaulted or missing. Example: struct Resource(T=int) { static auto create() {return Resource(null);} this(string s) {} } auto resource = Resource.create

Re: template auto instantiation when parameters empty

2016-05-05 Thread Andrea Fontana via Digitalmars-d-learn
On Wednesday, 4 May 2016 at 22:10:16 UTC, Erik Smith wrote: Any ideas? Using an alias could be a solution.

template auto instantiation when parameters empty

2016-05-04 Thread Erik Smith via Digitalmars-d-learn
I want to have a struct template auto instantiate when the template parameters are defaulted or missing. Example: struct Resource(T=int) { static auto create() {return Resource(null);} this(string s) {} } auto resource = Resource.create; As a plain struct it works

Re: Auto field member?

2016-03-02 Thread Rikki Cattermole via Digitalmars-d-learn
On 02/03/16 3:50 PM, Hanh wrote: Hi, Is there a way to declare a class field 'auto'? I have a problem when I try to 'promote' a variable to a field. import std.csv; import std.typecons; class Test { this() { auto text = "Joe,Carpenter,30\nFred,Blacksmith,4

Auto field member?

2016-03-02 Thread Hanh via Digitalmars-d-learn
Hi, Is there a way to declare a class field 'auto'? I have a problem when I try to 'promote' a variable to a field. import std.csv; import std.typecons; class Test { this() { auto text = "Joe,Carpenter,30\nFred,Blacksmith,40\r\n"; a

Re: UFCS vs auto-completion support

2016-01-09 Thread cym13 via Digitalmars-d-learn
On Saturday, 9 January 2016 at 15:50:33 UTC, Jay Norwood wrote: I'm reading Jack Stouffer's documentation: http://jackstouffer.com/blog/nd_slice.html considering the UFCS example below and how it would impact auto-completion support. auto slice = sliced(iota(1000), 5, 5, 40); auto slice

Re: UFCS vs auto-completion support

2016-01-09 Thread Jay Norwood via Digitalmars-d-learn
if auto-completion provided correct possible parameter type lists for the last three, but obviously the first two would provide no help, and I'd be pleasantly surprised if the third form provided the parameter type list without the first parameter. anyway ... I'll just try some simple cases

UFCS vs auto-completion support

2016-01-09 Thread Jay Norwood via Digitalmars-d-learn
I'm reading Jack Stouffer's documentation: http://jackstouffer.com/blog/nd_slice.html considering the UFCS example below and how it would impact auto-completion support. auto slice = sliced(iota(1000), 5, 5, 40); auto slice = 1000.iota.sliced(5, 5, 40); Seems like auto-complete support

Re: specifying an auto array type

2015-12-27 Thread Jay Norwood via Digitalmars-d-learn
On Sunday, 27 December 2015 at 07:40:55 UTC, Ali Çehreli wrote: It looks like you need map(), not each(): import std.algorithm; import std.typecons; import std.array; void main() { auto a = [ 1, 2 ]; auto arr = a.map!(e => tuple(2 * e, e * e)).array; static assert(is(typeof(

Re: specifying an auto array type

2015-12-27 Thread Ali Çehreli via Digitalmars-d-learn
On 12/27/2015 08:42 AM, Jay Norwood wrote: > However, I was trying to use each!, with the intention of then moving to > parallel processing by samples blocks. My guess is this would be more > efficient than using parallel map or amap, which would parallel process > by function application, if I

Re: specifying an auto array type

2015-12-26 Thread Ali Çehreli via Digitalmars-d-learn
On 12/26/2015 09:45 PM, Jay Norwood wrote: > This is getting kind of a long example, There are issues with that code that make it hard for me to guess the intent. > a way to have the Tuple array defined as auto instead of having to specify > the types. I tried using .array() a

specifying an auto array type

2015-12-26 Thread Jay Norwood via Digitalmars-d-learn
This is getting kind of a long example, but I'm really only interested in the last 4 or 5 lines. This works as desired, creating the array of tuples, but I'm wondering if there is a way to have the Tuple array defined as auto instead of having to specify the types. I tried using .array

use of typeof to determine auto type with ndslice examples

2015-12-20 Thread Jay Norwood via Digitalmars-d-learn
e some other way to get a valid fully specified type for these sliced auto variables? import std.stdio; import std.experimental.ndslice; void main() { import std.algorithm.iteration: map; import std.array: array; import std.range; import std.traits; auto t0 = 1000.iota.slice

Re: use of typeof to determine auto type with ndslice examples

2015-12-20 Thread Jay Norwood via Digitalmars-d-learn
So, the extra confusion of the typeof(iota) Result return goes away when slicing arrays. auto a1 = new int[100]; auto t3 = a1.sliced(3,4,5); pragma(msg,typeof(t3)); //This prints Slice!(3u, int*) Slice!(3u, int*) t4 = a1.sliced(3,4,5); // and this works ok

Re: use of typeof to determine auto type with ndslice examples

2015-12-20 Thread lobo via Digitalmars-d-learn
on win32, "dip80-ndslice": "~>0.8.4" Is there some other way to get a valid fully specified type for these sliced auto variables? import std.stdio; import std.experimental.ndslice; void main() { import std.algorithm.iteration: map; import std.array: array; impor

Re: use of typeof to determine auto type with ndslice examples

2015-12-20 Thread drug via Digitalmars-d-learn
21.12.2015 07:23, Jay Norwood пишет: import std.stdio; import std.experimental.ndslice; void main() { import std.algorithm.iteration: map; import std.array: array; import std.range; import std.traits; auto t0 = 1000.iota.sliced(3, 4, 5); pragma(msg, typeof(t0

Re: use of typeof to determine auto type with ndslice examples

2015-12-20 Thread Jay Norwood via Digitalmars-d-learn
import std.stdio; import std.experimental.ndslice; void main() { import std.algorithm.iteration: map; import std.array: array; import std.range; import std.traits; auto t0 = 1000.iota.sliced(3, 4, 5); pragma(msg, typeof(t0)); Slice!(3u, Result) t1 = 1000

Re: use of typeof to determine auto type with ndslice examples

2015-12-20 Thread Jay Norwood via Digitalmars-d-learn
, well this worked, so it seems to be something lacking in the description of iota's type rather than an issue with ndslice. alias RESULT = typeof(1000.iota); Slice!(3u, RESULT) t1 = 1000.iota.sliced(3, 4, 5); auto t2 = 1000.iota(); pragma(msg, typeof(t2)); This just prints Result

Re: Compile time strings auto concatenation!?

2015-11-21 Thread Marc Schütz via Digitalmars-d-learn
On Friday, 20 November 2015 at 20:39:58 UTC, Ilya wrote: Can DMD frontend optimize string concatenation ``` enum Double(S) = S ~ S; assert(condition, "Text " ~ Double!"+" ~ ___FUNCTION__); ``` to ``` assert(condition, "Text ++_function_name_"); ``` ? At least for string (and array?)

Re: Compile time strings auto concatenation!?

2015-11-21 Thread Tofu Ninja via Digitalmars-d-learn
On Friday, 20 November 2015 at 20:39:58 UTC, Ilya wrote: Can DMD frontend optimize string concatenation ``` enum Double(S) = S ~ S; assert(condition, "Text " ~ Double!"+" ~ ___FUNCTION__); ``` to ``` assert(condition, "Text ++_function_name_"); ``` ? If you really want to make sure it is

Compile time strings auto concatenation!?

2015-11-20 Thread Ilya via Digitalmars-d-learn
Can DMD frontend optimize string concatenation ``` enum Double(S) = S ~ S; assert(condition, "Text " ~ Double!"+" ~ ___FUNCTION__); ``` to ``` assert(condition, "Text ++_function_name_"); ``` ?

Re: Compile time strings auto concatenation!?

2015-11-20 Thread Justin Whear via Digitalmars-d-learn
On Fri, 20 Nov 2015 20:39:57 +, Ilya wrote: > Can DMD frontend optimize > string concatenation > ``` > enum Double(S) = S ~ S; > > assert(condition, "Text " ~ Double!"+" ~ ___FUNCTION__); > ``` > > to > > ``` > assert(condition, "Text ++_function_name_"); > > ``` > ? Yes this occurs as

Re: Erroneous auto can only be used for template function parameters?

2015-06-22 Thread Yuxuan Shui via Digitalmars-d-learn
On Monday, 22 June 2015 at 13:49:21 UTC, Steven Schveighoffer wrote: On 6/20/15 10:26 PM, Yuxuan Shui wrote: On Sunday, 21 June 2015 at 01:26:51 UTC, Adam D. Ruppe wrote: On Saturday, 20 June 2015 at 01:50:11 UTC, Yuxuan Shui wrote: auto ref R) is indeed a template function, so I don't

Re: Erroneous auto can only be used for template function parameters?

2015-06-22 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/22/15 1:37 PM, Yuxuan Shui wrote: On Monday, 22 June 2015 at 13:49:21 UTC, Steven Schveighoffer wrote: On 6/20/15 10:26 PM, Yuxuan Shui wrote: On Sunday, 21 June 2015 at 01:26:51 UTC, Adam D. Ruppe wrote: On Saturday, 20 June 2015 at 01:50:11 UTC, Yuxuan Shui wrote: auto ref R

Re: Erroneous auto can only be used for template function parameters?

2015-06-22 Thread Yuxuan Shui via Digitalmars-d-learn
On Saturday, 20 June 2015 at 01:50:11 UTC, Yuxuan Shui wrote: Try to compile this code snippet: import std.traits; template a(R) { auto a(S)(auto ref R i) { return cast(S)i*2; } } template ReturnTypeEx(alias A, B) { alias ReturnTypeEx = ReturnType!(A!B

Re: Erroneous auto can only be used for template function parameters?

2015-06-22 Thread Jesse Phillips via Digitalmars-d-learn
On Sunday, 21 June 2015 at 02:37:59 UTC, Yuxuan Shui wrote: On Sunday, 21 June 2015 at 01:26:51 UTC, Adam D. Ruppe wrote: On Saturday, 20 June 2015 at 01:50:11 UTC, Yuxuan Shui wrote: auto ref R) is indeed a template function, so I don't understand. But R is not a parameter on the function

Re: Erroneous auto can only be used for template function parameters?

2015-06-22 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/20/15 10:26 PM, Yuxuan Shui wrote: On Sunday, 21 June 2015 at 01:26:51 UTC, Adam D. Ruppe wrote: On Saturday, 20 June 2015 at 01:50:11 UTC, Yuxuan Shui wrote: auto ref R) is indeed a template function, so I don't understand. But R is not a parameter on the function itself. It comes from

Re: Erroneous auto can only be used for template function parameters?

2015-06-20 Thread Adam D. Ruppe via Digitalmars-d-learn
On Saturday, 20 June 2015 at 01:50:11 UTC, Yuxuan Shui wrote: auto ref R) is indeed a template function, so I don't understand. But R is not a parameter on the function itself. It comes from the outside template. Move it to the inside template, rewrite it as: auto a(S, R)(auto ref

Re: Erroneous auto can only be used for template function parameters?

2015-06-20 Thread Yuxuan Shui via Digitalmars-d-learn
On Sunday, 21 June 2015 at 01:26:51 UTC, Adam D. Ruppe wrote: On Saturday, 20 June 2015 at 01:50:11 UTC, Yuxuan Shui wrote: auto ref R) is indeed a template function, so I don't understand. But R is not a parameter on the function itself. It comes from the outside template. Move

Re: Erroneous auto can only be used for template function parameters?

2015-06-20 Thread Yuxuan Shui via Digitalmars-d-learn
On Sunday, 21 June 2015 at 01:26:51 UTC, Adam D. Ruppe wrote: On Saturday, 20 June 2015 at 01:50:11 UTC, Yuxuan Shui wrote: auto ref R) is indeed a template function, so I don't understand. But R is not a parameter on the function itself. It comes from the outside template. Move

Erroneous auto can only be used for template function parameters?

2015-06-19 Thread Yuxuan Shui via Digitalmars-d-learn
Try to compile this code snippet: import std.traits; template a(R) { auto a(S)(auto ref R i) { return cast(S)i*2; } } template ReturnTypeEx(alias A, B) { alias ReturnTypeEx = ReturnType!(A!B); } template b(alias R) { int b(S)(S i

Re: Erroneous auto can only be used for template function parameters?

2015-06-19 Thread Yuxuan Shui via Digitalmars-d-learn
On Saturday, 20 June 2015 at 01:50:11 UTC, Yuxuan Shui wrote: Try to compile this code snippet: import std.traits; template a(R) { auto a(S)(auto ref R i) { return cast(S)i*2; } } template ReturnTypeEx(alias A, B) { alias ReturnTypeEx = ReturnType!(A!B

Re: Auto ref function : How is this possible ?

2015-04-15 Thread Ali Çehreli via Digitalmars-d-learn
On 04/15/2015 10:50 AM, Ali Çehreli wrote: pragma(msg) has been added to Programming in D but it is not available online yet: Sorry for the spam :( but apparently it is already online: http://ddili.org/ders/d.en/templates.html#ix_templates.pragma Ali

Re: Auto ref function : How is this possible ?

2015-04-15 Thread Ali Çehreli via Digitalmars-d-learn
On 04/13/2015 07:44 AM, matovitch wrote: Thanks for the tip ! I was looking at something like this. pragma(msg) has been added to Programming in D but it is not available online yet:

Re: Auto ref function : How is this possible ?

2015-04-13 Thread matovitch via Digitalmars-d-learn
Thanks for the tip ! I was looking at something like this.

Re: Auto ref function : How is this possible ?

2015-04-13 Thread Steven Schveighoffer via Digitalmars-d-learn
On 4/11/15 6:08 AM, matovitch wrote: Hi, I just learn about auto ref functions and tried this : import std.stdio; auto ref foo(int i, ref float f) { if (i f) { return i; } else { return f; } } void main

Auto ref function : How is this possible ?

2015-04-11 Thread matovitch via Digitalmars-d-learn
Hi, I just learn about auto ref functions and tried this : import std.stdio; auto ref foo(int i, ref float f) { if (i f) { return i; } else { return f; } } void main() { int i = 1; float f1

Re: Auto ref function : How is this possible ?

2015-04-11 Thread matovitch via Digitalmars-d-learn
In fact I am now thinking it's great...I tried with string instead of float and got a clear error message. I should have read the spec more thoroughly.

Re: Auto ref function : How is this possible ?

2015-04-11 Thread matovitch via Digitalmars-d-learn
(you can remove the ref stuff)

Re: Auto ref function : How is this possible ?

2015-04-11 Thread matovitch via Digitalmars-d-learn
Ok this explain it : http://dlang.org/function.html#auto-functions. It should return a float.

Re: Should this work: export extern(C) auto ...

2015-03-20 Thread Robert M. Münch via Digitalmars-d-learn
On 2015-03-19 13:22:44 +, Benjamin Thaut said: Generally don't expect to many things to work with DLLs at the moment. Hi, well, I think what's available is good enough to get most things done. Generally speaking only exporting global functions works. Don't try to export classes /

Re: Should this work: export extern(C) auto ...

2015-03-19 Thread Benjamin Thaut via Digitalmars-d-learn
On Thursday, 19 March 2015 at 12:58:42 UTC, Robert M. Münch wrote: On 2015-03-18 21:50:39 +, Adam D. Ruppe said: It will not work because a function with an auto return value is actually a template, and unused templates won't be put into a dll. Ok, that makes it clear. Thanks

Re: Should this work: export extern(C) auto ...

2015-03-19 Thread Robert M. Münch via Digitalmars-d-learn
On 2015-03-18 21:50:39 +, Adam D. Ruppe said: It will not work because a function with an auto return value is actually a template, and unused templates won't be put into a dll. Ok, that makes it clear. Thanks. -- Robert M. Münch http://www.saphirion.com smarter | better | faster

Should this work: export extern(C) auto ...

2015-03-18 Thread Robert M. Münch via Digitalmars-d-learn
Windows, 32-Bit, DLL: export extern(C) struct1 struct1(){ struct1 x; return(x); } export extern(C) auto struct2(){ struct1 x; return(x); } struct1 is visible in the DLL, struct2 is not visible in the DLL. -- Robert M. Münch http://www.saphirion.com smarter | better | faster

Re: Should this work: export extern(C) auto ...

2015-03-18 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 18 March 2015 at 15:50:16 UTC, Robert M. Münch wrote: struct1 is visible in the DLL, struct2 is not visible in the DLL. It will not work because a function with an auto return value is actually a template, and unused templates won't be put into a dll.

Re: int-double auto array

2015-03-17 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 18 March 2015 at 03:54:01 UTC, Dennis Ritchie wrote: Hi. To create int-double array I have to pre-initialize the auto array: There's no such thing as an int double array, what you made there is just a double[]. The ints are converted to double when added to that array. So

int-double auto array

2015-03-17 Thread Dennis Ritchie via Digitalmars-d-learn
Hi. To create int-double array I have to pre-initialize the auto array: import std.stdio; import std.algorithm; void main() { auto s = [5.31, 6]; s = s.remove(0, 1); double k; readf(%s, k); // 17.32 s ~= k, s ~= 5, s ~= 1.125; writeln(s

Re: int-double auto array

2015-03-17 Thread Dennis Ritchie via Digitalmars-d-learn
On Wednesday, 18 March 2015 at 04:00:04 UTC, Adam D. Ruppe wrote: So you can just do double[] s; Thanks. Yes, I overthink everything :)

Re: auto function attributes based on type

2015-03-12 Thread ketmar via Digitalmars-d-learn
On Thu, 12 Mar 2015 04:51:40 +, amber wrote: On Thursday, 12 March 2015 at 04:04:28 UTC, weaselcat wrote: On Thursday, 12 March 2015 at 03:12:15 UTC, amber wrote: ... http://dlang.org/function.html#function-attribute-inference might be a good read if you haven't read it already. I did

Re: auto function attributes based on type

2015-03-12 Thread weaselcat via Digitalmars-d-learn
On Thursday, 12 March 2015 at 05:01:50 UTC, amber wrote: On Thursday, 12 March 2015 at 04:51:42 UTC, amber wrote: On Thursday, 12 March 2015 at 04:04:28 UTC, weaselcat wrote: On Thursday, 12 March 2015 at 03:12:15 UTC, amber wrote: ...

Re: auto function attributes based on type

2015-03-11 Thread weaselcat via Digitalmars-d-learn
On Thursday, 12 March 2015 at 03:12:15 UTC, amber wrote: ... http://dlang.org/function.html#function-attribute-inference might be a good read if you haven't read it already.

Re: auto function attributes based on type

2015-03-11 Thread amber via Digitalmars-d-learn
On Thursday, 12 March 2015 at 04:04:28 UTC, weaselcat wrote: On Thursday, 12 March 2015 at 03:12:15 UTC, amber wrote: ... http://dlang.org/function.html#function-attribute-inference might be a good read if you haven't read it already. I did read it but didn't really understand it, so I've

Re: auto function attributes based on type

2015-03-11 Thread amber via Digitalmars-d-learn
On Thursday, 12 March 2015 at 04:51:42 UTC, amber wrote: On Thursday, 12 March 2015 at 04:04:28 UTC, weaselcat wrote: On Thursday, 12 March 2015 at 03:12:15 UTC, amber wrote: ... http://dlang.org/function.html#function-attribute-inference might be a good read if you haven't read it already.

auto function attributes based on type

2015-03-11 Thread amber via Digitalmars-d-learn
and for others they're not. I'd rather not duplicate each function body just to get attributes working. Hmm, just had a thought, would this work?? --- struct S(T) { T[] values; private void someFuncImpl()(int i) { // the impl goes here with auto-deduced attributes

Re: with (auto p = new ...)

2014-09-26 Thread Freddy via Digitalmars-d-learn
On Tuesday, 23 September 2014 at 15:19:59 UTC, Andre wrote: Hi, I just wonder why with (auto p = new ...) is not working. It would be some syntax sugar in this scenario: with (auto p = new Panel()) { parent = this; text = bla

Re: with (auto p = new ...)

2014-09-26 Thread Freddy via Digitalmars-d-learn
On Friday, 26 September 2014 at 19:59:56 UTC, Freddy wrote: On Tuesday, 23 September 2014 at 15:19:59 UTC, Andre wrote: Hi, I just wonder why with (auto p = new ...) is not working. It would be some syntax sugar in this scenario: with (auto p = new Panel

Re: with (auto p = new ...)

2014-09-24 Thread kiran kumari via Digitalmars-d-learn
aOn Tuesday, 23 September 2014 at 15:19:59 UTC, Andre wrote: Hi, I just wonder why with (auto p = new ...) is not working. It would be some syntax sugar in this scenario: with (auto p = new Panel()) { parent = this; text = bla

Re: with (auto p = new ...)

2014-09-24 Thread Andre via Digitalmars-d-learn
Enhancement 13526 filed: https://issues.dlang.org/show_bug.cgi?id=13526

Re: with (auto p = new ...)

2014-09-24 Thread ketmar via Digitalmars-d-learn
On Wed, 24 Sep 2014 14:39:25 + Andre via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: Enhancement 13526 filed: https://issues.dlang.org/show_bug.cgi?id=13526 i wrote a quickhack-patch for this ER. as it's my first patch that goes outside parser it needs to be reviewed by

with (auto p = new ...)

2014-09-23 Thread Andre via Digitalmars-d-learn
Hi, I just wonder why with (auto p = new ...) is not working. It would be some syntax sugar in this scenario: with (auto p = new Panel()) { parent = this; text = bla; with (auto b = new Button

Re: with (auto p = new ...)

2014-09-23 Thread Nordlöw
On Tuesday, 23 September 2014 at 15:19:59 UTC, Andre wrote: I just wonder why with (auto p = new ...) is not working. It would be some syntax sugar in this scenario: I presume with is limited to expressions and not statements as the messages says. However, you can use if (auto p

Re: with (auto p = new ...)

2014-09-23 Thread Graham Fawcett via Digitalmars-d-learn
How about: auto b - new Button(); with (b) { On Tuesday, 23 September 2014 at 15:19:59 UTC, Andre wrote: Hi, I just wonder why with (auto p = new ...) is not working. It would be some syntax sugar in this scenario: with (auto p = new Panel()) { parent

Re: with (auto p = new ...)

2014-09-23 Thread Graham Fawcett via Digitalmars-d-learn
Sorry, I sent that last message before I intended to. How about: auto b = new Button(); with (b) { ... } 'b' is explicitly outside of the scope of the 'with' block, which may not be what you intended. But you could use more braces to add an extra level of scope if that's

Re: with (auto p = new ...)

2014-09-23 Thread andre via Digitalmars-d-learn
Yes, that is also working. As far as I remember (only my tablet currently available) also this works: Panel p; with(p = new Panel ()) {} Therefore it seems strange,the same does not work with auto. Kind regards André On Tuesday, 23 September 2014 at 19:49:22 UTC, Graham Fawcett wrote

Re: with (auto p = new ...)

2014-09-23 Thread Meta via Digitalmars-d-learn
I think this is just a language oversight. It's allowed in if statements, and people have made a good case for allowing it for switch statements. It just hasn't been implemented. I made an attempt one evening to implement it for switch statements, but I'm not at all familiar with DMD, so I

Re: with (auto p = new ...)

2014-09-23 Thread Nordlöw
On Tuesday, 23 September 2014 at 20:16:29 UTC, andre wrote: Therefore it seems strange,the same does not work with auto. Yes, it seem logical to me allow this also in with and switch.

Re: Auto-add static field when inherit // mixins, templates?

2014-08-22 Thread Chris Nicholson-Sauls via Digitalmars-d-learn
class A { string getName(this Klass)() { return Klass.stringof; } } class B : A {} void main() { import std.stdio; auto a = new A; auto b = new B; writeln(a.getName()); writeln(b.getName

Auto-add static field when inherit // mixins, templates?

2014-08-21 Thread MarisaLovesUsAll via Digitalmars-d-learn
inherit from base class Component, I need to auto-create child own static fields with child type. It should look like this, after compilation: class Component { //it doesn't matter to have any fields here //but it's important to be able to create an instance of Component //and when

Re: Auto-add static field when inherit // mixins, templates?

2014-08-21 Thread MarisaLovesUsAll via Digitalmars-d-learn
(foo.getName() == B); ... Hi! I'm stuck at one issue, and I don't know how to solve it. I think this is about mixins/templates, isn't it? When inherit from base class Component, I need to auto-create child own static fields with child type. It should look like this, after compilation: class

Re: Auto-add static field when inherit // mixins, templates?

2014-08-21 Thread anonymous via Digitalmars-d-learn
On Thursday, 21 August 2014 at 12:58:13 UTC, MarisaLovesUsAll wrote: I found a rough solution. It's not ideal and I still want to make autoinject, but it works. mixin template Manager(T) {}; class Component {}; class Sprite:Component { mixin Manager!Sprite; }; 1) How to make mixin inject

Re: Auto-add static field when inherit // mixins, templates?

2014-08-21 Thread MarisaLovesUsAll via Digitalmars-d-learn
(this)` in Manager: mixin template Manager() { void someMethod(typeof(this) otherInstance) {} } Thanks, it works. ...I also have more questions %) When I make mixin injection in one class, I want auto-injection in another class. How can I do this? class Component:GameObject { //second

Re: Auto-add static field when inherit // mixins, templates?

2014-08-21 Thread Ary Borenszweig via Digitalmars-d-learn
this is about mixins/templates, isn't it? When inherit from base class Component, I need to auto-create child own static fields with child type. It should look like this, after compilation: class Component { //it doesn't matter to have any fields here //but it's important to be able to create

Re: Auto-add static field when inherit // mixins, templates?

2014-08-21 Thread anonymous via Digitalmars-d-learn
On Thursday, 21 August 2014 at 19:58:18 UTC, MarisaLovesUsAll wrote: When I make mixin injection in one class, I want auto-injection in another class. How can I do this? class Component:GameObject { //second injection must be here and must be automatic }; class Sprite:Component

Re: Auto-add static field when inherit // mixins, templates?

2014-08-21 Thread anonymous via Digitalmars-d-learn
On Thursday, 21 August 2014 at 20:05:13 UTC, Ary Borenszweig wrote: I'll tell you how it's done in Crystal in case someone wants to come up with a proposal to make it work in D. ~~~ class Foo macro inherited def method_in_{{@class_name.downcase.id}} puts Hello {{@class_name.id}}!

Re: Auto-add static field when inherit // mixins, templates?

2014-08-21 Thread MarisaLovesUsAll via Digitalmars-d-learn
On Thursday, 21 August 2014 at 20:16:33 UTC, anonymous wrote: Maybe you can explain what you're trying to achieve with all this. There may be a different/better way to do it. Sure. Class tree: GameObject-Component-Sprite. GameObject structure: Component[]; Component

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

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

Auto attributes for functions

2014-08-19 Thread uri via Digitalmars-d-learn
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 show me where they're not applicable and take them away. It would be great if this could be achieved like

Re: Auto attributes for functions

2014-08-19 Thread Meta via Digitalmars-d-learn
On Wednesday, 20 August 2014 at 01:38:53 UTC, uri 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 show me where they're not applicable and take them

auto ref function parameters in a free function

2014-08-03 Thread Vlad Levenfeld via Digitalmars-d-learn
This doesn't work: bool less_than (T)(auto ref T a, auto ref T b) { return a b; } Error: auto can only be used for template function parameters What am I doing wrong? Is this not a template function?

Re: auto ref function parameters in a free function

2014-08-03 Thread Martijn Pot via Digitalmars-d-learn
On Sunday, 3 August 2014 at 19:07:32 UTC, Vlad Levenfeld wrote: This doesn't work: bool less_than (T)(auto ref T a, auto ref T b) { return a b; } Error: auto can only be used for template function parameters What am I doing wrong? Is this not a template function? I think you can

Re: auto ref function parameters in a free function

2014-08-03 Thread Vlad Levenfeld via Digitalmars-d-learn
This would make the function always take its argument by reference. I'm trying to use the feature here: http://dlang.org/template.html from the section Function Templates with Auto Ref Parameters

Re: auto ref function parameters in a free function

2014-08-03 Thread anonymous via Digitalmars-d-learn
On Sunday, 3 August 2014 at 19:07:32 UTC, Vlad Levenfeld wrote: bool less_than (T)(auto ref T a, auto ref T b) { return a b; } Error: auto can only be used for template function parameters Works for me with dmd versions back to 2.060. What compiler are you using?

Re: auto ref function parameters in a free function

2014-08-03 Thread Vlad Levenfeld via Digitalmars-d-learn
On Sunday, 3 August 2014 at 19:26:28 UTC, anonymous wrote: Works for me with dmd versions back to 2.060. What compiler are you using? dmd 2.065

Re: auto ref function parameters in a free function

2014-08-03 Thread anonymous via Digitalmars-d-learn
less_than.d bool less_than (T)(auto ref T a, auto ref T b) { return a b; } void main() { int a = 1, b = 2; assert(less_than(a, b)); assert(less_than(a, 2)); assert(less_than(1, b)); assert(less_than(1, 2)); } $ dmd less_than.d echo ok ok

Re: auto ref function parameters in a free function

2014-08-03 Thread Martijn Pot via Digitalmars-d-learn
On Sunday, 3 August 2014 at 19:25:32 UTC, Vlad Levenfeld wrote: This would make the function always take its argument by reference. I'm trying to use the feature here: http://dlang.org/template.html from the section Function Templates with Auto Ref Parameters I thought I finally saw

<    1   2   3   4   5   6   7   >