title: Table Representation in C++
body: <p>Basically, say, I have the following data:</p>
  
  <p><a href="https://i.stack.imgur.com/CMmp9.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/CMmp9.png" alt="enter image description here"></a></p>
  
  <p><em>(let me note that the columns change with every piece of data I get, i.e. I need to keep things general and cannot restrict my solution to only Tenor, Date, etc.)</em></p>
  
  <p>Now I want to be able to represent and conveniently access this data in an object/class in C++.</p>
  
  <p>I have been playing around with <code>map</code> a bit:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;map&gt;
  #include &lt;string&gt;
  using namespace std;
  
  class my_table {
  private:
      map&lt;string, map&lt;string, string&gt;&gt; c;
  
  public:
      void set(string key1, string key2, string value){ this-&gt;c[key1][key2] = value; }
  
      string get(string key1, string key2){
          map&lt;string, map&lt;string, string&gt;&gt;::iterator it = this-&gt;c.find(key1);
          if (it != this-&gt;c.end()){
              map&lt;string, string&gt;::iterator it2 = this-&gt;c[key1].find(key2);
              if (it2 != this-&gt;c[key1].end()){
                  return c[key1][key2];
              }
              return "n/a";
          }
          return "n/a";
      }
  };
  
  void main() {
      my_table a;
      a.set("1", "Tenor", "1D");
      cout &lt;&lt; a.get("1", "Tenor") &lt;&lt; endl; // returns '1D'
      cout &lt;&lt; a.get("2", "Tenor") &lt;&lt; endl; // returns 'n/a'
      cout &lt;&lt; a.get("1", "Rate") &lt;&lt; endl;  // returns 'n/a'
  }
  </code></pre>
  
  <p>But I am not overly satisfied with this implemenation. In particular, I would want to be able to do things like:</p>
  
  <pre><code>a.get("Tenor","3M", "Rate")                   // should return '1.6%'
  a.get("Date","01-Jan-2016", "Responsibility") // should return 'MG'
  a.get_all("Type","Forward", "Rate")           // should return an array {1.3%,2.4%}
  a.get_row(4)                                  // should return an array {4M,...,2.0%,MG}
  </code></pre>
  
  <p><br>
  And:</p>
  
  <ul>
  <li>I am wondering whether there are there any standard packages that could help me simplify this implementation overall?</li>
  <li>In particular, my <code>get</code> function seems unnecessarily cumbersome.</li>
  <li>And generally, is <code>map</code> is even the right way to go in terms of storing data like this?</li>
  <li>And what if I wanted to generalise this implemenation to more than just 2 keys? Maybe 3 keys. My solution is quite rigid</li>
  </ul>