I'm following Josh Lospinoso's C++ Crash Course and I'm at a part where it's trying to show me an example of how to use concepts to constrain a method's parameters, and also wants me to use type_traits. However, I'm getting errors saying that it's argument list is missing and that it has an invalid combination of type specifiers. Here's the concept and the method:
template <typename T>
concept bool Averageable() {
return std::is_default_constructible<T>::value && requires (T a, T b) {
{ a += b } -> T;
{ a / size_t{ 1 } } -> T;
};
}
template <Averageable T>
T mean(const T* values, size_t length) {
T result{};
for (size_t i{}; i < length; i++) {
result += values[i];
}
return result / length;
}