VC++でこんな感じのコードをコンパイルしたとき
void Func(int* dest, int size)
{
std::vector<int> src(size);
std::copy(src.cbegin(), src.cend(), dst);
}
以下のような警告文が出てきたときの対処方法。
'std::_Copy_impl': Function call with parameters that may be unsafe
- this call relies on the caller to check that the passed values are correct.
std::copy
にイテレータではなくポインタを渡していたことが原因でした。
配列であり、そのサイズもわかっているなら以下のようにすることでイテレータに変換できるようです。
std::copy(src.cbegin(), src.cend(), stdext::checked_array_iterator<int*>(dst, size));