“Overload” function template based on function object operator() signature in C++98

后端 未结 1 1789
梦如初夏
梦如初夏 2020-12-21 15:35

I want to make a template function that takes a function and a vector and uses the function to map that vector to another vector that will be returned by the function templa

1条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-21 15:50

    Here's my approach:

    template  struct ignore_value {typedef T type;};
    
    template 
    T& declval();
    
    template
    typename ignore_value()(declval())),
           std::vector >::type map_vec(F fnc, const std::vector& source);
    
    template
    typename ignore_value()
                             (declval(), declval >())),
           std::vector >::type map_vec(F fnc, const std::vector& source);
    

    It works with the same Demo that 0x499602D2 used, with both GCC and Clang in C++98 mode.

    0 讨论(0)
提交回复
热议问题