How to replicate map, filter and reduce behaviors in C++ using STL?

后端 未结 2 1692
野性不改
野性不改 2021-01-31 10:27

I suppose we can use std::transform to replicate the map behavior in C++ like this :

std::vector in = { 1 , 2 , 3 ,4 }; 
std::vector out(i         


        
2条回答
  •  北荒
    北荒 (楼主)
    2021-01-31 10:57

    Depends which container you use.

    std::back_inserter will work only if the container has a push_back function.

    For example back_insterter can't be used with forward_list.

    In that case we need to have the memory allocated before we call std::transform on the same and first approach is better.

提交回复
热议问题