static if in plain c++?

后端 未结 4 1194
轻奢々
轻奢々 2021-02-13 20:13

Problem in short:
How could one implement static if functionality, proposed in c++11, in plain c++ ?

History and original prob

4条回答
  •  既然无缘
    2021-02-13 20:51

    std::string a("hello world");
    // bool a = true;
    if(std::is_same::value) {
        std::string &la = *(std::string*)&a;
        std::cout << "std::string " << la.c_str() << std::endl;
    } else {
        bool &la = *(bool*)&a;
        std::cout << "other type" << std::endl;
    }
    

提交回复
热议问题