I am trying to use C++20 Concepts to constrain an interface. In this interface, I want a function signature to only use references. For some reason, I can't do this. Would someone help?
#include <concepts>
template <typename T>
concept MyInterface = requires(T t)
{
// How do I specify a f(int&) instead of f(int) here?
{t.f(int{})} -> std::integral;
};
struct X
{
int f(int& i) {
return i;
}
};
static_assert(MyInterface<X>);
/*
** While tempting, this is _NOT_ a solution. **
template <typename T>
concept MyInterface = requires(T t, int& i) // Add a requirement here.
{
{t.f(i)} -> std::integral;
};
// This will compile, despite allowing `i` to be an int.
// When really, it should be a int&.
X::f(int i) { return i };
*/