locked
tuple and 0 values RRS feed

  • Question

  • hello.
    I have this code
    [code]

    std::tr1::tuple<float,float,float,float>tCol(0.0f, 0.0f, 0.0f, 0.0f);
           
    if(Mat1.m_pfColorFront)
    std::tr1::tuple<float,float,float,float>tCol(Mat1.m_pfColorFront[0], Mat1.m_pfColorFront[1], Mat1.m_pfColorFront[2], Mat1.m_pfColorFront[3]);
    [/code]
    I wish mantain the 0 values of the tuple tCol if Mat1.m_pfColorFront is 0(NULL) and set the values of the tuple(tCol) if there are values in Mat1.m_pfColorFront.

    how?

    Thanks
    Wednesday, June 8, 2011 3:12 PM

Answers

  • You can do it like this:

    std::tr1::tuple<float,float,float,float>tCol(0.0f, 0.0f, 0.0f, 0.0f);
    if (Mat1.m_pfColorFront)
    {
    	std::tr1::get<0>(tCol) = Mat1.m_pfColorFront[0];
    	std::tr1::get<1>(tCol) = Mat1.m_pfColorFront[1];
    	std::tr1::get<2>(tCol) = Mat1.m_pfColorFront[2];
    	std::tr1::get<3>(tCol) = Mat1.m_pfColorFront[3];
    }
    

    Or like this:

    std::tr1::tuple<float,float,float,float>tCol(0.0f, 0.0f, 0.0f, 0.0f);
    if (Mat1.m_pfColorFront)
    {
    	tCol = make_tuple(Mat1.m_pfColorFront[0], Mat1.m_pfColorFront[1], Mat1.m_pfColorFront[2], Mat1.m_pfColorFront[3]);
    }
    
    

    - Shoaib.

    • Proposed as answer by ildjarn Wednesday, June 8, 2011 7:47 PM
    • Marked as answer by Rob Pan Thursday, June 16, 2011 3:02 AM
    Wednesday, June 8, 2011 5:39 PM