Topic: Provide a global method to convert any structure
Author: Matthew Woehlke <mwoehlke.floss@gmail.com>
Date: Wed, 3 Aug 2016 12:24:51 -0400
Raw View
On 2016-08-01 15:32, Antonio Perez wrote:
> There has been some discussion of adding reflection to C++, with the main
> arguments in opposition being that 1) it would take a lot of effort to do
> so, and 2) template metaprogramming can be used in place of reflection in
> most cases. Both of these things are true, however template metaprogramming
> still has shortcomings. I propose that most of the shortcomings in template
> metaprogramming can be overcome if there were a method to convert a class
> or structure into a tuple that contained copies of all member variables.
> For example:
>
> template<typename T> /*tuple whose parameters depend on input type*/ Unpack(
> const T& input);
I've previously suggested:
std::make_tuple([*]my_struct...);
That is, convert a tuple-like into a parameter pack. This gets you what
you want with only one extra step (std::make_tuple) and is FAR more
powerful overall. For example:
struct simple_t { int a; int b; }
auto s = simple_t{1, 2};
auto sum = [*]s + ...;
int add(int, int);
add([*]s...);
You could even write `unpack` in terms of this feature:
auto unpack(auto const& in) { return std::make_tuple([*]in...); }
--
Matthew
--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/57A21AD3.5010103%40gmail.com.
.