C++11 pattern for factory function returning tuple

前端 未结 4 667
感动是毒
感动是毒 2020-12-30 07:18

In my project I have some functions like

std::tuple LoadWavefront(std::string filename);

That I can use lik

4条回答
  •  醉梦人生
    2020-12-30 08:01

    You could use boost::optional:

    boost::optional teapotVAO;
    boost::optional teapotMesh;
    boost::optional teapotShader;
    std::tie(teapotVAO, teapotMesh, teapotShader)
        = LoadWavefront("assets/teapot.obj");
    

    Of course you'd have to change the way you access these values to always do *teapotVAO, but at least the compiler will let you know if you mess up any of the access.

提交回复
热议问题