How to cheaply assign C-style array to std::vector?

后端 未结 4 1411
[愿得一人]
[愿得一人] 2020-12-01 16:13

Currently I do the following:

// float *c_array = new float[1024];

void Foo::foo(float *c_array, size_t c_array_size) {
  //std::vector cpp_arr         


        
4条回答
  •  不思量自难忘°
    2020-12-01 16:21

    The only way to do it would be to create a custom allocator.

    1. Write an allocator class that you can initialise with your array.

    2. Instantiate the vector with the allocator as an argument.

提交回复
热议问题