使用BOOST_FOREACH时如何正确地使Eclipse CDT自动缩进?

时间:2022-04-01 11:26:08

I write this tiny C++ example in Eclipse 3.4.1 (CDT 5.0.1):

我在Eclipse 3.4.1(CDT 5.0.1)中编写了这个小小的C ++示例:

#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:

然后我按Shift + Ctrl + F格式化我的代码,它变为:

#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.

这与BSD / Allman代码风格有关。其他样式显然改变了格式化代码的外观,但没有一个给出正确的缩进。

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?

我有什么办法可以使缩进与BOOST_FOREACH一起正常工作吗?

5 个解决方案

#1


3  

Add this to some header used by your code:

将其添加到代码使用的某些标头中:

#ifdef __CDT_PARSER__
    #undef BOOST_FOREACH
    #define BOOST_FOREACH(a, b) for(a; ; )
#endif

#2


2  

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

您可能想尝试astyle eclipse插件。它似乎比C ++缩进的默认eclipse风格好得多。

#3


2  

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 :-)

在目前的开普勒CDT中,它仍然被打破。但Eclipse的Bugzilla中存在一个错误(请在此处查看其状态)。它最终将被修复:-)

#4


1  

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

奇怪,这曾经与CDT 4一起使用。所以,如果你真的需要这个,我建议你降级你的CDT: - /

#5


0  

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

呃......你不能?尝试下一版CDT ......:_(

#1


3  

Add this to some header used by your code:

将其添加到代码使用的某些标头中:

#ifdef __CDT_PARSER__
    #undef BOOST_FOREACH
    #define BOOST_FOREACH(a, b) for(a; ; )
#endif

#2


2  

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

您可能想尝试astyle eclipse插件。它似乎比C ++缩进的默认eclipse风格好得多。

#3


2  

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 :-)

在目前的开普勒CDT中,它仍然被打破。但Eclipse的Bugzilla中存在一个错误(请在此处查看其状态)。它最终将被修复:-)

#4


1  

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

奇怪,这曾经与CDT 4一起使用。所以,如果你真的需要这个,我建议你降级你的CDT: - /

#5


0  

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

呃......你不能?尝试下一版CDT ......:_(