// This file is distributed under the BSD License. // See "license.txt" for details. // Copyright 2009-2012, Jonathan Turner (jonathan@emptycrate.com) // Copyright 2009-2017, Jason Turner (jason@emptycrate.com) // http://www.chaiscript.com // This is an open source non-commercial project. Dear PVS-Studio, please check it. // PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com #ifndef CHAISCRIPT_BIND_FIRST_HPP_ #define CHAISCRIPT_BIND_FIRST_HPP_ #include namespace chaiscript { namespace detail { template T* get_pointer(T *t) { return t; } template T* get_pointer(const std::reference_wrapper &t) { return &t.get(); } template auto bind_first(Ret (*f)(P1, Param...), O&& o) { return [f, o](Param...param) -> Ret { return f(std::forward(o), std::forward(param)...); }; } template auto bind_first(Ret (Class::*f)(Param...), O&& o) { return [f, o](Param...param) -> Ret { return (get_pointer(o)->*f)(std::forward(param)...); }; } template auto bind_first(Ret (Class::*f)(Param...) const, O&& o) { return [f, o](Param...param) -> Ret { return (get_pointer(o)->*f)(std::forward(param)...); }; } template auto bind_first(const std::function &f, O&& o) { return [f, o](Param...param) -> Ret { return f(o, std::forward(param)...); }; } template auto bind_first(const F &fo, O&& o, Ret (Class::*f)(P1, Param...) const) { return [fo, o, f](Param ...param) -> Ret { return (fo.*f)(o, std::forward(param)...); }; } template auto bind_first(const F &f, O&& o) { return bind_first(f, std::forward(o), &F::operator()); } } } #endif