The std::transform-like function that returns transformed container

后端 未结 5 919
心在旅途
心在旅途 2020-12-04 21:59

I\'m trying to implement a function similar to std::transform algorithm but instead of taking the output iterator by an argument I want to create and return a c

5条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-04 22:26

    The major difficulty is to somehow get the container type Container from Conainer. I have shamelessly stolen the code from template metaprogramming: (trait for?) dissecting a specified template into types T, in particular, Kerrek SB's answer (the accepted answer), as I am not familiar with template metaprogramming.

    #include 
    #include 
    #include 
    
    // stolen from Kerrek SB's answer
    template 
    struct tmpl_rebind {
        typedef T type;
    };
    
    template