相关疑难解决方法(0)

C++中的lambdas重载以及clang和gcc之间的差异

我正在玩一个用C++重载lambdas的技巧.特别:

// For std::function
#include <functional>

// For std::string
#include <string>

// For std::cout
#include <iostream>

template <class... F>
struct overload : F... {
    overload(F... f) : F(f)... {}
};      

template <class... F>
auto make_overload(F... f) {
    return overload<F...>(f...);
}

int main() {

    std::function <int(int,int)> f = [](int x,int y) {
        return x+y;
    };
    std::function <double(double,double)> g = [](double x,double y) {
        return x+y;
    };
    std::function <std::string(std::string,std::string)> h = [](std::string x,std::string y) {
        return x+y;
    };

    auto fgh = make_overload(f,g,h); …
Run Code Online (Sandbox Code Playgroud)

c++ gcc clang overload-resolution c++11

26
推荐指数
2
解决办法
1772
查看次数

标签 统计

c++ ×1

c++11 ×1

clang ×1

gcc ×1

overload-resolution ×1