Initializing from an initializer list, but without {{{{{{{{ … }}}}}}}}?

前端 未结 6 1729
忘了有多久
忘了有多久 2020-12-15 04:24

I recently stumbles across some problem with initializer lists. Consider a program that stores map-like data

struct MyMapLike {
  MyMapLike(std::map

        
6条回答
  •  孤城傲影
    2020-12-15 04:55

    Since I have a map-like class, and the initializer has the abstract value of a mapping-list, I would like to use the former version

    And herin lies the problem: it's up to you to supply the constructors that allow your class to be treated like a map. You called your solution a work-around, but there's nothing to work around. :)

    But I think this separate need of the constructor is dead ugly.

    It is, but unfortunately since it's your class, you have to specify how the initializer lists work.

提交回复
热议问题