[GiNaC-devel] Best way to iterate through an expression
Jan Rheinländer
jrheinlaender at gmx.de
Thu May 11 19:49:04 CEST 2017
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
>
More information about the GiNaC-devel
mailing list