How do I make Eclipse CDT auto-indent correctly when I use BOOST_FOREACH?

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

#include 
#include 
#include 

int foo()
{
  std::vector 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 
#include 
#include 

int foo()
{
    std::vector 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
Hello, buddy!责编内容来自:Hello, buddy! (源链) | 更多关于

阅读提示:酷辣虫无法对本内容的真实性提供任何保证,请自行验证并承担相关的风险与后果!
本站遵循[CC BY-NC-SA 4.0]。如您有版权、意见投诉等问题,请通过eMail联系我们处理。
酷辣虫 » 综合编程 » How do I make Eclipse CDT auto-indent correctly when I use BOOST&lowbar;FOREACH&quest;

喜欢 (0)or分享给?

专业 x 专注 x 聚合 x 分享 CC BY-NC-SA 4.0

使用声明 | 英豪名录