views:

2251

answers:

3

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?

A: 

Euh... you can't ? Try next version of CDT... :_(

Helltone
+1  A: 

Strange, this used to work with CDT 4. So if you really really need this I suggest you downgrade your CDT :-/

Martin
Maybe the formatter got too clever?
divideandconquer.se
+2  A: 

You might want to try the astyle eclipse plugin. It seems to be much nicer than the default eclipse style of C++ indentation.

Nik Reiman