Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove problematic templated overloads on callback-based functions #2395

Closed
wants to merge 1 commit into from

Commits on Aug 8, 2016

  1. Removed problematic templated overloads on callback-based functions

    Before this commit, the following pattern was suggested as a shortcut
    for writing callback-based functions overloaded based on arguments:
    
        template <typename T, typename M>
        void attach(T *obj, M method) {
            attach(Callback<void()>(obj, method);
        }
    
    Unfortunately, C++ did not fair well with this level of type-inference.
    
    The initial problems were with variable-arity function. The M type would
    happily consume arguments during overload-resolution, only to fail during
    template-expansion. Removed from problematic functions, this bug was
    unfortunately easy to reintroduce (for example in the RtosTimer) since
    it is undectable without forcing the template to expand.
    
    The latest problem is occuring during type-deduction of overloaded
    function pointers. The extra level of indirection with the templated-
    method parameter caused type-deduction to stop early, erroring with
    an ambiguity error. Even more unfortunate, this error is inconsistent,
    since some functions were unable to adopt the template-method pattern
    for the variable-arity issue mentioned earlier.
    
    For example:
    
        class Thing {
            void doit(int timeout);
            void doit();
        };
    
        Thing t;
    
        serial.attach(&t, &Thing::doit); // perfectly fine
        timer.attach(&t, &Thing::doit);  // ambiguity compile error
    
    After running into these issues with this design pattern, the best path
    forward seems to be to simply remove the templated-method overloads.
    These have been replaced by the two explicit overloads for the existing
    callback arguments.
    geky committed Aug 8, 2016
    Configuration menu
    Copy the full SHA
    702e9f3 View commit details
    Browse the repository at this point in the history