So I wrote a tool to save all people suffering from annoying template codes

Правка en4, от ExplodingKonjac, 2026-05-04 18:33:44

Foreword

Almost every competitive programmer has his own template codes such as IO library or algorithms or data structures or debugging support or anything. Though templates are absolutely useful, but when we try to submit our code onto any Online Judge, the problem appears: We must paste all those extremely long templates into a single source file. It is unpleasant. Even if we are solving a 800-rated problem our source code would contain hundreds of lines just because that stupid template. Long codes distract our attention and make us unhappy.

Ideally, we can use our templates by #include statements just like we use AC-Library in AtCoder. However, most online judges do not provide a library, and all online judges do not allow you to use your customized libraries. So I wrote a tool to solve this problem, in a compromise approch.

Introduction

Template Expand is a tool for C/C++ Competitive Programming. Its functionality is straightforward: read your code, expand the #include statements into full code, and output the expanded code. It can automatically resolve dependencies and remove duplicated includes, and even has an optional code compression feature.

For example, if you have

// mylib.hpp
int super_cool_algo(int a, int b) {
    return a + b;
}

// main.cpp
#include "mylib.hpp"
#include <iostream>

int main() {
    int a, b;
    std::cin >> a >> b;
    std::cout << super_cool_algo(a, b) << '\n';
    return 0;
}

and you perform expand on main.cpp, you will get

int super_cool_algo(int a, int b) {
    return a + b;
}
#include <iostream>

int main() {
    int a, b;
    std::cin >> a >> b;
    std::cout << super_cool_algo(a, b) << '\n';
    return 0;
}

and if you turned on the compress switch, you might get

int super_cool_algo(int a,int b){return a+b;}
#include <iostream>
int main(){int a,b;std::cin>>a>>b;std::cout<<super_cool_algo(a,b)<<'\n';return 0;}

The tool are suitable for most users:

  • If you are a normal coder using VSCode or editors based on VSCode: We provide a VSCode extension! Its UI is simple and its configuration is straightforward. Take 2 minutes to configure the extension, and next time just press a button on the editor title bar and the expanded code would be ready in your clipboard.

  • If you are a geek coder who types CLI commands like native language: We also provide a CLI tool named texpand-cli! The program can read from a source file (or stdin) and write the result into target file (or stdout or your clipboard), able to be easily integrated into your own workflow.

Links:

Currently this tool is under development. It is not fully tested on OS except for Linux and may have bunches of bugs. You are welcomed to create issues and PRs in the repository! If you like this tool offer me a star plz :)

Acknowledgements

  • Thanks Claude Code and DeepSeek V4 for reducing 90% of my tiring work.
  • Each day I spent tens of millions of tokens and it only cost me around 2~3 CNY, so thanks DeepSeek company for creating such an amazing model.
  • Thanks CharlieV for testing the tool and providing weird edge cases.
Теги tools, template, programming, cpp

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en4 Английский ExplodingKonjac 2026-05-04 18:33:44 36 Tiny change: 'tion\n\n![](/predown' -> 'tion\n\n![ ](/predown' (published)
en3 Английский ExplodingKonjac 2026-05-04 18:26:05 119
en2 Английский ExplodingKonjac 2026-05-04 18:21:55 273 Tiny change: 'CharlieV](/profile/CharlieV "Internati' -> 'CharlieV]("Internati'
en1 Английский ExplodingKonjac 2026-05-04 18:15:06 3416 Initial revision (saved to drafts)