v1; std::v...">

Are these vector definitions "permanent initialization"?

This question is about the code (in the namespace area):

std::vector<int> v1;
std::vector<int> v2(4);

Section 3.6.2 C ++ 14 (N4140) defines the term Constant initialization:

Continuous initialization is performed:

  • [omitted - about link initialization]
  • if an object with a static or storage duration of threads is initialized by calling the constructor, and if the full initialization expression is a constant initializer for the object,
  • if the object with the statics or duration of the storage of the stream is not initialized by calling the constructor, and if either the object is initialized with a value or any complete expression that appears in its initializer is a constant expression.

In addition, the term constant initializer is defined only earlier:

o - , , , constexpr o , .

, std::vector<int> v2(4).

, . 4. 4 - , . , , .

, , , v2 .

v1 , " "; , .

: v1 v2 ; , , ?

+2
1

1.9/10, :

- , .... , .... , , , .
[:
...

S s1(1); // full-expression is call of S::S(int)

, 8.5/17, ( v1, v2) .

, " " . , , 4, . , , , constexpr, ( , ). , size_t std::vector constexpr, .

+7

Source: https://habr.com/ru/post/1622964/


All Articles