In the following code, a vector<int> is constructed from an array of int8_t. It happens to work, but is it safe?
int8_t *arr;
int arr_size;
... // Filling the array somehow
std::vector<int> v(arr, arr + arr_size); // Is this safe even though we use int8_t* to construct a vector of int?
The documentation at cppreference.com says:
This constructor has the same effect as
vector(static_cast<size_type>(first), static_cast<value_type>(last), a)ifInputItis an integral type. (until C++11)This overload only participates in overload resolution if
InputItsatisfiesInputIterator, to avoid ambiguity with the overload (2). (since C++11)
This explanation does not give me a clue about my question. In fact, it confuses me further, since the template arguments for static casts seem to be very wrong...
Aucun commentaire:
Enregistrer un commentaire