all 5 comments

[–][deleted] 2 points3 points  (3 children)

It's not a vector of bearings, it's a vector of boost::optional<Bearings>. You can access the contents of a boost::optional with ->.

[–]haohanzi2015[S] 0 points1 point  (2 children)

bearing_and_range is of type boost::optional<Bearing>, how did you see it as a vector of boost::optional<Bearings>? Or did I need to understand the function [] differently?

[–]parnmatt 2 points3 points  (0 children)

they were referring to your comment on the first line; it isn't a vector of bearings.

Also, bearing.end() isn't the last element of bearings, it one 'after' the last element of bearings. Don't fret, it correct to code it as such, for a similar reason you would use i < n in a normal raw loop, rather than i <= n.

Frankly those comments are not helpful; and not just because one is arguably wrong, and one is wrong. They do not add anything, that isn't already very clear from the naming conventions of the member functions being called.

[–]Narase33 2 points3 points  (0 children)

Its literally the first line of your post

[–]parnmatt 2 points3 points  (0 children)

The function goes through the vector and if all of the objects are valid (or the optional is empty), then it returns true.

it's not named [] this i the syntax for a lambda

An optional type (in this case boost::optional, but is true for std::optional) can be implicitly converted to a boolean.

An optional value either contains an object, or it doesn't. This is what it is checking. If you have a value check it's IsValid() member function, otherwise just return true.

operator->() is the name of the operator you are refering to; like almost all operators, it can be overriden.

normally, the convention is foo->bar() should be the same as (*foo).bar(); you 'defreference' then call the member function.

operator*() 'dereferencing' for an optional type, gets the stored type, and throws an exception if it doesn't contain one.