Boost logo

Boost :

Subject: [boost] [foreach] Request for auto type deduction
From: Andrzej Krzemienski (akrzemi1_at_[hidden])
Date: 2009-11-16 07:03:49


Hi,
Boost already provides a tool for emulating C++0x auto syntax:

  auto iter = map_of_strings.begin(); // C++0x
  BOOST_AUTO( iter, map_of_strings.begin() ); // boost

It even works in more complex contexts like:

  if( BOOST_AUTO(ptr, get_pointer()) ) {
    ptr->run();
  }

or:

  BOOST_AUTO( const& val, vect.front() );

It already provides a tool for emulating C++0x range-based for syntax:

  for( int & x : vect ) { ...} // C++0x
  BOOST_FOREACH( int & x, vect ) { ... }; // boost

However currently it is impossible to emulate the following C++0x syntax:

  for( auto & x : collection ) { ... } // C++0x

Therefore, I would like to request a new tool in Boost.Foreach that
would emulate the above construct, and would look something like:

  BOOST_FOREACH_AUTO( const& x, collection ) {...}

I do not anticipate any technical difficulties with implementing this,
as it can already be achiever with a verbose:

  BOOST_FOREACH( BOOST_TYPEOF( boost::begin(collection) ) const& x,
collection ) {..}

Regards,
&rzej


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