Proper behavior for std :: vector <T> :: value_type

After scratching my head with some errors in some code template that I used std::vector::value_type, I tracked it to the next one. Is this the correct behavior according to the standard, or is this a problem with the MSVC 2012 CTP?

typedef std::vector<int>::value_type       t1;
typedef std::vector<int const>::value_type t2;

static_assert(!std::is_same<t1, t2>::value, "hmmm");

The above statement fails.

+5
source share
3 answers

value_typeof std::vector<T>- T(§23.3.6.1).

The value is_sametakes into account the qualifiers cv (§20.9.6).

In your case, this means a check std::is_same<int, int const>that should fail.

, , , , , . , MSVC cv- value_type:

std::vector<const int>::value_type val = 5;
val = 10;

MSVC2008, gcc 4.4 .

, Microsoft.

: Nawaz . const int value_type ++ 03! , ++ 11.. ++ 11 , (§17.6.3.5) , , , .

MSVC const .

+9

GCC 4.7.2, , OP , static_assert.

, (, std::vector) const T, , [allocator.requirements] , .

, , std::vector<const int> undefined. !

. , , , sencence:

: const T.

+3

It seems to me that std::vector<const int>it is not allowed: according to the standard T there should be CopyInsertableand const intnot.

See Sequence Container Requirements in 23.2.3. Sequence containers [sequence.reqmts] in draft N3485 .

OP code will not compile with both gcc 4.7 and icc 13.0 in line

typedef std::vector<int const>::value_type t2;

Apparently, MSVC discards the const specifier.

+1
source

All Articles