marcmo / delegates Goto Github PK
View Code? Open in Web Editor NEWsmall delegate implementation
Home Page: http://marcmo.github.io/delegates/
License: MIT License
small delegate implementation
Home Page: http://marcmo.github.io/delegates/
License: MIT License
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();
}
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?
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?
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.
Does this work on Windows? Has it been tested with MSVC++?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.