I want to test out the new concepts feature in c++20 and I was wondering if I can create a concept that checks for the existence of a function that is declared const.
I want the check to fail if the function exists with the right type but isn't const. I couldn't find anything relevant here: https://en.cppreference.com/w/cpp/concepts
I have this
template <typename T>
concept hasToString = requires (T val) {
{ val.toString() } /* const here gives error */ -> std::same_as<std::string>;
};
void f(hasToString auto bar)
{
std::cout << bar.toString();
}