
C++ value category cheat-sheet [pdf] - Jeaye
https://github.com/jeaye/value-category-cheatsheet/blob/master/value-category-cheatsheet.pdf
======
jewbacca
Softer entry to the whole concept of lvalues/rvalues in general:

[http://eli.thegreenplace.net/2011/12/15/understanding-
lvalue...](http://eli.thegreenplace.net/2011/12/15/understanding-lvalues-and-
rvalues-in-c-and-c)

~~~
mpweiher
And of course there's Strachey's _Fundamental Concepts in Programming
Languages_ (1967), which introduced the LValue/RValue distinction. It is very
readable and relevant today.

[http://www.cs.cmu.edu/~crary/819-f09/Strachey67.pdf](http://www.cs.cmu.edu/~crary/819-f09/Strachey67.pdf)

------
partycoder
It is great, but regarding the format I would suggest some options to PDF:

a) markdown with embedded graphviz.

ex: [https://github.com/TLmaK0/gravizo](https://github.com/TLmaK0/gravizo)

b) a jupyter notebook (which also uses markdown blocks). jupyter can embed
C++, so you can have interactive blocks that you can evaluate and play with.

ex:
[https://github.com/minrk/clingkernel/blob/master/cling.ipynb](https://github.com/minrk/clingkernel/blob/master/cling.ipynb)

Both seem more performant than in-browser PDF rendering.

~~~
Jeaye
I looked for a number of options and I didn't find anything which could
provide me with automatic syntax highlighting, non-html layouts, and quick
iteration. That doesn't mean that such a thing doesn't exist!

Thanks for the suggestions.

~~~
partycoder
Jupyter notebooks are probably what you are looking for. I highly recommend
them. Embedded REPL makes iteration very fast and results can be shared
directly through a URL, exported to various formats or shared in websites that
support it such as github.

------
smitherfield
Question: it _is_ ok to initialize a string_view from a string literal, right?

e.g.

    
    
      std::string_view sv{ "lvalue" };
    

or

    
    
      auto sv{ "lvalue"sv };

~~~
thecpphorse
Yes, but never use {} initialization with auto.

~~~
clishem
Never give advice without telling why, because it's very likely that people
will forget it if they don't understand your advice.

~~~
thecpphorse
Ok.

    
    
      auto i{42}; // std::initializer_list<int>

~~~
hellofunk
No longer applies with c++17

~~~
slavik81
More info about this:
[http://stackoverflow.com/q/25612262/331041](http://stackoverflow.com/q/25612262/331041)

------
valarauca1
I think the biggest issue in C++ is that you don't have to understand this
whole mess to be productive in it. This is also perhaps its greatest strength.
Where you have Rust which won't even compile a basic toy program without
demonstrating a full understanding of its Ownership model.

~~~
jjnoakes
It isn't a strength to allow ill-defined programs to silently corrupt your
process.

If you don't understand what you are writing, either the compiler (rust-like)
or the runtime (script-like) should complain.

C++ usually does neither. I think that's undesirable. Why it does neither
makes sense, but I wouldn't call it a strength.

------
7ewis
Are there cheat sheets like this for other languages too?

~~~
SolarNet
Most of them aren't as insane.

------
fytch
Reddit discussion:
[https://www.reddit.com/r/cpp/comments/5zzurr/c_value_categor...](https://www.reddit.com/r/cpp/comments/5zzurr/c_value_category_cheatsheet/)

~~~
Jare
I'd love it if someone could shed some light on my question here:

[https://www.reddit.com/r/cpp/comments/5zzurr/c_value_categor...](https://www.reddit.com/r/cpp/comments/5zzurr/c_value_category_cheatsheet/df2xvbj/)

    
    
        int const &f(int const &a) { return a; }
        int r = f(3);
    

Is the value of r implementation-defined according to the standard?

~~~
beached_whale
This might answer that [https://herbsutter.com/2008/01/01/gotw-88-a-candidate-
for-th...](https://herbsutter.com/2008/01/01/gotw-88-a-candidate-for-the-most-
important-const/)

I think this is similar to the std::max/std::min stuff

~~~
Jare
No, that post refers to the lifetime of temporaries held by local reference
variables. My question is about temporaries created to pass reference
parameters to a function. Is the lifetime of that temporary the BODY of the
function? The full expression that calls the function? The enclosing scope of
that full expression? (for the record, VS2017 does the latter)

------
jasode
A comment on the document's design: The low contrast of light gray text on
yellow background makes it difficult to read. Black text on white, or dark
gray text on white is perfectly acceptable.

Another drawback of colored backgrounds is that readers wanting to print out
the pdf will consume ink/toner to render the non-white background.

~~~
saagarjha
I'm pretty sure the author was trying to use the Solarized color scheme:
[http://ethanschoonover.com/solarized](http://ethanschoonover.com/solarized)

~~~
Jeaye
[https://github.com/jeaye/value-category-
cheatsheet/blob/mast...](https://github.com/jeaye/value-category-
cheatsheet/blob/master/src/value_categories/css.clj#L4)

You bet. :)

