Convert a vector to initializer_list

前端 未结 6 1905
时光取名叫无心
时光取名叫无心 2021-01-31 01:26

Everyone creates std::vector from std::initializer_list, but what about the other way around?

eg. if you use a std::initializer_list

6条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-31 02:00

    Apparently no, it is not possible. There is no such constructor (and I believe for good reasons), std::initializer_list is a weird creature.

    What you could do instead is to change someThing() to accept a pair of iterators. In that way you get what you want, provided you can change the signature of that function (it isn't in a third party library, etc).

提交回复
热议问题