Created
June 7, 2020 18:53
-
-
Save moonmagian/294000cbdedc60ceaf399cb4412c8f4b to your computer and use it in GitHub Desktop.
header only library to help implementing concept for a class
This file contains 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
// This header only library is usued to check whether a class satisfies a concept. | |
// When compiling, an error will happen if the class doesn't satisfy the concept. | |
// IDEs like QtCreator and CLion will also display an error for it whiling editing. | |
// This is useful when you want to satisfy a concept by implementing methods one by one. | |
// (without checking the definition of the concept over time). | |
// usage: implement(class, concept, unique name for the implementation) | |
// define DISABLE_IMPL_CHECK to disable the macro. | |
#ifndef IMPLEMENT_CONCEPT_HPP | |
#define IMPLEMENT_CONCEPT_HPP | |
#ifndef DISABLE_IMPL_CHECK | |
#define implement(cl, con, name) \ | |
template <con T> class __sat_check_##name##_c {};\ | |
static __sat_check_##name##_c<cl> __sat_check_##name __attribute__((unused)); | |
#else | |
#define implement(cl, con, name) ; | |
#endif | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment