Drake
makeFunction.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <functional>
4 
5 namespace Drake {
13 // plain function pointers
14 template <typename... Args, typename ReturnType>
15 auto make_function(ReturnType (*p)(Args...))
16  -> std::function<ReturnType(Args...)> {
17  return {p};
18 }
19 
20 // nonconst member function pointers
21 // note the ClassType& as one of the arguments, which was erroneously omitted in
22 // the SO answer above
23 // also note the conversion to mem_fn, needed to work around an issue with MSVC
24 // 2013
25 template <typename... Args, typename ReturnType, typename ClassType>
26 auto make_function(ReturnType (ClassType::*p)(Args...))
27  -> std::function<ReturnType(ClassType&, Args...)> {
28  return {std::mem_fn(p)};
29 }
30 
31 // const member function pointers
32 // note the const ClassType& as one of the arguments, which was erroneously
33 // omitted in the SO answer above
34 // also note the conversion to mem_fn, needed to work around an issue with MSVC
35 // 2013
36 template <typename... Args, typename ReturnType, typename ClassType>
37 auto make_function(ReturnType (ClassType::*p)(Args...) const)
38  -> std::function<ReturnType(const ClassType&, Args...)> {
39  return {std::mem_fn(p)};
40 }
41 }
NOTE: The contents of this class are for the most part direct ports of drake/systems/plants//inverseK...
Definition: Function.h:14
auto make_function(ReturnType(*p)(Args...)) -> std::function< ReturnType(Args...)>
make_function Note that a completely general make_function implementation is not possible due to ambi...
Definition: makeFunction.h:15