// This file is distributed under the BSD License. // See "license.txt" for details. // Copyright 2009-2012, Jonathan Turner (jonathan@emptycrate.com) // Copyright 2009-2018, 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 constexpr T *get_pointer(T *t) noexcept { return t; } template T *get_pointer(const std::reference_wrapper &t) noexcept { return &t.get(); } template constexpr auto bind_first(Ret (*f)(P1, Param...), O &&o) { return [f, o = std::forward(o)](Param... param) -> Ret { return f(o, std::forward(param)...); }; } template constexpr auto bind_first(Ret (Class::*f)(Param...), O &&o) { return [f, o = std::forward(o)](Param... param) -> Ret { return (get_pointer(o)->*f)(std::forward(param)...); }; } template constexpr auto bind_first(Ret (Class::*f)(Param...) const, O &&o) { return [f, o = std::forward(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 = std::forward(o)](Param... param) -> Ret { return f(o, std::forward(param)...); }; } template constexpr auto bind_first(const F &fo, O &&o, Ret (Class::*f)(P1, Param...) const) { return [fo, o = std::forward(o), f](Param... param) -> Ret { return (fo.*f)(o, std::forward(param)...); }; } template constexpr auto bind_first(const F &f, O &&o) { return bind_first(f, std::forward(o), &F::operator()); } } // namespace detail } // namespace chaiscript #endif