mirror of
https://github.com/kotatogram/kotatogram-desktop
synced 2025-08-31 06:35:14 +00:00
First version of ShareBox done, cute animations.
Temporarily ShareBox is opened instead of ContactsBox, for testing.
This commit is contained in:
@@ -1275,8 +1275,8 @@ public:
|
||||
template <typename R, typename... Args>
|
||||
class NullFunctionImplementation : public FunctionImplementation<R, Args...> {
|
||||
public:
|
||||
virtual R call(Args... args) { return R(); }
|
||||
virtual void destroy() {}
|
||||
R call(Args... args) override { return R(); }
|
||||
void destroy() override {}
|
||||
static NullFunctionImplementation<R, Args...> SharedInstance;
|
||||
|
||||
};
|
||||
@@ -1325,7 +1325,7 @@ class WrappedFunction : public FunctionImplementation<R, Args...> {
|
||||
public:
|
||||
using Method = R(*)(Args... args);
|
||||
WrappedFunction(Method method) : _method(method) {}
|
||||
virtual R call(Args... args) { return (*_method)(args...); }
|
||||
R call(Args... args) override { return (*_method)(args...); }
|
||||
|
||||
private:
|
||||
Method _method;
|
||||
@@ -1341,7 +1341,7 @@ class ObjectFunction : public FunctionImplementation<R, Args...> {
|
||||
public:
|
||||
using Method = R(I::*)(Args... args);
|
||||
ObjectFunction(O *obj, Method method) : _obj(obj), _method(method) {}
|
||||
virtual R call(Args... args) { return (_obj->*_method)(args...); }
|
||||
R call(Args... args) override { return (_obj->*_method)(args...); }
|
||||
|
||||
private:
|
||||
O *_obj;
|
||||
|
@@ -372,3 +372,42 @@ public:
|
||||
};
|
||||
|
||||
} // namespace base
|
||||
|
||||
// While we still use Function<>
|
||||
|
||||
template <typename FunctionType>
|
||||
struct LambdaFunctionHelper;
|
||||
|
||||
template <typename Lambda, typename R, typename ...Args>
|
||||
struct LambdaFunctionHelper<R(Lambda::*)(Args...) const> {
|
||||
using FunctionType = Function<R, Args...>;
|
||||
using UniqueType = base::lambda_unique<R(Args...)>;
|
||||
};
|
||||
|
||||
template <typename FunctionType>
|
||||
using LambdaGetFunction = typename LambdaFunctionHelper<FunctionType>::FunctionType;
|
||||
|
||||
template <typename FunctionType>
|
||||
using LambdaGetUnique = typename LambdaFunctionHelper<FunctionType>::UniqueType;
|
||||
|
||||
template <typename R, typename ...Args>
|
||||
class LambdaFunctionImplementation : public FunctionImplementation<R, Args...> {
|
||||
public:
|
||||
LambdaFunctionImplementation(base::lambda_unique<R(Args...)> &&lambda) : _lambda(std_::move(lambda)) {
|
||||
}
|
||||
R call(Args... args) override { return _lambda(std_::forward<Args>(args)...); }
|
||||
|
||||
private:
|
||||
base::lambda_unique<R(Args...)> _lambda;
|
||||
|
||||
};
|
||||
|
||||
template <typename R, typename ...Args>
|
||||
inline Function<R, Args...> lambda_wrap_helper(base::lambda_unique<R(Args...)> &&lambda) {
|
||||
return Function<R, Args...>(new LambdaFunctionImplementation<R, Args...>(std_::move(lambda)));
|
||||
}
|
||||
|
||||
template <typename Lambda, typename = std_::enable_if_t<std_::is_rvalue_reference<Lambda&&>::value>>
|
||||
inline LambdaGetFunction<decltype(&Lambda::operator())> func(Lambda &&lambda) {
|
||||
return lambda_wrap_helper(LambdaGetUnique<decltype(&Lambda::operator())>(std_::move(lambda)));
|
||||
}
|
||||
|
Reference in New Issue
Block a user