$include_dir="/home/hyper-archives/boost/include"; include("$include_dir/msg-header.inc") ?>
From: E. Gladyshev (egladysh_at_[hidden])
Date: 2003-10-28 15:55:13
--- Eric Friedman <ebf_at_[hidden]> wrote:
[...]
> 
> Yes, the idea of not allowing singular state is that the user is forced 
> to deal with the possibility that the variant contains boost::empty.
> 
> If you really wanted, you could write something as follows (not tested):
> 
>    template <typename VisitorBase, typename T>
>    struct cannot_visit
>      : VisitorBase
>    {
>      typedef typename VisitorBase::result_type result_type;
> 
>      result_type operator()(const T&) const
>      { throw boost::bad_visit(); }
> 
>      template <typename U>
>      result_type operator()(const T&, const U&) const
>      { throw boost::bad_visit(); }
> 
>      template <typename U>
>      result_type operator()(const U&, const T&) const
>      { throw boost::bad_visit(); }
>    };
> 
> Which would then be used like this:
> 
>    struct my_visitor
>      : cannot_visit<
>            boost::static_visitor<R>, boost::empty
>          >
>    {
>      using cannot_visit::operator();
> 
>      template <typename T>
>      R operator()(const T& t)
>      {
>        return t.f(); // or whatever
>      }
>    };
I think you forgot one more overload
     template <typename U, typename T>
     result_type operator()(const T& x, const U& y) const
     {
        x.do_something(y);
     }
I am not sure that the overloads
      template <typename U, typename T>
      result_type operator()(const T&, const U&) const;
      template <typename U>
      result_type operator()(const T&, const U&) const;
      template <typename U>
      result_type operator()(const U&, const T&) const;
will be resolved by the compiler.
I have done a quick test.
struct test_t
{
        template< typename T, typename U > void f( T& , U& );
        template<typename U> void f( int&, U& );
        template<typename T> void f( T&, int& );
};
test_t m;
void* p;
int n;
m.f(p, n);
Got the following error:
'f' : none of 2 overload have a best conversion
'f' : ambiguous call to overloaded function
I don't think that the overloading solution will work for
binary visitors.
Eugene
__________________________________
Do you Yahoo!?
Exclusive Video Premiere - Britney Spears
http://launch.yahoo.com/promos/britneyspears/