Skip to content

Instantly share code, notes, and snippets.

@Manu343726
Created January 19, 2018 10:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Manu343726/509dde37bed1c75146b72021debfb369 to your computer and use it in GitHub Desktop.
Save Manu343726/509dde37bed1c75146b72021debfb369 to your computer and use it in GitHub Desktop.
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
Copy link

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