mirror of
https://github.com/ChaiScript/ChaiScript.git
synced 2026-02-06 09:49:56 +08:00
constexpr bind_first
This commit is contained in:
parent
535c0344b7
commit
b51b52dea9
@ -82,7 +82,7 @@ namespace chaiscript {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
// construct/copy/destruct
|
// construct/copy/destruct
|
||||||
Any() noexcept = default;
|
constexpr Any() noexcept = default;
|
||||||
Any(Any &&) = default;
|
Any(Any &&) = default;
|
||||||
Any &operator=(Any &&t_any) = default;
|
Any &operator=(Any &&t_any) = default;
|
||||||
|
|
||||||
|
|||||||
@ -31,25 +31,25 @@ namespace chaiscript
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename O, typename Ret, typename P1, typename ... Param>
|
template<typename O, typename Ret, typename P1, typename ... Param>
|
||||||
auto bind_first(Ret (*f)(P1, Param...), O&& o)
|
constexpr auto bind_first(Ret (*f)(P1, Param...), O&& o)
|
||||||
{
|
{
|
||||||
return [f, o](Param...param) -> Ret {
|
return [f, o = std::forward<O>(o)](Param...param) -> Ret {
|
||||||
return f(std::forward<O>(o), std::forward<Param>(param)...);
|
return f(o, std::forward<Param>(param)...);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename O, typename Ret, typename Class, typename ... Param>
|
template<typename O, typename Ret, typename Class, typename ... Param>
|
||||||
auto bind_first(Ret (Class::*f)(Param...), O&& o)
|
constexpr auto bind_first(Ret (Class::*f)(Param...), O&& o)
|
||||||
{
|
{
|
||||||
return [f, o](Param...param) -> Ret {
|
return [f, o = std::forward<O>(o)](Param...param) -> Ret {
|
||||||
return (get_pointer(o)->*f)(std::forward<Param>(param)...);
|
return (get_pointer(o)->*f)(std::forward<Param>(param)...);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename O, typename Ret, typename Class, typename ... Param>
|
template<typename O, typename Ret, typename Class, typename ... Param>
|
||||||
auto bind_first(Ret (Class::*f)(Param...) const, O&& o)
|
constexpr auto bind_first(Ret (Class::*f)(Param...) const, O&& o)
|
||||||
{
|
{
|
||||||
return [f, o](Param...param) -> Ret {
|
return [f, o = std::forward<O>(o)](Param...param) -> Ret {
|
||||||
return (get_pointer(o)->*f)(std::forward<Param>(param)...);
|
return (get_pointer(o)->*f)(std::forward<Param>(param)...);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -58,22 +58,22 @@ namespace chaiscript
|
|||||||
template<typename O, typename Ret, typename P1, typename ... Param>
|
template<typename O, typename Ret, typename P1, typename ... Param>
|
||||||
auto bind_first(const std::function<Ret (P1, Param...)> &f, O&& o)
|
auto bind_first(const std::function<Ret (P1, Param...)> &f, O&& o)
|
||||||
{
|
{
|
||||||
return [f, o](Param...param) -> Ret {
|
return [f, o = std::forward<O>(o)](Param...param) -> Ret {
|
||||||
return f(o, std::forward<Param>(param)...);
|
return f(o, std::forward<Param>(param)...);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename F, typename O, typename Ret, typename Class, typename P1, typename ... Param>
|
template<typename F, typename O, typename Ret, typename Class, typename P1, typename ... Param>
|
||||||
auto bind_first(const F &fo, O&& o, Ret (Class::*f)(P1, Param...) const)
|
constexpr auto bind_first(const F &fo, O&& o, Ret (Class::*f)(P1, Param...) const)
|
||||||
{
|
{
|
||||||
return [fo, o, f](Param ...param) -> Ret {
|
return [fo, o = std::forward<O>(o), f](Param ...param) -> Ret {
|
||||||
return (fo.*f)(o, std::forward<Param>(param)...);
|
return (fo.*f)(o, std::forward<Param>(param)...);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename F, typename O>
|
template<typename F, typename O>
|
||||||
auto bind_first(const F &f, O&& o)
|
constexpr auto bind_first(const F &f, O&& o)
|
||||||
{
|
{
|
||||||
return bind_first(f, std::forward<O>(o), &F::operator());
|
return bind_first(f, std::forward<O>(o), &F::operator());
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user