The operation is &
+ variable_name, rather than &_
+ variable_name.
In this context, &
followed by a variable means passing the pointer of this variable as one of the function arguments. You will probably notice that in the code you pasted, the third very long argument of std::sort
is actually a lambda expression( a function ):
[] (const auto &_1st, const auto &_2st) {
return _1st->h_value + _1st->g_value < _2st->h_value + _2st->g_value
}
It corresponds to the third argument of sort
from according to HERE, and below is a short quote:
comp
Binary function that accepts two elements in the range as arguments, and returns a value convertible to bool. The value returned indicates whether the element passed as first argument is considered to go before the second in the specific strict weak ordering it defines.
The function shall not modify any of its arguments.
This can either be a function pointer or a function object.
So basically when you want to sort a type of variable with your specifically defined rule or c++ does not know how to compare the target you are trying to sort, you have to define a function tells c++ how to perform sorting.
For details, you may also want to take a look at THIS.
There are few reasons to pass variables as reference pointers instead of passing by value. In many cases you just do not wanted to create additional memory consumption and save time, passing by reference allows you access values without make a copy. For details, please refer to HERE