Skip to content

Commit

Permalink
TICK_MEMBER_REQUIRES_OC for outside-class-definitions of members
Browse files Browse the repository at this point in the history
  • Loading branch information
ajneu committed Jan 22, 2016
1 parent 3a70ee5 commit 7b53ee4
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 3 deletions.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<class T>
struct foo
{
T x;

TICK_MEMBER_REQUIRES(is_incrementable<T>())
void up();
};

template<class T>
TICK_MEMBER_REQUIRES_OC(is_incrementable<T>())
void foo<T>::up()
{
x++;
}
```
TICK_PARAM_REQUIRES
--------------------
Expand Down
19 changes: 19 additions & 0 deletions doc/src/requires.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<class T>
struct foo
{
T x;
TICK_MEMBER_REQUIRES(is_incrementable<T>())
void up();
};
template<class T>
TICK_MEMBER_REQUIRES_OC(is_incrementable<T>())
void foo<T>::up()
{
x++;
}
```

TICK_PARAM_REQUIRES
--------------------

Expand Down
8 changes: 5 additions & 3 deletions tick/requires.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,16 @@ 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<TICK_REQUIRES(__VA_ARGS__)>
#define TICK_MEMBER_REQUIRES(...) template<TICK_REQUIRES( __VA_ARGS__)>
#define TICK_MEMBER_REQUIRES_OC(...) template<TICK_REQUIRES_OC(__VA_ARGS__)>

#define TICK_PARAM_REQUIRES(...) \
typename std::enable_if< \
(tick::detail::param_extract<decltype(__VA_ARGS__)>::value), \
typename tick::detail::private_enum<__LINE__>::type \
>::type = tick::detail::private_enum<__LINE__>::type::na

#endif
#endif

0 comments on commit 7b53ee4

Please sign in to comment.