2

I see a code below. (it's from caffe source, a deep learning library)

  map<int, string> layer_idx_to_layer_name;
  layer_idx_to_layer_name[-1] = "input";

What does the second line mean? I guess it's assigning a default value. Is it correct?

Shai
  • 111,146
  • 38
  • 238
  • 371
Chan Kim
  • 5,177
  • 12
  • 57
  • 112

1 Answers1

3

It's doing what it says: Assigning the string "input" to the map entry whose key is -1.

There's no concept of a default value with std::map.

Remember, the key of a std::map doesn't have to be an int (let alone, positive ints) - it can be pretty much any type. std::map isn't a vector.

What requirements must std::map key classes meet to be valid keys?

Community
  • 1
  • 1
Roddy
  • 66,617
  • 42
  • 165
  • 277