Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I'm pretty sure that this is because it would play havoc with rvalue references and any sort of <code>decltype</code>. Even though these features were not in C++03, they have been known to be coming.</p> <p>More importantly, I don't believe that any Standard function returns const rvalues, it's probably something that wasn't considered until after the Standard was published. In addition, const rvalues are generally not considered to be the Right Thing To Do™. Not all uses of non-const member functions are invalid, and returning const rvalues is blanketly preventing them.</p> <p>For example,</p> <pre><code>auto it = ++vec.begin(); </code></pre> <p>is perfectly valid, and indeed, valid semantics, if not exactly desirable. Consider my class that offers method chains.</p> <pre><code>class ILikeMethodChains { public: int i; ILikeMethodChains&amp; SetSomeInt(int param) { i = param; return *this; } }; ILikeMethodChains func() { ... } ILikeMethodChains var = func().SetSomeInt(1); </code></pre> <p>Should that be disallowed just because maybe, sometimes, we might call a function that doesn't make sense? No, of course not. Or how about "swaptimization"?</p> <pre><code>std::string func() { return "Hello World!"; } std::string s; func().swap(s); </code></pre> <p>This would be illegal if <code>func()</code> produced a const expression - but it's perfectly valid and indeed, assuming that <code>std::string</code>'s implementation does not allocate any memory in the default constructor, both fast and legible/readable.</p> <p>What you should realize is that the C++03 rvalue/lvalue rules frankly just don't make sense. They are, effectively, only part-baked, and the minimum required to disallow some blatant wrongs whilst allowing some possible rights. The C++0x rvalue rules are much saner and much more <em>complete</em>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload