How should std::map be used with a value that does not have a default constructor?

前端 未结 3 1694
闹比i
闹比i 2021-01-18 16:58

I\'ve got a value type that I want put into a map. It has a nice default copy constructor, but does not have a default constructor.

I believe that so long as I stay

3条回答
  •  北海茫月
    2021-01-18 17:45

    You could first get the position to insert the pair with lower_bound, then check if it's already there, and if not, insert it, providing the iterator where to insert. Something along those lines.

提交回复
热议问题