I am unclear about the following.
First, this code compiles fine:
#include
typedef struct{
int x1,x2,x3,x4;
} ints;
typedef std
The requirement for value type T
for all STL containers, including std::vector
, is that T
is Assignable
- ISO C++03 23.1[lib.container.requirements]/4-5. Assignable
is defined as follows:
Expression
t = u
, wheret
is of typeT
, andu
is of type cvT
, is valid, its return type isT&
, and the post-condition is thatt
is equivalent tou
.
Arrays do not fulfill this requirement, because you cannot write:
int a[2], b[2];
a = b;
The reason why you cannot is because both a
and b
in the code snippet above decay to pointer-type rvalues according to the usual C++ rules for array-to-pointer decay described in 4.2[conv.array]. Naturally, an rvalue if not permitted on the left side of non-overloaded operator=
.