c++ - 使用 BOOST_FOREACH 时如何使 Eclipse CDT 自动缩进?

我在 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;
}

然后我按 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;
}

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

当我在一段较大的代码上使用格式化功能时,后续的函数或方法也会受到缩进太少的影响,使得格式化帮助非常无用。

我可以做些什么来使缩进与 BOOST_FOREACH 一起正常工作吗?

最佳答案

将此添加到您的代码使用的某些 header 中:

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

https://stackoverflow.com/questions/366380/

相关文章:

android - 如何在 Android 上将持续时间格式化为具有本地化时间单位的字符串?

javascript - Highcharts y轴千位分隔符

formatting - 在 Redmine wiki 页面中插入特殊字符

python - 避免在字符串中指定相同值的最pythonic方法是什么

iphone - 时间跨度的智能格式化

latex - 如何在 LaTeX 中的空格后设置制表位?

python - 我怎样才能产生一个很好的 numpy 矩阵输出?

wpf - 使用小数分隔符格式化 XAML 中的值?

c# - 单元格值的条件格式

c# - 为什么只有一个语句的方法需要大括号?