After this question by utilizing ADL one can create a trait to answer if the passed type comes from our namespace:
#include <utility>
namespace helper
{
template <typename T, typename = void>
struct is_member_of_sample : std::false_type
{
};
template <typename T>
struct is_member_of_sample<
T,
decltype(adl_is_member_of_sample(std::declval<T>()))> : std::true_type
{
};
}
namespace sample
{
template <typename T>
auto adl_is_member_of_sample(T && ) -> void;
}
// -- Test it
namespace sample
{
struct X;
}
struct Y;
static_assert(helper::is_member_of_sample<sample::X>::value, "");
static_assert(not helper::is_member_of_sample<Y>::value, "");
int main(){}
From obvious reason this cannot be applied to the std
namespace - there is simply no way to inject the adl_is_member_of_sample
equivalent to the std
namespace without exposing ourself to undefined behaviour.
Is there some workaround enabling to create the trait?
std::pair<foo::fooClass, bar::barClass>
is in three namespaces - std, foo, and bar. – Carverstd::hash
which isn't sfinae ready... – Lehrstd::hash
was designed as a set of free functions, and fighting that design just makes things harder. Whether it needs to be a friend depends on just what it does, but free function that's a friend is still a free function. – Braid