C++11 pattern for factory function returning tuple

前端 未结 4 688
感动是毒
感动是毒 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:05

    How do I get around that without having to std::get<> each item? Is there an elegant way to do this?

    Return by value, instead of returning by "values" (which is what this std::tuple allows you to do).

    API changes:

    class Wavefront
    {
    public:
        Wavefront(VAO v, Mesh m, ShaderProgram sp); // use whatever construction
                                                    // suits you here; you will
                                                    // only use it internally
                                                    // in the load function, anyway
        const VAO& vao() const;
        const Mesh& mesh() const;
        const ShaderProgram& shader() const;
    };
    
    Wavefront LoadWavefront(std::string filename);
    

提交回复
热议问题