GCC 4.4 does not implement the C ++ 11 range loop. What other range loop syntax does it support?

I have a third-party tool that uses some c++11 features, and I need to compile it under gcc 4.4. Since I am not at all familiar with the new c++11 features, but I thought I would ask for help after the google search turned out to be fruitless.

I turned on the c++0x switch, but this does not help here:

 for (auto const& fixup : self->m_Fixups) 

An error has occurred:

 error: expected initializer before ':' token 

What other range loop syntax that is equivalent to the c++11 range loop does GCC 4.4 support?

+7
c ++ c ++ 11 g ++
source share
2 answers

The code is a for-loop, which is really new in C ++ 11. It is not implemented in GCC 4.4, unlike some other functions from C ++ 11. Try the following:

 for( auto it = self->m_Fixups.begin(); it != self->m_Fixups.end(); ++it ) { const auto& fixup = *it; // the rest of the code... } 

The above example uses some C ++ 11 features that should be available in GCC 4.4.


As Ben Voigt noted: if you need to make the code more efficient, you can also use this slightly less compressed version:

 for( auto it = self->m_Fixups.begin(), end = self->m_Fixups.end(); it != end; ++it ) { const auto& fixup = *it; // the rest of the code... } 
+7
source share

If you have a raise, the following should work with -std=c++0x (tested on gcc 4.4.7, RHEL6):

 #include <boost/foreach.hpp> BOOST_FOREACH(const auto &fixup, self->m_Fixups) { ... } 
0
source share

All Articles