这是indexloc提供的服务,不要输入任何密码
Skip to content

[inplace_function] Ambiguous overloads. #149

@p-groarke

Description

@p-groarke

Just hit an issue when overloading a function accepting inplace_function vs. std::function. The compiler (MSVC 2017, clang 7) cannot disambiguate by function arguments. Here is a repro example and a link to it on compiler explorer.

Not sure if there is something to be done about this, worth investigating though.

#include <cstdio>
#include <functional>
#include <sg14/inplace_function.h>

// Something to be done about this?

/**
 * Ambiguous
 */
void myfunc(stdext::inplace_function<void()>&& exec) {
    std::invoke(exec);
}
void myfunc(stdext::inplace_function<void(size_t)>&& exec) {
    std::invoke(exec, size_t(42));
}

/**
 * Not ambiguous
 */
void myfunc_std(std::function<void()>&& exec) {
    std::invoke(exec);
}
void myfunc_std(std::function<void(size_t)>&& exec) {
    std::invoke(exec, size_t(42));
}

int main(int, char**) {
    // ambiguous
    myfunc([](){
        printf("blee\n");
    });

    // ok
    myfunc_std([](){
        printf("blou\n");
    });

    return 0;
}

https://godbolt.org/z/38cCZz

Good day

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions