basics

Quick Q: Is (4 > y > 1) a valid statement in C++? How do you evaluate it if so?

Quick A: This is not a valid statement.

Recently on SO:

Is (4 > y > 1) a valid statement in C++? How do you evaluate it if so?

The statement (4 > y > 1) is parsed as this:

((4 > y) > 1)

The comparison operators < and > evaluate left-to-right.

The 4 > y returns either 0 or 1 depending on if it's true or not.

Then the result is compared to 1.

In this case, since 0 or 1 is never more than 1, the whole statement will always return false.

Quick Q: Confused about vectors

Quick A: Do not confuse mathematical concepts with C++ terminology.

Recently on SO:

Confused about vectors

You are getting confused because the mathematical concept of a vector can mean a "collection of data" and that is what you were taught int v[10] was. The actual name for that in C++ (and most other languages) is an "array" not a vector.

The libraries referred to in C++ Primer have a class called "vector" which is an implementation of an array. They are similar, but not the same.

I hope that clears that up a bit. You are probably confused because you were taught that int v[10] is a vector, but it is "not really" in C++. It's an array. Use that term to refer to it. If you ever refer to it as a vector, you will confuse others and yourself.

5 ways how unique_ptr enhances resource safety in your code -- Bartlomiej Filipek

Examples where unique_ptr shines:

5 ways how unique_ptr enhances resource safety in your code

by Bartlomiej Filipek

From the article:

While shared_ptr and weak_ptr are more complex, unique_ptr seems to be a perfect replacement for owning raw pointers. Not to mention is the fact that this pointer type is mostly a compile time “wrapper” and it cost almost nothing in the runtime.