I write this tiny C++ example in Eclipse 3.4.1 (CDT 5.0.1):
#include <iostream>
#include <vector>
#include <boost/foreach.hpp>
int foo()
{
std::vector<int> numbers;
BOOST_FOREACH(int n, numbers)
{
std::cout << n << std::endl;
}
std::cout << numbers.size << std::endl;
}
Then I hit Shift+Ctrl+F to format my code, and it becomes:
#include <iostream>
#include <vector>
#include <boost/foreach.hpp>
int foo()
{
std::vector<int> numbers;
BOOST_FOREACH(int n, numbers)
{ std::cout << n << std::endl;
}
std::cout << numbers.size << std::endl;
}
This is with the BSD/Allman Code Style. Other styles obviously vary the look of the formatted code, but none give correct indentation.
When I use the format feature on a larger piece of code, subsequent functions or methods are also affected by too little indentation, making the formatting help pretty unhelpful.
Is there something I can do to make the indentation work properly with BOOST_FOREACH?
Add this to some header used by your code:
#ifdef __CDT_PARSER__
#undef BOOST_FOREACH
#define BOOST_FOREACH(a, b) for(a; ; )
#endif
It is still broken in the current CDT for Kepler. But there is a bug in Eclipse's Bugzilla (check its status here). It will eventually be fixed :-)
You might want to try the astyle eclipse plugin. It seems to be much nicer than the default eclipse style of C++ indentation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With