dimanche 21 novembre 2021

How to declare a template function with a std::ratio template parameter

I'm trying to define three functions with C++14 as below:

template <typename D = std::chrono::seconds>
typename D::rep test() {
    // somethinig
}

template <std::intmax_t N, std::intmax_t D = 1, typename V = uint64_t>
V test() {
     // something
}

The two functions work as expected. I can call them like test<std::chrono::minutes>() and test<60>. Now, I want to define the third function, which accepts a std::ratio as a template parameter.

template <template<std::intmax_t, std::intmax_t> class R, std::intmax_t N, std::intmax_t D, typename V = uint64_t>
V test() {
    // R<N, D> should be std::ratio<N, D>
    // something
}

But in this case I would get a compile-time error while calling test<std::milli>(). I think it's because the compiler mixed up the first function and the third function. How could I define the third one?

Aucun commentaire:

Enregistrer un commentaire