How to emulate C array initialization “int arr[] = { e1, e2, e3, … }” behaviour with std::array?

后端 未结 10 941
难免孤独
难免孤独 2020-11-22 17:23

(Note: This question is about not having to specify the number of elements and still allow nested types to be directly initialized.)
This question discu

10条回答
  •  爱一瞬间的悲伤
    2020-11-22 17:50

    I'd expect a simple make_array.

    template std::array make_array(T&&... refs) {
        // return std::array{ { std::forward(refs)... } };
        return { std::forward(refs)... };
    }
    

提交回复
热议问题