As an example, I want to use a constraint to ensure that the function isinf is implemented for a template parameter T. If T is one of float, double, long double or an integral type, this can be done in the following way:
#include <cmath>
template <typename T>
concept Test = requires (T a) {
std::isinf(a);
};
However, I also want to use this constraint for custom, non-standard data types for which I implement my own isinf function. This function is not contained in the std namespace, so I tried the following instead:
#include <cmath>
template <typename T>
concept Test = requires (T a) {
using std::isinf;
isinf(a);
};
This does not work since every statement in the requires clause should be a valid requirement and using std::isinf is not a "requirement" at all.
I see two workarounds to this problem:
Move the
using std::isinf;clause to the global namespace. But this introducesisinfto the global namespace, which I'd like to avoid.Encapsulate the
using std::isinf;clause with the concept definition in a namespace namedABC, then addusing ABC::Test;directly after the namespace. This seems a little bit weird.
Is there a better solution?