How do I write a concept that detects a pointer to an arithmetic type?
template <typename T>
concept arithmetic = std::is_arithmetic<T>::value;
template <typename T>
concept pointer_to_arithmetic = requires (T a) {
{ *a } -> arithmetic;
};
template <typename T>
void fn() {
printf("fail\n");
}
template <pointer_to_arithmetic T>
void fn() {
printf("pass\n");
}
struct s{};
int main() {
fn<int>();
fn<int*>();
fn<s>();
fn<s*>();
}
I tried the above and it compiles but doesn't do what it's supposed to.
Expected output is:
fail
pass
fail
fail
Instead I get:
fail
fail
fail
fail
It also doesn't work if I replace *a with a[0].