How to constraint a function for pair-like objects?

62 Views Asked by At

In C++20, I need to implement a static function key() that takes a const reference to an object and returns a const reference to the key. Since the object can be a key itself or a key-value pair, the function has been implemented in the following way:

template <typename K>
static const K& key(const K& x) noexcept
{ return x; }

template <pair-like P>
static const K& key(const P& x) noexcept
{ return std::get<0>(x); }

Is there a way to constraint the second function overload in order that it accept only a pair-like object as an argument?

0

There are 0 best solutions below