Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TICK_MEMBER_REQUIRES_OC for outside-class-definitions of members #11

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

ajneu
Copy link

@ajneu ajneu commented Jan 22, 2016

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;
}

@pfultz2
Copy link
Owner

pfultz2 commented Jan 22, 2016

Thanks, are you able to add some tests?

@ajneu
Copy link
Author

ajneu commented Jan 26, 2016

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).

@pfultz2
Copy link
Owner

pfultz2 commented Jan 31, 2016

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants