GameApi 28
Library used by GameApi Builder tool
Loading...
Searching...
No Matches
bind_first.hpp
Go to the documentation of this file.
1// This file is distributed under the BSD License.
2// See "license.txt" for details.
3// Copyright 2009-2012, Jonathan Turner (jonathan@emptycrate.com)
4// Copyright 2009-2017, Jason Turner (jason@emptycrate.com)
5// http://www.chaiscript.com
6
7// This is an open source non-commercial project. Dear PVS-Studio, please check it.
8// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
9
10
11#ifndef CHAISCRIPT_BIND_FIRST_HPP_
12#define CHAISCRIPT_BIND_FIRST_HPP_
13
14#include <functional>
15
16namespace chaiscript
17{
18 namespace detail
19 {
20
21 template<typename T>
23 {
24 return t;
25 }
26
27 template<typename T>
28 T* get_pointer(const std::reference_wrapper<T> &t)
29 {
30 return &t.get();
31 }
32
33 template<typename O, typename Ret, typename P1, typename ... Param>
34 auto bind_first(Ret (*f)(P1, Param...), O&& o)
35 {
36 return [f, o](Param...param) -> Ret {
37 return f(std::forward<O>(o), std::forward<Param>(param)...);
38 };
39 }
40
41 template<typename O, typename Ret, typename Class, typename ... Param>
42 auto bind_first(Ret (Class::*f)(Param...), O&& o)
43 {
44 return [f, o](Param...param) -> Ret {
45 return (get_pointer(o)->*f)(std::forward<Param>(param)...);
46 };
47 }
48
49 template<typename O, typename Ret, typename Class, typename ... Param>
50 auto bind_first(Ret (Class::*f)(Param...) const, O&& o)
51 {
52 return [f, o](Param...param) -> Ret {
53 return (get_pointer(o)->*f)(std::forward<Param>(param)...);
54 };
55
56 }
57
58 template<typename O, typename Ret, typename P1, typename ... Param>
59 auto bind_first(const std::function<Ret (P1, Param...)> &f, O&& o)
60 {
61 return [f, o](Param...param) -> Ret {
62 return f(o, std::forward<Param>(param)...);
63 };
64 }
65
66 template<typename F, typename O, typename Ret, typename Class, typename P1, typename ... Param>
67 auto bind_first(const F &fo, O&& o, Ret (Class::*f)(P1, Param...) const)
68 {
69 return [fo, o, f](Param ...param) -> Ret {
70 return (fo.*f)(o, std::forward<Param>(param)...);
71 };
72
73 }
74
75 template<typename F, typename O>
76 auto bind_first(const F &f, O&& o)
77 {
78 return bind_first(f, std::forward<O>(o), &F::operator());
79 }
80
81 }
82}
83
84
85#endif
Classes and functions reserved for internal use. Items in this namespace are not supported.
auto bind_first(Ret(*f)(P1, Param...), O &&o)
Definition bind_first.hpp:34
T * get_pointer(T *t)
Definition bind_first.hpp:22
Namespace chaiscript contains every API call that the average user will be concerned with.
double f(const std::string &, double, bool) noexcept
Definition profile_cpp_calls_2.cpp:4
Definition parser.cc:9
Definition GameApi.h:32
Definition GameApi.h:22
Definition GameApi_bm.cc:4579
Definition GameApi.h:42