alkurbatov/suvorov-bot

Refactor: Create chaining filter class

Closed this issue · 2 comments

For GetUnits(sc2::Filter), it would be good to create a chaining filter class in Helpers.h/cpp in order to reuse code for compound filters. [e.g. .GetUnits( AllOf( IsNonSaturated(IsFinished(IsTownHall())) ) ) ]

alkurbatov:
"i.e. assuming that we have IsNonSaturatedTownHall, IsTownHall and IsFinished it would be convenient to use e.g. 'AllOf' predicate which uses inside all of these. Ideally, it should be part of the API.

The simples way would be to use this approach:
http://www.cplusplus.com/reference/algorithm/all_of/

This lambda should chain our predicates.

Speaking about creating a special class, std::vector is enough, I think.
Also, there is a trick with predicates as template argument, but I am not sure how to do it with variadic list of parameters."

Other possible references for different chaining syntaxes:
https://www.fluentcpp.com/2019/08/06/chaining-output-iterators-into-a-pipeline/
http://cpptruths.blogspot.com/2014/03/fun-with-lambdas-c14-style-part-1.html
https://stackoverflow.com/questions/8367879/c-lambda-expression-for-method-chains
https://chriskohlhepp.wordpress.com/advanced-c-lisp/lambda-over-lambda-in-cplusplus14/

I suggest to add it to cpp-sc2 in the form of a separate call like getUnits, but getUnitsAllOf with array of filters passed by reference. In this case the implementation will be much simpler.

Moved this to cpp-sc2.