title: Function arguments grouping and constness
body: <p>We are trying to refactor our code and one of the improvements we want is the following: many functions have many arguments but many of them share a common subset. So, we would like to create a structure that would group them. The problem is that some functions need some of the parameters to be const and some not. Some of these functions must be able to call a subset of these functions supplying this parameter-grouping structure, but under the following restriction: a called function cannot "degrade" the constness of this structure (see the following example). Implementing all required variations of this struct solves the problem but not elegantly. One solution we're working on is to use templates, e.g:</p>
  
  <pre><code>template&lt;class A, class B, class C&gt;
  struct my_container
  {
      A a;
      B b;
      C c;
  };
  
  void foo1(my_container&lt;int, char, float const&gt; &amp; my_cont)
  {
  }
  
  void foo2(my_container&lt;int const, char, float const&gt; &amp; my_cont)
  {
      // This should NOT be allowed: we do mind something being const to be treated by the
      // called function as non-const.
      foo1(my_cont);
  }
  
  void foo3(my_container&lt;int, char, float&gt; &amp; my_cont)
  {
      // This should be allowed: we don't mind something being non-const to be treated by the
      // called function as const.
      foo2(my_cont);
  }
  </code></pre>
  
  <p>Our problem is that foo2 calls foo1 without the compiler complaining, and we'd like the exact opposite. Is this even possible to implement with templates? Is there any other technique?</p>