Re: get from tuple by type

2015-03-15 Thread anonymous via Digitalmars-d-learn
On Sunday, 15 March 2015 at 23:13:58 UTC, Charles Cooper wrote: And yes, I could use names. But then you are subject to name clashes and using strings instead of types as member identifiers is more prone to error anyways. Ever gotten this wrong before -- void CRITICAL_TO_GET_THIS_RIGHT(uint

Re: get from tuple by type

2015-03-15 Thread anonymous via Digitalmars-d-learn
On Sunday, 15 March 2015 at 21:59:18 UTC, Charles Cooper wrote: C++14 has: templateclass T, class... Types constexpr T get(tupleTypes... t); Which allows you to get a member of the tuple struct by type. Is there an idiomatic / library way to do this in D? Preferably by indexing. I don't

Re: get from tuple by type

2015-03-15 Thread Charles Cooper via Digitalmars-d-learn
foo[1] is sometimes better, but not always. One has to go back to the definition of the thing and literally calculate by hand which element of the tuple you want, and then try compiling it, and so forth. Although the type system will guarantee that you eventually get it right it is a waste of

Re: get from tuple by type

2015-03-15 Thread Charles Cooper via Digitalmars-d-learn
Not offended at all :), in fact it was not even my suggestion that it be included in the standard. I was just knee jerk reacting to the comment that, just because something is simple to do precludes it from getting standardized On Sunday, 15 March 2015 at 23:28:18 UTC, ketmar wrote: sorry

Re: get from tuple by type

2015-03-15 Thread bearophile via Digitalmars-d-learn
Charles Cooper: Yes, I could say external_api1_react_to_event(event_t[1], event_t[0]) .. but that is barbaric. It's a productivity sink because I have to go back to the original definition, align the arguments, and then context switch back to whatever I was working on before. If you are

get from tuple by type

2015-03-15 Thread Charles Cooper via Digitalmars-d-learn
C++14 has: templateclass T, class... Types constexpr T get(tupleTypes... t); Which allows you to get a member of the tuple struct by type. Is there an idiomatic / library way to do this in D? Preferably by indexing. Here is what I have, it is ugly but works: /* CODE */ static import

Re: get from tuple by type

2015-03-15 Thread ketmar via Digitalmars-d-learn
On Sun, 15 Mar 2015 22:35:03 +, weaselcat wrote: Seems like a useful feature(useful enough to get past the C++ standards committee,) consider submitting a phobos PR? ah, c++ committee accepts by randomness. ;-) honestly, i can't see why it's useful and where it can be used. and it's so

Re: get from tuple by type

2015-03-15 Thread ketmar via Digitalmars-d-learn
p.s. to be clear: it's freaking hard to do metaprogramming and template functional programming in c++, that's why c++ committee accepts such things. and it's very easy to write such code in D, so this is a good excersise for newcomers and almost no-brainer for expirienced D user. signature.asc

Re: get from tuple by type

2015-03-15 Thread Charles Cooper via Digitalmars-d-learn
Thanks for the style recommendations. On Sunday, 15 March 2015 at 23:14:32 UTC, anonymous wrote: I don't think there is. I don't know if there should be. Distinguishing tuple fields by their type doesn't seem very useful to me, since multiple fields can have the same type. Using combined

Re: get from tuple by type

2015-03-15 Thread Charles Cooper via Digitalmars-d-learn
Sure. It is also easy to write merge sort. Or std.typetuple.Erase. Or Tuple.opIndex(size_t). But that doesn't mean everybody does it. Some utilities (and I am not saying this is, but it could be) are widely used enough that it makes sense to put them in the standard. On Sunday, 15 March 2015

Re: get from tuple by type

2015-03-15 Thread ketmar via Digitalmars-d-learn
On Sun, 15 Mar 2015 23:30:48 +, Charles Cooper wrote: Not offended at all :), in fact it was not even my suggestion that it be included in the standard. I was just knee jerk reacting to the comment that, just because something is simple to do precludes it from getting standardized ah, i

Re: get from tuple by type

2015-03-15 Thread Charles Cooper via Digitalmars-d-learn
http://dlang.org/phobos/std_variant.html#.Algebraic Thanks! This is fascinating, really a breath of fresh air coming from the C++ way of doing things. On Sunday, 15 March 2015 at 23:31:59 UTC, bearophile wrote: If you are experiencing those problems it's probably the way D/Phobos to tell you

Re: get from tuple by type

2015-03-15 Thread ketmar via Digitalmars-d-learn
On Sun, 15 Mar 2015 21:59:16 +, Charles Cooper wrote: C++14 has: templateclass T, class... Types constexpr T get(tupleTypes... t); Which allows you to get a member of the tuple struct by type. Is there an idiomatic / library way to do this in D? Preferably by indexing. why indexing?

Re: get from tuple by type

2015-03-15 Thread Charles Cooper via Digitalmars-d-learn
True. If I had to do something involving such an API I would first wrap the API with a type safe one before doing anything else. void external_api_do_something(uint dollars, uint cents); /* I think this could somehow be automated with staticMap and ParameterTypeTuple /

Re: get from tuple by type

2015-03-15 Thread ketmar via Digitalmars-d-learn
On Sun, 15 Mar 2015 23:17:34 +, Charles Cooper wrote: Sure. It is also easy to write merge sort. Or std.typetuple.Erase. Or Tuple.opIndex(size_t). But that doesn't mean everybody does it. Some utilities (and I am not saying this is, but it could be) are widely used enough that it makes