How do I handle "warning: use of ‘auto’ in parameter declaration only available with -fconcepts"

Viewed 6004

This is the code that cause the warning:

inline auto getclock() { return std::chrono::steady_clock::now(); }
inline auto getelapsed(auto b, auto e) { return std::chrono::duration_cast<std::chrono::nanoseconds>(e-b).count(); }
//USAGE: auto b=getclock(); some_func_to_be_timed(...); auto duration=getelapsed(b, getclock()); ..

This code compiled without problem before I recently upgraded to gcc 8 (c++17), now I get the warning as stated in the question. Why would I get this warning now, and how should I handle it?

PS: I don't use concepts (explicitly) anywhere in the rest of the code.

1 Answers

auto as parameter are not (yet) allowed for regular functions.

You might use regular template, something like:

template <typename T> // or T1, T2 to mimic your code
auto getelapsed(T b, T e)
{
    return std::chrono::duration_cast<std::chrono::nanoseconds>(e-b).count();
}
Related