title: Type erasing type erasure, `any` questions?
body: <p>So, suppose I want to type erase using type erasure.</p>
  
  <p>I can create pseudo-methods for variants that enable a natural:</p>
  
  <pre><code>pseudo_method print = [](auto&amp;&amp; self, auto&amp;&amp; os){ os &lt;&lt; self; };
  
  std::variant&lt;A,B,C&gt; var = // create a variant of type A B or C
  
  (var-&gt;*print)(std::cout); // print it out without knowing what it is
  </code></pre>
  
  <p>My question is, how do I extend this to a <code>std::any</code>?</p>
  
  <p>It cannot be done "in the raw".  But at the point where we assign to/construct a <code>std::any</code> we have the type information we need.</p>
  
  <p>So, in theory, an augmented <code>any</code>:</p>
  
  <pre><code>template&lt;class...OperationsToTypeErase&gt;
  struct super_any {
    std::any data;
    // or some transformation of OperationsToTypeErase?
    std::tuple&lt;OperationsToTypeErase...&gt; operations;
    // ?? what for ctor/assign/etc?
  };
  </code></pre>
  
  <p>could somehow automatically rebind some code such that the above type of syntax would work.</p>
  
  <p>Ideally it would be as terse in use as the variant case is.</p>
  
  <pre><code>template&lt;class...Ops, class Op,
    // SFINAE filter that an op matches:
    std::enable_if_t&lt; std::disjunction&lt; std::is_same&lt;Ops, Op&gt;... &gt;{}, int&gt;* =nullptr
  &gt;
  decltype(auto) operator-&gt;*( super_any&lt;Ops...&gt;&amp; a, any_method&lt;Op&gt; ) {
    return std::get&lt;Op&gt;(a.operations)(a.data);
  }
  </code></pre>
  
  <p>Now can I keep this to a <em>type</em>, yet reasonably use the lambda syntax to keep things simple?</p>
  
  <p>Ideally I want:</p>
  
  <pre><code>any_method&lt;void(std::ostream&amp;)&gt; print =
    [](auto&amp;&amp; self, auto&amp;&amp; os){ os &lt;&lt; self; };
  
  using printable_any = make_super_any&lt;&amp;print&gt;;
  
  printable_any bob = 7; // sets up the printing data attached to the any
  
  int main() {
    (bob-&gt;*print)(std::cout); // prints 7
    bob = 3.14159;
    (bob-&gt;*print)(std::cout); // prints 3.14159
  }
  </code></pre>
  
  <p>or similar syntax.  Is this impossible?  Infeasible?  Easy?</p>