[fusion] nth runtime element of a sequence
Hello, I just wanted to confirm there's no provided method to get the n'th element of say a fusion vector where n is known at runtime, except of handling it explicitkly with a switch case? Thanks MM
2014-02-24 11:55 GMT+01:00 MM <finjulhich@gmail.com>:
Hello,
I just wanted to confirm there's no provided method to get the n'th element of say a fusion vector where n is known at runtime, except of handling it explicitkly with a switch case?
Thanks
MM
If such a function existed, what return type would it have? Regards, Kris
On 02/24/14 05:04, Krzysztof Czainski wrote:
2014-02-24 11:55 GMT+01:00 MM <finjulhich@gmail.com <mailto:finjulhich@gmail.com>>:
Hello,
I just wanted to confirm there's no provided method to get the n'th element of say a fusion vector where n is known at runtime, except of handling it explicitkly with a switch case?
Thanks
MM
If such a function existed, what return type would it have?
Regards, Kris
What about: variant<T1,T2,T3> get(unsigned n, vector<T1,T2,T3>) ? For example: vector<T1,T2,T3> vec(T1(),T2(),T3()); variant<T1,T2,T3> var; var = get(2,vec); assert(var.which(),2); -regards, Larry
On 24 February 2014 14:28, Larry Evans <cppljevans@suddenlink.net> wrote:
On 02/24/14 05:04, Krzysztof Czainski wrote:
2014-02-24 11:55 GMT+01:00 MM <finjulhich@gmail.com <mailto:finjulhich@gmail.com>>:
Hello,
I just wanted to confirm there's no provided method to get the n'th element of say a fusion vector where n is known at runtime, except of handling it explicitkly with a switch case?
Thanks
MM
If such a function existed, what return type would it have?
Regards, Kris
What about: variant<T1,T2,T3> get(unsigned n, vector<T1,T2,T3>) ? For example:
vector<T1,T2,T3> vec(T1(),T2(),T3()); variant<T1,T2,T3> var; var = get(2,vec); assert(var.which(),2);
-regards, Larry
Possible, a variant over the unique types in the sequence. What would the impl look like though?
MM
On 02/24/14 11:55, MM wrote:
On 24 February 2014 14:28, Larry Evans <cppljevans@suddenlink.net <mailto:cppljevans@suddenlink.net>> wrote:
On 02/24/14 05:04, Krzysztof Czainski wrote:
2014-02-24 11:55 GMT+01:00 MM <finjulhich@gmail.com <mailto:finjulhich@gmail.com> <mailto:finjulhich@gmail.com <mailto:finjulhich@gmail.com>>>__:
Hello,
I just wanted to confirm there's no provided method to get the n'th element of say a fusion vector where n is known at runtime, except of handling it explicitkly with a switch case?
Thanks
MM
If such a function existed, what return type would it have?
Regards, Kris
What about: variant<T1,T2,T3> get(unsigned n, vector<T1,T2,T3>) ? For example:
vector<T1,T2,T3> vec(T1(),T2(),T3()); variant<T1,T2,T3> var; var = get(2,vec); assert(var.which(),2);
-regards, Larry
Possible, a variant over the unique types in the sequence. What would the impl look like though?
I'd guess it would have switch statements, as you surmised in your OP. I'd also guess it could be implemented with some sort of vector of n functors, where n is the size of the fusion vector, and the i-th functor simply call fusion's get<i>(vec) and assigns the result to the variant. This vector of functors would then be used in the implementation of the get(i,vec) mentioned in my post. HTH -regards, Larry
On 02/24/14 12:51, Larry Evans wrote:
On 02/24/14 11:55, MM wrote:
On 24 February 2014 14:28, Larry Evans <cppljevans@suddenlink.net <mailto:cppljevans@suddenlink.net>> wrote:
On 02/24/14 05:04, Krzysztof Czainski wrote:
2014-02-24 11:55 GMT+01:00 MM <finjulhich@gmail.com <mailto:finjulhich@gmail.com> <mailto:finjulhich@gmail.com <mailto:finjulhich@gmail.com>>>__:
Hello,
I just wanted to confirm there's no provided method to get the n'th element of say a fusion vector where n is known at runtime, except of handling it explicitkly with a switch case?
Thanks
MM
If such a function existed, what return type would it have?
Regards, Kris
What about: variant<T1,T2,T3> get(unsigned n, vector<T1,T2,T3>) ? For example:
vector<T1,T2,T3> vec(T1(),T2(),T3()); variant<T1,T2,T3> var; var = get(2,vec); assert(var.which(),2);
-regards, Larry
Possible, a variant over the unique types in the sequence. What would the impl look like though?
I'd guess it would have switch statements, as you surmised in your OP. I'd also guess it could be implemented with some sort of vector of n functors, where n is the size of the fusion vector, and the i-th functor simply call fusion's get<i>(vec) and assigns the result to the variant. This vector of functors would then be used in the implementation of the get(i,vec) mentioned in my post.
This vector of functors was proposed for variant here: http://lists.boost.org/Archives/boost/2012/04/192357.php IIRC, there was also a preprocessor generated switch statement as an alternative implementation. I'd guess this should give some idea of how to do what you want. HTH.
HTH -regards, Larry
On 02/24/14 11:55, MM wrote:
On 24 February 2014 14:28, Larry Evans <cppljevans@suddenlink.net <mailto:cppljevans@suddenlink.net>> wrote:
On 02/24/14 05:04, Krzysztof Czainski wrote:
2014-02-24 11:55 GMT+01:00 MM <finjulhich@gmail.com <mailto:finjulhich@gmail.com> <mailto:finjulhich@gmail.com <mailto:finjulhich@gmail.com>>>__:
Hello,
I just wanted to confirm there's no provided method to get the n'th element of say a fusion vector where n is known at runtime, except of handling it explicitkly with a switch case?
Thanks
MM
If such a function existed, what return type would it have?
Regards, Kris
What about: variant<T1,T2,T3> get(unsigned n, vector<T1,T2,T3>) ? For example:
vector<T1,T2,T3> vec(T1(),T2(),T3()); variant<T1,T2,T3> var; var = get(2,vec); assert(var.which(),2);
-regards, Larry
Possible, a variant over the unique types in the sequence.
It has to be over unique types because boost::variant cannot handle duplicates. However, if, instead of boost::variant, a truly tagged union: http://en.wikipedia.org/wiki/Tagged_union were used, then the types could be duplicated and there would be any need to program some metafunction to find the unique types in the fusion::vector<T1,T2,...,Tn>. Tagged unions were also requested here: http://stackoverflow.com/questions/17727563/tagged-unions-aka-variant-in-c-w... which also provided a link to an implementation of a tagged union.
What would the impl look like though?
MM
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Steven Watanabe proposed Boost.Switch years ago and I believe it was accepted but never added. It would work fine here to do what you want and has more general use than just fusion (and gives more information than a variant result would). I bring this up every time a question like this comes up but it would be nice for his library to be revived and added. :( On Feb 24, 2014 2:55 AM, "MM" <finjulhich@gmail.com> wrote:
Hello,
I just wanted to confirm there's no provided method to get the n'th element of say a fusion vector where n is known at runtime, except of handling it explicitkly with a switch case?
Thanks
MM
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
On 25 February 2014 18:39, Matt Calabrese <rivorus@gmail.com> wrote:
Steven Watanabe proposed Boost.Switch years ago and I believe it was accepted but never added. It would work fine here to do what you want and has more general use than just fusion (and gives more information than a variant result would). I bring this up every time a question like this comes up but it would be nice for his library to be revived and added. :(
I found the header file here, I suppose that's all that's needed. http://dancinghacker.com/switch/switch.hpp MM
On 02/26/14 05:54, MM wrote:
On 25 February 2014 18:39, Matt Calabrese <rivorus@gmail.com <mailto:rivorus@gmail.com>> wrote:
Steven Watanabe proposed Boost.Switch years ago and I believe it was accepted but never added. It would work fine here to do what you want and has more general use than just fusion (and gives more information than a variant result would). I bring this up every time a question like this comes up but it would be nice for his library to be revived and added. :(
I found the header file here, I suppose that's all that's needed. http://dancinghacker.com/switch/switch.hpp
Strange place to find the code! Some version of code is also still in svn: http://svn.boost.org/svn/boost/sandbox/switch/boost/control/switch.hpp Based only on the Copyright comments in the two version, I'd guess the one in svn is newer. I searched github for the code, but had no luck.
MM
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (4)
-
Krzysztof Czainski
-
Larry Evans
-
Matt Calabrese
-
MM