Codeforces Round 1133 (Div. 1, Div. 2) is coming soon! Register here. ×
The use of `#include __FILE__`
Difference between en3 and en4, changed 161 character(s)
So many people want to make a template that including everything needed to code faster during rounds. But if your templates are too long, it will take some time to scroll down. So here's a solution (asides from `#pragma region`): `#include __FILE__`.↵
↵
Combine it with `#ifdef` and other defines, it can move codes to the top section. Here's an example:↵
↵
```cpp↵
#ifndef TYPE_A↵
#define TYPE_A 1↵
#include __FILE__↵
int main()↵
{↵
    lint a=0;↵
}↵
#elif TYPE_A == 1↵
using lint=long long;↵
#endif↵
```↵
↵
You can see it just move the `lint` declar
ation to the top. But your clangd might give you an error. To bypass this, you need to add a `using` before the `#include`. It can be `using namespace ...`, or `using lint = int64_t`. But I suggest you to write like this:↵
↵
```cpp↵
#ifndef TYPE_A↵
#define TYPE_A 1↵
#include <bits/stdc++.h>↵
using namespace std;↵
#include __FILE__↵
int main()↵
{↵
    lint a=0;↵
}↵
#elif TYPE_A == 1↵
using lint=long long;↵
#endif↵
```↵
↵
Now there will be no warnings or errors anymore. Also if you decided to move `bits/stdc++.h` down below, your clangd will be super slow.↵
↵
Also you can `#include __FILE__` multiple times, just `#undef TYPE_A` the redefine it. But that will make your template a terrible chaos. Use at your own risk.
↵
↵
I've been using this technique on several OJs, they can all accept such codes.↵
↵
Note that even if clangd gives you an error, g++ can still compile this.

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en4 English ForgottenCat 2026-06-12 13:03:19 161 (published)
en3 English ForgottenCat 2026-06-12 12:58:20 4
en2 English ForgottenCat 2026-06-12 12:57:53 9
en1 English ForgottenCat 2026-06-12 12:57:33 1302 Initial revision (saved to drafts)