Passing non-const references to rvalues in C++

前端 未结 7 988
长发绾君心
长发绾君心 2020-12-09 18:28

In the following line of code:

bootrec_reset(File(path, size, off), blksize);

Calling a function with prototype:

static void b         


        
相关标签:
7条回答
  • 2020-12-09 19:16

    Does the upcoming C++0x standard change this in anyway, or is there something the new standard gives me that is more appropriate here, for example all that jibberish about rvalue references?

    Yes. Since every name is an lvalue, it is almost trivial to treat any expression as if it was an lvalue:

    template <typename T>
    T& as_lvalue(T&& x)
    {
        return x;
    }
    
    // ...
    
    bootrec_reset(as_lvalue(File(path, size, off)), blksize);
    
    0 讨论(0)
提交回复
热议问题