11 May
2017
11 May
'17
7:49 p.m.
Dear Ricardo, great idea! I compacted it to for (const auto& m: (is_a<mul>(some_ex) ? some_ex : lst{some_ex}) // Do something with m Greetings, Jan Am 10.05.2017 um 17:47 schrieb Ricardo Buring:
Dear Jan,
Here's a trick I've used to avoid such code duplication:
if (!is_a<mul>(some_ex)) some_ex = lst(some_ex); for (const auto& m : some_ex) { // Do something with m }
If some_ex is a product then you iterate over the factors, and otherwise you iterate over the 1-element lst containing only some_ex. Perhaps this fits your use case as well.
Best wishes, Ricardo