diff --git a/README.md b/README.md index 8cf1254..f50f1cf 100644 --- a/README.md +++ b/README.md @@ -383,6 +383,25 @@ struct foo }; ``` +If the member is defined outside of the class, use `TICK_MEMBER_REQUIRES_OC` (OC: outside_class) outside the class. For example, +```cpp +template +struct foo +{ + T x; + + TICK_MEMBER_REQUIRES(is_incrementable()) + void up(); +}; + +template +TICK_MEMBER_REQUIRES_OC(is_incrementable()) +void foo::up() +{ + x++; +} +``` + TICK_PARAM_REQUIRES -------------------- diff --git a/doc/src/requires.md b/doc/src/requires.md index 2d2d9dc..53d455c 100644 --- a/doc/src/requires.md +++ b/doc/src/requires.md @@ -57,6 +57,25 @@ struct foo }; ``` +If the member is defined outside of the class, use `TICK_MEMBER_REQUIRES_OC` (OC: outside_class) outside the class. For example, +```cpp +template +struct foo +{ + T x; + + TICK_MEMBER_REQUIRES(is_incrementable()) + void up(); +}; + +template +TICK_MEMBER_REQUIRES_OC(is_incrementable()) +void foo::up() +{ + x++; +} +``` + TICK_PARAM_REQUIRES -------------------- diff --git a/test/requires.cpp b/test/requires.cpp index eb2a468..01b5b05 100644 --- a/test/requires.cpp +++ b/test/requires.cpp @@ -3,6 +3,7 @@ #include #include #include +#include struct not_int {}; @@ -163,3 +164,36 @@ TICK_STATIC_TEST_CASE() STATIC_ASSERT_SAME(decltype(check_param_trait_requires(not_int())), std::false_type); }; + + +template +struct member_requires_oc +{ + T x; + + TICK_MEMBER_REQUIRES(std::is_same::value) + int foo(); + + TICK_MEMBER_REQUIRES(std::is_same::value) + char foo(); +}; + +template +TICK_MEMBER_REQUIRES_OC(std::is_same::value) +int member_requires_oc::foo() +{ + return 123; +} + +template +TICK_MEMBER_REQUIRES_OC(std::is_same::value) +char member_requires_oc::foo() +{ + return 'a'; +} + +TICK_TEST_CASE() +{ + assert(member_requires_oc().foo() == 123); + assert(member_requires_oc().foo() == 'a'); +} diff --git a/tick/requires.h b/tick/requires.h index 7604bc4..a1a6507 100644 --- a/tick/requires.h +++ b/tick/requires.h @@ -53,9 +53,11 @@ trait(Ts&&...) noexcept #define TICK_CLASS_REQUIRES(...) typename std::enable_if<(__VA_ARGS__)>::type -#define TICK_REQUIRES(...) bool TickPrivateBool ## __LINE__=true, typename std::enable_if<(TickPrivateBool##__LINE__ && __VA_ARGS__), int>::type = 0 +#define TICK_REQUIRES(...) bool TickPrivateBool ## __LINE__=true, typename std::enable_if<(TickPrivateBool##__LINE__ && __VA_ARGS__), int>::type = 0 +#define TICK_REQUIRES_OC(...) bool TickPrivateBool ## __LINE__, typename std::enable_if<(TickPrivateBool##__LINE__ && __VA_ARGS__), int>::type -#define TICK_MEMBER_REQUIRES(...) template +#define TICK_MEMBER_REQUIRES(...) template +#define TICK_MEMBER_REQUIRES_OC(...) template #define TICK_PARAM_REQUIRES(...) \ typename std::enable_if< \ @@ -63,4 +65,4 @@ typename std::enable_if< \ typename tick::detail::private_enum<__LINE__>::type \ >::type = tick::detail::private_enum<__LINE__>::type::na -#endif \ No newline at end of file +#endif