|Related to : Const char* not assigning properly?|
|Universal member-function definition, instanceable from both 'const' & 'non-const' objects|
@dyp's answer by way of comment was good, but I would use a static
member function rather than a friend function: friend functions have
no access control.
template <typename T>
void DoForEachList(auto pFunc)
void DoForEachList(auto pFunc) const
|According to the spec, is const required with auto for const references?|
Yes, this behaviour is entirely standard-mandated:
[C++11: 220.127.116.11/5]: A program that uses auto in a context not
explicitly allowed in this section is ill-formed.
[C++11: 18.104.22.168/6]: Once the type of a declarator-id has been
determined according to 8.3, the type of the declared variable using
the declarator-id is determined from the type of its initializer using
the rules for template arg
|const vector implies const elements?|
Yes, const vector provides access to it's elemets as if they were
const (that is, gives you const references). In your second function
not the objects of type A are const, but pointers to them. A pointer
being const does not mean that the object the pointer is pointing to
is const. To declare pointer-to-const, use the type A const *.
|Should single-use values be inline, function-level const variables, or class-level static const variables?|
What do you prefer?
They're not all equivalent of course.
If you give them (named) namespace or global scope, they can get
external visibility, meaning you can define them in a separate TU and
even change their definition without recompiling (just linking). If
that TU is in a dynamic library that linking might be at runtime.
Also, function locals are usually not separately documented. However i
|Understanding Pointer to constant pointer to integer constant (const int * const * variable)|
But i was wondering why is this happening since pcpci is not a
No, but *(pcpci+1) is. It has type const int* const. Obviously you
can't assign anything to that.