Initialize a vector of pairs in one line

后端 未结 2 1319
独厮守ぢ
独厮守ぢ 2020-12-21 18:36

I want to initialize a std::vector (of std::pair), with k objects, with the pair of values shown below.

Here is my attempt:

// int k
std         


        
2条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-21 18:50

    You can just switch to { } around the constructor arguments...

    std::vector> v{k, {std::numeric_limits::max(), -1}};
    

    See it running here

提交回复
热议问题