Boost::unordered_map with initialization list?
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.
加载中,请稍侯......
精彩评论