Composability of STL algorithms

后端 未结 4 1303
星月不相逢
星月不相逢 2021-02-02 06:44

The STL algorithms are a pretty useful thing in C++. But one thing that kind of irks me is that they seem to lack composability.

For example, let\'s say I have a v

4条回答
  •  既然无缘
    2021-02-02 07:12

    I think the problem is unfortunately structural

    1. C++ uses two iterators to represent a sequence
    2. C++ functions are single-valued

    so you cannot chain them because a function cannot return "a sequence".

    An option would have been to use single-object sequences instead (like the range approach from boost). This way you could have combined the result of one processing as the input of another... (one object -> one object).

    In the standard C++ library instead the processing is (two objects -> one object) and it's clear that this cannot be chained without naming the temporary object.

提交回复
热议问题