title: const correctness for custom reference wrapper
body: <p>I'm using <code>boost::variant</code> to implement type erasure when sending data across network. When the data arrives to the client or server, I'm inspecting its structure to retrieve the underlying information and reporting errors when the structure does not match the one agreed upon in the API. For this purpose, I created a lightweight reference wrapper that holds a reference to the variant and provides a convenient interface for structure inspection and type conversions.</p>
  
  <pre><code>using value_t = boost::make_recursive_variant&lt; /*types, some of them recursive*/ &gt;::type;
  
  class view_t {
  public:
    /*non-const methods to access value_*/
  private:
    value_t&amp; value_;
  };
  
  class cview_t {
  public:
    /*const methods to access value_*/
  private:
    const value_t&amp; value_;
  };
  
  view_t   view(value_t&amp; v){ return v; }
  cview_t cview(const value_t&amp; v){ return v; }
  cview_t cview(value_t&amp;&amp; v) = delete;
  cview_t cview(const value_t&amp;&amp; v) = delete;
  </code></pre>
  
  <p>Unfortunately, this interface proves to be cumbersome because every aggregate type that has a <code>view</code> member needs to follow the same const/non-const split. I was wondering whether it was legal to merge these two classes into a single view and use a const_cast in the methods that create views like this:</p>
  
  <pre><code>class view_t {
  public:
    /*const and non-const methods to access value_*/
  private:
    value_t&amp; value_;
  };
  
        view_t view(value_t&amp; v){ return v; }
  const view_t cview(const value_t&amp; v){ return const_cast&lt;value_t&amp;&gt;(v); }
  const view_t cview(value_t&amp;&amp; v) = delete;
  const view_t cview(const value_t&amp;&amp; v) = delete;
  </code></pre>