Boost logo

Boost :

From: Kevin S. Van Horn (kevin.vanhorn_at_[hidden])
Date: 2002-02-18 11:28:41


On 18 Feb 2002 nbecker_at_[hidden] wrote:

> joel> Next to typeof(x), I'd love to see Dave (Abraham's) "auto" for type deduction.
> joel> auto v = an_arbitrarily_complex_expression;
>
> Wow. c++ has always been strongly typed. Doesn't this potentially
> have far reaching consequences?

You don't have to lose strong typing for this to work. The point is that
the compiler can *deduce* the type for v -- it's just the type of
an_arbitrarily_complex_expression. One way to think of this is that

  {
   ...
   auto v = e;
   some_code
  }

is semantically equivalent to

  {
   ...
   foo(e)
  }

where we define

  template <typename T>
  void foo(T v)
  {
    some_code
  }

We see here that one might want to distinguish auto, auto &, auto const
and auto const &.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk