ericniebler / meta

A tiny metaprogramming library
Boost Software License 1.0
302 stars 47 forks source link

it seems that meta::transpose does not work #56

Closed qqsunkist closed 5 years ago

qqsunkist commented 6 years ago

using ListOfLists = meta::list< meta::list, meta::list<std::string, int>, meta::list<unsigned, long> >;

using tp_t = meta::transpose;

when the above code get compiled, the following errors are generated.

/Users/Michael_Z/open_source/meta/include/meta/meta.hpp:140:9: error: no type named 'type' in 'meta::v1::detail::fold_<meta::v1::list<meta::v1::list<char>, meta::v1::list<std::__1::basic_string<char>, int>, meta::v1::list<unsigned int, long> >, meta::v1::id<meta::v1::list<meta::v1::list<> > >, meta::v1::bind_back<meta::v1::quote<transform>, meta::v1::quote<push_back> > >' using _t = typename T::type; ^~~~~ /Users/Michael_Z/open_source/meta/include/meta/meta.hpp:1303:9: note: in instantiation of template type alias '_t' requested here using fold = _t<detail::fold_<List, id<State>, Fun>>; ^ /Users/Michael_Z/open_source/meta/include/meta/meta.hpp:2452:9: note: in instantiation of template type alias 'fold' requested here using transpose = fold<ListOfLists, ^ test_meta.cpp:12:22: note: in instantiation of template type alias 'transpose' requested here using tp_t = meta::transpose<listOfLists>; ^ 1 error generated.

anyone can figure it out ? thanks.

qqsunkist commented 6 years ago

some piece of code were ignored when published :(

CaseyCarter commented 5 years ago

From the error message, it looks like you're using:

using ListOfLists = meta::list<
    meta::list<char>, 
    meta::list<std::string, int>,
    meta::list<unsigned, long>
>;

using tp_t = meta::transpose<ListOfLists>;

which is ill-formed. Despite the lack of clarity in the documentation, the input to meta::transpose must be a list of lists of the same length in order for the output to be a list of lists of the same length,

If you change your program by adding another type to the first sublist, say double:

using ListOfLists = meta::list<
    meta::list<char, double>, 
    meta::list<std::string, int>,
    meta::list<unsigned, long>
>;

using tp_t = meta::transpose<ListOfLists>;

Then it compiles correctly, and tp_t is meta::list<meta::list<char, std::string, unsigned>, meta::list<double, int, string>> (https://godbolt.org/z/rBf6-O).

qqsunkist commented 5 years ago

Thanks, CaseyCarter. I got it.