1

This question isn't directly related to coding, but more to do with the efficiency and organisation of the c++ code. I have loads of declarations of arrays with preset data so they take up quite a lot of space.

I don't know whether this is a visual studio 2012 only feature but with functions I am able to minimise it so all I see is the name "void randomfunction()", this means I really speed up coding by collapsing all functions that I know are done and dusted for the time being.

What I would like to know if this is possible with any other parts of the code, like when you want to add a comment you // before typing. Is it possible to define two boundaries around a chunk of code so that I can collapse it.

Ok thanks guys for help im using the #pragma region #pragma endregion commands, how would i name the region so that if i create multiple i can know which is which whithout opening?

2 Answers2

5

You can write

#pragma region "My region name"

And it will work.

However, if you find yourself in a need to hide code, that means your functions are too long. You should divide your code logically without resorting to hacks like these.

Bartek Banachewicz
  • 38,596
  • 7
  • 91
  • 135
  • He specifically said what he wanted to be able to collapse: a long constant list. How exactly would you "divide your code logically" in a long list of constants? I can't think of anything. :p (Well, I suppose putting them in a separate file, but sometimes you don't want to.) – neminem Aug 12 '13 at 14:41
  • @neminem In that case putting it in a separate header would be a reasonable solution. Also when answering on SO you're answering to the whole community, not only the OP. I don't want newbies abusing `#pragma region` (I did that myself `:(`) – Bartek Banachewicz Aug 12 '13 at 14:55
  • It seems you must use `#pragma endregion "My region name"` to be able to collapse the code chunk. – joepol Nov 19 '20 at 07:19
1

This is called code folding. In visual studi there are hotkeys that are described here Visual Studio - Command to collapse all sections of code? For C++, any scope block {} can be folded separately...

Community
  • 1
  • 1
Ilya Kobelevskiy
  • 5,245
  • 4
  • 24
  • 41
  • To piggyback on this answer, VS stores which scope blocks are folded in your .user profile file, and will keep them folded the next time you open the file. – moswald Aug 09 '13 at 19:12