#include <iostream>
#include <concepts>
template <typename T>
concept is_int = requires (T t) {
sizeof(t) == sizeof(int);
};
is_int auto add(is_int auto a, is_int auto b) {
return a + b;
}
int main() {
int a = 5;
int b = 10;
std::cout << add(a, b);
}
Problems –
- identifier “concept” is undefined
- this declaration has no storage class or type specifier
- expected a ‘;’
Compiler – GCC 14.1.0 (with POSIX threads) + LLVM/Clang/LLD/LLDB 18.1.8 + MinGW-w64 12.0.0 (UCRT) – release 3
Platform – Windows
Visual Studio Code detects concepts as errors even though it compiles properly.
New contributor
WarFiN is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.