Equivalent # areas to C ++

What is the C ++ equivalent for #region for C ++, so I can put legible bits in the compilation code and make my code a little easier to read?

+67
c ++ c #
Jan 25 '12 at 9:40
source share
10 answers

The Region> keyword is a specific IDE and affects rendering in Visual Studio. The closest equivalent is the #pragma Region , which applies only to Visual Studio.

Sample Code from MSDN

// pragma_directives_region.cpp #pragma region Region_1 void Test() {} void Test2() {} void Test3() {} #pragma endregion Region_1 int main() {} 
+75
Jan 25 2018-12-12T00:
source share

In addition to #pragma region ... #pragma endregion for Visual Studio, many IDEs support the following syntax for regions in any {} -delimited, // -commented language:

 //{ Region header text. … //} 

Notable examples include Code :: Blocks and FlashDevelop, and any other editor that uses the Scintilla editing component, such as Notepad ++ , Geany , Komodo Edit, and many others.

+25
Jan 25 2018-12-12T00:
source share

There is no equivalent in C ++. However, IDEs should be able to collapse sections.

You can also use something like this:

 #pragma region #pragma endregion A comment about the region. 

But probably not very portable

+10
Jan 25 2018-12-12T00: 00Z
source share

There is no equivalent. The #region function is part of the C # specification.

C ++ has no such equivalent. You could mimic it with specially formatted comments, but that would be editor specific.

For Visual Studio you can use:

 #pragma region name ... #pragma endregion name 
+9
Jan 25 2018-12-12T00:
source share

I used

 #ifndef ANY_NAME_FOR_THIS_REGION ... #endif 

for several projects over the past few years, and it suits me (including collapsible blocks). As an addition, I can disable the block using #define ANY_NAME_FOR_THIS_REGION just above it.

+5
Oct 23 '15 at 11:02
source share

There is no equivalent.

Most good editors or IDEs will let you collapse functions, if not if / else / while / for / etc as well.

0
Jan 25 2018-12-12T00:
source share

Just a complement to the other answers. The definition of a region varies from IDE to IDE.

To develop a Mac in Xcode, you can use the pragma:

 #pragma mark 
0
May 29 '12 at 10:01
source share

C ++ Builder supports this, but you must declare the scope as:

 #pragma region BLAH ..... #pragma end_region 

You must use end_region for C ++ Builder, but it will work and it will destroy the region!

0
Dec 11 '14 at 22:06
source share

Kate, KDevelop, and all other text editors and IDEs that use Katepart support marking areas with the //BEGIN and //END markers.

 // BEGIN GPT entity types #define GPT_ENT_TYPE_UNUSED \ {0x00000000,0x0000,0x0000,0x00,0x00,{0x00,0x00,0x00,0x00,0x00,0x00}} #define GPT_ENT_TYPE_EFI \ {0xc12a7328,0xf81f,0x11d2,0xba,0x4b,{0x00,0xa0,0xc9,0x3e,0xc9,0x3b}} #define GPT_ENT_TYPE_MBR \ {0x024dee41,0x33e7,0x11d3,0x9d,0x69,{0x00,0x08,0xc7,0x81,0xf3,0x9f}} // END 

You can collapse the region defined in this way.

0
Oct 28 '17 at 9:38 on
source share

In the first answer, this question mentions another alternative. However, this is not applicable in all situations.

Method: Use instead {...}, which natively supports code failure in Visual Studio.

  • Enable the option: Tools → Options → Text Editor → C / C ++ → Formatting → Statement OutLine Blocks → True.

  • Put yours in different scopes {...}, then it will hide the code in different scopes:

Scoped code collapsing example

-one
Nov 11 '14 at 14:21
source share



All Articles