Tick icon indicating copy to clipboard operation
Tick copied to clipboard

TICK_MEMBER_REQUIRES_OC for outside-class-definitions of members

Open ajneu opened this issue 8 years ago • 3 comments

Nice Library.

This pullrequest adds the possibility to use TICK_MEMBER_REQUIRES (_OC); also for members that are defined outside of the class.

Example.

#include "tick/requires.h"
#include "tick/builder.h"
#include <iostream>

TICK_TRAIT(is_incrementable)
{
    template<class T>
        auto require(T&& x) -> valid<
            decltype(x++),
            decltype(++x)
            >;
};

template<class T>
struct foo
{
    T x = 0; // C++11 in-member initialization

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

template<class T>
TICK_MEMBER_REQUIRES_OC(is_incrementable<T>())  // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
void foo<T>::up()
{
    x++;
}

int main()
{
    foo<int> f;
    std::cout << f.x << std::endl;
    f.up();
    std::cout << f.x << std::endl;
    return 0;
}

ajneu avatar Jan 22 '16 12:01 ajneu

Thanks, are you able to add some tests?

pfultz2 avatar Jan 22 '16 17:01 pfultz2

Ok, I've added a test which uses normal assert to check the actual invocation of a member function, whose code is defined oc (outside the class).

ajneu avatar Jan 26 '16 20:01 ajneu

Thanks. I've just added support for Visual Studio. However, this won't work for msvc, since msvc needs to use the __LINE__ macro. I think I'll try to merge this in, but it will only be supported on C++ compilers. For portability, its best to define it inline.

pfultz2 avatar Jan 31 '16 16:01 pfultz2