I have a foo() function that is provided in the context of a library. The library defines several overloads for this function, for example:
char foo(float x, int y); short foo(double x, char y);
(I made the above arguments / result types up. The conclusion is that there is no common connection between the argument types and the corresponding return type of the overload type.)
The idea is that the library user can add overloads for foo() for their own custom types as needed. Functional overload is very easy.
I would like to make the foo() family of functions applicable in the Boost.Proto expression. To do this, I think I would need to wrap this in a function object using the template call operator:
struct foo_wrap { template <typename A1, typename A2> result_type operator()(A1 a1, A2 a2) { return foo(a1, a2); } };
The problem is how to determine result_type . I understand that this would be easy with C ++ 11 and decltype() and return types of return functions, but I am looking for a C ++ 03 solution. Therefore, foo_wrap should be a TR1 style function object. I need to find a way to define result_type as a function of compilation time of argument types A1 and A2 . This is necessary not only for the operator() return type, but also for the TR1 protocol result_of . In short:
- Is there a metaprogramming method that, given the name of the function and the set of argument types, will give a function of the corresponding return type?
- Alternatively, is there another way that I can use to transfer multiple function overloads using a universal function object?
source share