开发者

Boost::unordered_map with initialization list?

开发者 https://www.devze.com 2023-03-24 14:41 出处:网络
Is it possible to initialize a boost::unordered_map with a initialization list? -Weffc++ requires it.

Is it possible to initialize a boost::unordered_map with a initialization list? -Weffc++ requires it.

I can't use a method to initialize it because I only fill the map after some processing inside the constructor. I could create an empty map inside a metho开发者_Python百科d and return it, but that doesn't sound like a good idea to me.

I could use a pointer too and initialize it to NULL. I'd rather not though it's better than creating the equivalent of an empty method.


Just default-construct the member variable in the initialization list:

struct S {
    boost::unordered_map<int, int> m;

    S() : m() { }
};

This is enough to make -Weffc++ shut up.

0

精彩评论

暂无评论...
验证码 换一张
取 消