Open pan- opened 8 years ago
ARM Internal Ref: IOTSFW-1087
This all looks really good to me. I'd be happy to see these optimizations added!
I'm not sure what the right semantics are for comparing function pointers. I'm not convinced that it's necessarily wrong to compare a function pointer to a function pointer with bound arguments and discover they are equal if they both point to the same underlying function pointer.
On the other hand, this is not likely to be the behaviour that a developer expects. It might be reasonable to argue that a comparison of FunctionPointer to FunctionPointerBind should always fail.
FunctionPointer and FunctionPointerBind should handle function objects
I need this support in order to use lambda. Because of -fno-rtii
option in yotta_targets/mbed-gcc/CMake/toolchain.make
, I don't have any way to convert std::function
, which is a lambda function type, to c-style function pointer which FunctionPointers' constructors require.
Of course, -fno-rtii
makes sense for mbed OS apps so I think FunctionPointer/FunctionPointerBind should support the feature.
Several improvements can be made on FunctionPointer and FunctionPointerBind classes. While all of them may not be applicable, I will list everything that is on my mind for this subject.
Unique name for all FunctionPointerX classes:
Today, the FunctionPointer class add the arity of the function to the class suffix name (FunctionPointer0, FunctionPointer1, ..., FunctionPointerN). It is possible to to use a single class name across all FunctionPointer if the "function signature type" is used instead of a list of Return + Arguments type list in template parameters.
This little change might just look like a cosmetic one, it's not:
Clarification of FunctionPointer semantic
The semantic of FunctionPointer, FunctionPointerBind and FunctionPointer is not clear. Is it a polymorphic type ? Is it a value type ?
If it is a value type :
If it is a true polymorphic type:
FunctionPointer and FunctionPointerBind should handle function objects
At the moment, it is not possible to handle function object values with FunctionPointer. This addition will be required to support c++11 lambda.
FunctionPointer does not handle smart pointers
It would be nice if FunctionPointer can handle smart pointers (for RAII purposes).
FunctionPointer and FunctionPointerBind takes too much space:
It is possible to reduce the size of FunctionPointer and FunctionPointerBind by optimizing the pointer to member function storage.
It is also possible to reduce the size of bound arguments if we use a well tuned generic Tuple type instead of a POD as bound arguments storage. A well optimized Tuple type can reorganized its member at compile time and reduce padding.