Git Product home page Git Product logo

delegates's People

Contributors

marcmo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

delegates's Issues

What syntax to use member function/method with service delegate?

Following on from test and example code, s.registerDelegate(d) will fail if d is not a free function.

void test() {
//  Free function works fine
//  auto d = make_delegate(&myFreeFunction);

//  But member methods will create an error
    A a;
    auto d = make_delegate(&A::simple, a);

    Service s;
    s.registerDelegate(d);
//  Error (active)  a reference of type "ServiceDelegate &" (not
//  const-qualified) cannot be initialized with a value of type
//  "dlgt::delegate<void (A::*)()>"

//  Error   C2664   'void Service::registerDelegate(ServiceDelegate &)': cannot
//  convert argument 1 from 'dlgt::delegate<void (__cdecl A::* )(void)>' to
//  'ServiceDelegate &'

    s.notifyDelegate();
}

Duplicate code

The code for const function delegates causes a compilation error in VC++ 2013:

template<typename return_type, typename... params>
class Delegate<return_type(params...) const>
        : public BaseDelegate<return_type, params...>
{
    typedef BaseDelegate<return_type, params...> Base;
public:
    Delegate(void* callee, typename Base::Pointer2Function function)
        : Base(callee, function)
    { }
};

error C2953: 'Delegate<return_type(params...),>' : class template has already been defined.

Which also causes an error further down in the file:

    template<return_type(T::*Func)(params...) const>
    inline static Delegate<return_type(params...) const> CreateC(T* o)
    {
        return Delegate<return_type(params...) const>(o, &DelegateFactory::MethodCallerC<Func>);
    }

'abstract declarator' : modifiers not allowed on nonmember functions

Here is what is needed for it to fully build:

#ifndef _MSC_VER
template<typename return_type, typename... params>
class Delegate<return_type(params...) const>
        : public BaseDelegate<return_type, params...>
{
    typedef BaseDelegate<return_type, params...> Base;
public:
    Delegate(void* callee, typename Base::Pointer2Function function)
        : Base(callee, function)
    { }
};
#endif

...

#ifdef _MSC_VER
    template<return_type(T::*Func)(params...) const>
    inline static Delegate<return_type(params...)/* const*/> CreateC(T* o)
    {
        return Delegate<return_type(params...)/* const*/>(o, &DelegateFactory::MethodCallerC<Func>);
    }
#else
    template<return_type(T::*Func)(params...) const>
    inline static Delegate<return_type(params...) const> CreateC(T* o)
    {
        return Delegate<return_type(params...) const>(o, &DelegateFactory::MethodCallerC<Func>);
    }
#endif

Were you able to get this to build in Visual C++?

Thanks.

Using lambdas

Would it be possible to use these delegates with lambdas? It does not seem to have support for this at the moment but I am hoping that it won't be to difficult to implement?

New system requires class as part of the type

I am not sure if this was intentional but the new implementation requires that the type of the class be part of the template type for member functions. This was not the case with the previous implementation. In other words, the type of a delegate now restricts it for use on a certain type.

I would assume that this is not part of the plan because if this is allowable then the concept of this delegate system does not make it any more useful than standard C++ member function pointers. Or am I missing something?

Windows?

Does this work on Windows? Has it been tested with MSVC++?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.