Created
January 19, 2018 10:36
-
-
Save Manu343726/509dde37bed1c75146b72021debfb369 to your computer and use it in GitHub Desktop.
ADL-based SFINAE
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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?