Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
ADL-based SFINAE
namespace bitmasks_lib
{
std::false_type enableBitMaskOperators(type_tag<T>);
// use the result of this function as SFINAE predicate
template<typename T>
constexpr bool bitmaskOperatorsEnabled()
{
using bitmasks_lib::enableBitMaskOperators;
return decltype(enableBitMaskOperators(type_tag<T>()))::value;
}
}
#define ENABLE_BITMASK_OPERATORS(T) std::true_type enableBitMaskOperators(type_tag<T>);
// usage:
namespace mynamespace
{
enum class MyBitmap
{
...
};
ENABLE_BITMASK_OPERATORS(MyBitmap)
}
@Guillaume227

This comment has been minimized.

Copy link

@Guillaume227 Guillaume227 commented Apr 14, 2019

Hello Manu,
where does the 'T' come from in
std::false_type enableBitMaskOperators(type_tag<T>);
Also, where is type_tag defined and why is it needed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.