简体   繁体   中英

Can you have typedefs for a single function?

I'm just wondering, in the following function I'm trying to get the return type of "Getter" into the function arguments. The default arguments is so that you don't need to pass the final arguments, especially if you don't provide a setter. Is there a cleaner way?

template <typename Getter, typename Setter>
        void makeSpinnerBox(Getter getter, Setter setter = char, float sensitivity = 0.f,
             std::invoke_result_t<Getter> minValue = std::invoke_result_t<Getter>(), 
             std::invoke_result_t<Getter> maxVal = std::invoke_result_t<Getter>(), 
             std::invoke_result_t<Getter> incrementStep = std::invoke_result_t<Getter>());

Maybe a typedef?

Using a defaulted template parameter:

template <typename Getter, typename Setter, typename R = std::invoke_result_t<Getter>>
void makeSpinnerBox(Getter getter, Setter setter, float sensitivity = 0.f,
                    R minValue = R(), R maxVal = R(), R incrementStep = R())

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM