This project is read-only.

sum ( selector) cannot work with select statement

Nov 21, 2017 at 4:49 AM
If the select statement returns an object type of which no operator += declared, compilation error occurs because sum_selector_builder function declaration is

template<typename TRange>
select_range::value_type sum_selector_builder::build(TRange range) const

of which select_range::value_type is the object returns from the predicate lambda expression, which is not desirable. The function return type should be determined from the return type of sum selector lambda expression.

Example usage:

typedef std::shared_ptr<SD> SDPtr;
std::vector<SDPtr> SequenceList;

//Note: long long SD::GetWin() const;

long long TotalAmount =
    from(SequenceList)
            >> select([] (SDPtr spSd) { spSd->DoSomeStuff(); return spSd; })
    >> sum([](const SDPtr& spSd) { return spSd->GetWin(); });
Resolution:
  1. Adding a static function without implementation in class member section under sum_selector_builder
static typename selector_type get_selector();
  1. Change sum_selector_builder::build() function return type to
        template<typename TRange>
        CPPLINQ_INLINEMETHOD auto build (TRange range_) -> decltype( get_selector()(range_.front()))const