find out the type of auto

前端 未结 3 1022
无人及你
无人及你 2020-12-06 15:44

I am playing with generic lambda in C++1y and I often confused by don\'t know what is the type of auto variable/parameter. Is any good way to find it out?

3条回答
  •  既然无缘
    2020-12-06 16:29

    Use GCC’s __cxa_demangle function:

    std::string demangled(std::string const& sym) {
        std::unique_ptr
            name{abi::__cxa_demangle(sym.c_str(), nullptr, nullptr, nullptr), std::free};
        return {name.get()};
    }
    
    auto f = [](auto && a, auto b) {
        std::cout << demangled(typeid(decltype(a)).name()) << '\n';
        std::cout << demangled(typeid(decltype(b)).name()) << '\n';
    };
    

提交回复
热议问题