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
  • 102,241
  • 35
  • 217
  • 344
Chan Kim
  • 4,339
  • 10
  • 39
  • 84

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
  • 64,903
  • 40
  • 160
  • 271