"David B. Held" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> "David Abrahams" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
> > [...]
> > That's a pretty major problem, though.  Your idea also cuts off
> > implicit conversions.
>
> Do you mean user-defined conversions, because it consumes one
> from by_ref->T?  It's more awkward, but wouldn't calling a named
> member to get T solve that?
> [...]

I wonder if you mean the implicit conversion from T to by_ref in the
first place instead.  It turns out that I really don't understand how
argument deduction goes, because Comeau doesn't like this code,
which I expected to work:

template <typename T, bool Big = (sizeof(T) > 8)>
class by_ref
{
public:
  by_ref(T const& val) : val_(&val) { }
  operator T const&() const { return *val_; }
private:
  T* val_;
};

template <typename T>
class by_ref<T, false>
{
public:
  by_ref(T val) : val_(val) { }
  operator T() const { return val_; }
private:
  T val_;
};

void g(long l) { }

template <typename T1>
void f(by_ref<T1> v1)
{
  g(v1);
}

int main()
{
  f(5);
}

"ComeauTest.c", line 31: error: no instance of function template "f"
          matches the argument list
            The argument types that you used are: (int)


Also, I was suprised that I had to put parens around the sizeof(T) > 8
expression, as I thought that the parser had to try to match the largest
possible token sequence to the template parameter.  But maybe that
only applies for instantiations, and not definitions?

Dave



_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

Reply via email to