STL algorithms: Why no additional interface for containers (additional to iterator pairs)?

前端 未结 7 622
花落未央
花落未央 2020-11-30 11:31

I\'m wondering why the STL doesn\'t overload their algorithm functions such that I can call them by simply providing a container and not taking the more verbose way to pass

7条回答
  •  余生分开走
    2020-11-30 11:46

    There is a Range Operators library with intention to fix that. Verbosity was cut several times over.

    Your example would look something like this:

    auto newVector = myVector * doSomething;
    

    Yes, doSomething - is without parenthesis.

    Familiar idiom from shell (with std algorithm):

    auto t = vector{3,2,1,4} | sort | unique; 
    

提交回复
热议问题