Boost logo

Boost :

From: David B. Held (dheld_at_[hidden])
Date: 2003-03-18 12:28:21

"David B. Held" <dheld_at_[hidden]> wrote in message
> "David Abrahams" <dave_at_[hidden]> wrote in message
> > [...]
> > 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
  by_ref(T const& val) : val_(&val) { }
  operator T const&() const { return *val_; }
  T* val_;

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

void g(long l) { }

template <typename T1>
void f(by_ref<T1> v1)

int main()

"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?


Boost list run by bdawes at, gregod at, cpdaniel at, john at