Repeating a list
weshoke opened this issue · comments
I'm trying to figure out how to take a list list<0, 1, 2>
and turn it into a list list<0, 0, 0, 1, 1, 1, 2, 2, 2>
.
I've tried various combinations of:
flatten<transform<List, filled_list<_1, 3>>>
The above code gives an error about _1 not having a type
member, so I made a lazy version of flatten:
namespace lazy
{
template <typename Sequence>
using flatten = typename detail::flatten_impl<Sequence>;
}
and then did
transform<List, lazy::filled_list<_1, 3>>
Now the problem is that I have a list of filled_list_impl
types, and I can't figure out how to unwrap them to flatten them. Thoughts?
Could you share the code?
using List = brigand::list<
brigand::uint16_t<0>,
brigand::uint16_t<1>,
brigand::uint16_t<2>>;
using Expanded = brigand::transform<List, brigand::filled_list<brigand::_1, 3>>;
int main(int argc, const char * argv[])
{
brigand::for_each<Expanded>([](auto v)
{
using T = brigand::type_from<decltype(v)>;
std::cout << typeid(T).name() << "\n";
});
return 0;
}
Using the lazy version, this one compiles:
using List = brigand::list<
brigand::uint16_t<0>,
brigand::uint16_t<1>,
brigand::uint16_t<2>>;
using Expanded = brigand::transform<List, brigand::lazy::filled_list<brigand::_1, 3>>;
int main(int argc, const char * argv[])
{
brigand::for_each<Expanded>([](auto v)
{
using T = brigand::type_from<decltype(v)>;
std::cout << typeid(T).name() << "\n";
});
return 0;
}
But each element isn't a sequence, so flatten
won't give me a 9 element list.
I don't have a solution for this exact problem right now, but my understanding of the lambda system (bind, apply, defer) has improved a lot after reading seeing the cartesian product examples and the discussion here: #187 . This is enough for me to close this out.