Why both runtime-sized arrays and std::dynarray in C++14?

前端 未结 3 476
北荒
北荒 2020-12-16 09:17

Draft C++14 includes both runtime-sized arrays and the std::dynarray container. From what I can tell, the only real difference between the two is that st

3条回答
  •  死守一世寂寞
    2020-12-16 09:30

    I think you answered the question yourself, std::dynarray has the stl interface. A goal of c++11 and I'm assuming c++14 is to make c++ more user friendly, less error prone and easier for beginners. With c style arrays you may run into pointer arithmetic problems but dynarray avoids the problems if used as intended
    EDIT: so it looks like one difference is that runtime-sized arrays must be allocated on the stack, increasing the likelyhood of a stack overflow. dynarray is allocated on the heap though it is possible to allocate on the stack (if the implementation did so)

提交回复
热议问题