title: Boost type_erasure any with const member function
body: <p>I want to access a getter of type-erased types in a vector. The getter is marked const. Somehow, the const-ness does not propagate to the boost::any wrapper object. The minimal example</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;vector&gt;
  
  #include &lt;boost/mpl/vector.hpp&gt;
  #include &lt;boost/type_erasure/any.hpp&gt;
  #include &lt;boost/type_erasure/member.hpp&gt;
  
  using namespace boost;
  using namespace boost::type_erasure;
  
  BOOST_TYPE_ERASURE_MEMBER((has_test), test, 1)
  
  using AnyTest = any&lt;mpl::vector&lt;copy_constructible&lt;&gt;,
                                  has_test&lt;int(double)&gt;,
                                  relaxed&gt;&gt;;
  
  struct ATest {
    int test(double x) const {
      return 5;
    }
  };
  
  int main() {
    auto xs = std::vector&lt;AnyTest&gt;{};
    xs.push_back(ATest{});
  
    for (const auto&amp; x : xs) {
      std::cout &lt;&lt; x.test(42.0) &lt;&lt; '\n';
    }
  }
  </code></pre>
  
  <p>results in an error saying</p>
  
  <pre><code>clang++ -O3 -std=c++14    minimal.cc   -o minimal
  minimal.cc:28:18: error: member function 'test' not viable: 'this' argument has type 'const
        boost::type_erasure::any&lt;boost::mpl::vector&lt;boost::type_erasure::copy_constructible&lt;boost::type_erasure::_self&gt;, has_test&lt;int (double),
        boost::type_erasure::_self&gt;, boost::type_erasure::relaxed, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na,
        mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na&gt;, boost::type_erasure::_self&gt;', but
        function is not marked const
      std::cout &lt;&lt; x.test(42.0) &lt;&lt; '\n';
                   ^
  minimal.cc:11:39: note: 'test' declared here
  BOOST_TYPE_ERASURE_MEMBER((has_test), test, 1)
                                        ^
  /opt/local/include/boost/type_erasure/member.hpp:133:9: note: expanded from macro 'BOOST_TYPE_ERASURE_MEMBER'
          member,                                                                             \
          ^
  /opt/local/include/boost/type_erasure/member.hpp:242:64: note: expanded from macro 'BOOST_TYPE_ERASURE_MEMBER_I'
      BOOST_TYPE_ERASURE_MEMBER_II(namespace_name, concept_name, member, N)
                                                                 ^
  /opt/local/include/boost/type_erasure/member.hpp:170:44: note: expanded from macro 'BOOST_TYPE_ERASURE_MEMBER_II'
          typename rebind_any&lt;Base, R&gt;::type member(                                              \
                                             ^
  1 error generated.
  make: *** [minimal] Error 1
  </code></pre>
  
  <p>However, once <code>const auto&amp; x</code> in the for-loop is changed to just <code>auto&amp; x</code>, it works. What's the reason for this and how can I require the wrapper object to respect constness?</p>