title: Understanding how to add data to a map with SFML functions
body: <p>I'm doing this simple tutorial with SFML and c++ 11. I'm at the point where he teaches the map container. I have c# knowledge, and my understanding is map are the same as dictionaries. My question is about a code snippet he presents but doesn't explain well.</p>
  
  <p>TextureHolder.h</p>
  
  <pre><code>std::map&lt;std::string, sf::Texture&gt; m_textures;
  </code></pre>
  
  <p>TextureHolder.cpp</p>
  
  <pre><code>sf::Texture&amp; TextureHolder::GetTexture(std::string const&amp; filename)
  {
      auto&amp; r_textures = m_s_instance -&gt; m_textures;
      auto keyValuePair = r_textures.find(filename);
  
      if (keyValuePair != r_textures.end())
      {
          return keyValuePair-&gt;second;
      }
      else
      {
          auto&amp; texture = r_textures[filename];
          texture.loadFromFile(filename);
          return texture;
      }
  }
  </code></pre>
  
  <p>I understand everything except the else statement. This is my understanding of whats going on, but if anyone can clarify to me what is actually going on and why I'm mistaken, I would appreciate it.</p>
  
  <p><code>auto&amp; texture = r_textures[filename]</code> This creates a new key value pair with the key of filename. It then assigns the value to texture, which is an empty value since no texture has been loaded.</p>
  
  <p><code>texture.loadFromFile(filename);</code> This loads a texture file and assigns it to texture. This is where i'm completely lost. Some way this line is also adding the texture to the value of the key.</p>
  
  <p>Then it returns the texture to the calling function.</p>
  
  <p>This is probably more of a misunderstanding of how SFML handles the texture object, but I'm still confused on how this line communicates with the key value pair in the map.</p>