小编Ale*_*voy的帖子

Define a function in function declaration using std::iterator traits and auto

Today I tried to implement radix sort. The function must have two variables: begin iterator and end iterator, and can have third: some function that must return the integer type to sort by. By default it must be the identity function.

My tries look like (sorry, code looks very long and dirty, but it's just a try):

template<class ForwardIt>
void radix_sort(
    ForwardIt first,
    ForwardIt last,
    std::function<auto(typename std::iterator_traits<ForwardIt>::value_type)> get_value =
    [](const typename std::iterator_traits<ForwardIt>::value_type& x){ return x; }) {
        // ...
} …
Run Code Online (Sandbox Code Playgroud)

c++ c++11

9
推荐指数
2
解决办法
178
查看次数

标签 统计

c++ ×1

c++11 ×1