title: Pass by value or const reference to function?
body: <p>Should I pass <code>std::string</code> by value or by reference to one function. This function store this values in member variable of class.</p>
  
  <p>I am always confuse when about pass by value or reference. Please clear my confusion about this. </p>
  
  <p>Here is code :</p>
  
  <pre><code>class DataStore {
  public:
      void addFile(const string&amp; filename, const set&lt; std::string&gt;&amp; filePaths)
      {  
          if (dataStoreMap.insert(make_pair(filename, filePaths)).second)
          {
              cout &lt;&lt; "Data Added" &lt;&lt;endl;
          }
          else
          {
              cout &lt;&lt; "Data not Added" &lt;&lt; endl;
          }
      }
  private:
      // member variable
      map &lt; string, set &lt; string &gt;  &gt; dataStoreMap;
  };
  </code></pre>
  
  <p>Shall I make function declaration like this :</p>
  
  <pre><code>void addFile(const string&amp; filename, const set&lt; std::string&gt;&amp; filePaths)
  </code></pre>
  
  <p>or </p>
  
  <pre><code>void addFile(const string filename, const set&lt; std::string&gt; filePaths)
  </code></pre>
  
  <p>Both gives same result. If there any issue about memory allocation or performance.</p>
  
  <p>Above function call from <code>cpp</code> class.    </p>
  
  <pre><code>DataStore ds;
  set&lt;string&gt; setFileDirectory{ "1", "2", "3", "4", "6", "5" };
  ds.addFile("file.txt", setFileDirectory);
  
  setFileDirectory.erase(setFileDirectory.begin(), setFileDirectory.end());
  setFileDirectory.insert({ "1", "2", "3", "4", "5", "6" });
  ds.addFile("demo.txt", setFileDirectory);
  </code></pre>
  
  <p>Any detailed explanation would be appreciated.</p>
  
  <p>Thanks</p>