Question

Is there a difference in the following initializations of a static map?

static std::map<FunctionID, std::string> enum_string_representation {
  {FunctionID.something, "something"}
};

and

static std::map<FunctionID, std::string> enum_string_representation {
  {std::make_pair(FunctionID.something, "something")}
};
Was it helpful?

Solution

No difference. There are several possible constructors of map and you are using this one in both cases:

map( std::initializer_list<value_type> init,
     const Compare& comp = Compare(),
     const Allocator& alloc = Allocator() );

value_type is of type std::pair<..,..> and built from either {FunctionID.something, "something"} or std::make_pair(FunctionID.something, "something").

You could also write:

static std::map<FunctionID, std::string> enum_string_representation {
  std::make_pair(FunctionID.something, "something")
};
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top