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

标签 c++ eclipse boost formatting indentation

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

关于c++ - 使用 BOOST_FOREACH 时如何使 Eclipse CDT 自动缩进?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/366380/

相关文章:

c++ - 为什么 C++ 不支持命名参数?

c++ - 将消息添加到断言

eclipse - 如何使用sbt-eclipse创建项目的Eclipse项目文件?

java - 向android项目添加不同的外部jar

c++ - Boost.asio 端点是否可以用于识别 UDP 连接的客户端?

c++ - boost::bind()-类似的东西,但用于函数调用

c++ - 未定义、实现定义、未指定的行为都不是

c++ - 混合转换指针和引用

java - 程序参数和 VM 参数有什么区别?

c++ - 如何更改或删除 boost 序列化中的标签?