An Empirical Evaluation Of C++ Generic Programming For Reducing Code Duplication

Authors

  • Mohammad Bani Younes Computer Science, Information Technology, Ajloun National University, Ajloun, Jordan, (corresponding author)
  • Issa Alsmadi Data Science and Artificial Intelligence, Information Technology, Ajloun National University, Ajloun, Jordan
  • Njood Aljarrah Computer Science, Information Technology, Ajloun National University, Ajloun, Jordan
  • Razan Obeidat Software Engineering, Information Technology, Ajloun National University, Ajloun, Jordan
  • Mohamed S. Sawah Department of Data Science and Artificial Intelligence, Faculty of Information Technology, Ajloun National University, P.O.43, Ajloun 26810, Jordan. Department of Information Systems, Al-Alson Higher Institute, Cairo, Egypt.

DOI:

https://doi.org/10.29284/sf7m6w45

Keywords:

C++, Code Reusability, Template Programming, Generic Programming, Function Templates, Class Templates, Standard Template Library (STL), Compile-Time Polymorphism, Template Metaprogramming.

Abstract

Code reusability is essential for building maintainable and scalable software, yet in C++, it must be achieved without compromising type safety or runtime efficiency. This study empirically evaluates C++ generic programming covering function and class templates, variadic templates, and template metaprogramming using STL-inspired design patterns, open-source project case studies, and controlled benchmarks. The results show that template-based designs reduce code duplication by 20–60% while generally maintaining performance comparable to that of inheritance-based alternatives. However, the analysis also reveals measurable engineering costs in template-heavy modules, including increased compilation time (15–30%) and binary size (5–20%) as instantiation counts proliferate. To address these usability and maintenance challenges, we evaluate C++20 Concepts, which improve interface clarity and reduce the length of template-related diagnostic messages by approximately 40%. Overall, the findings provide actionable guidance for adopting templates in large-scale systems by balancing reuse gains against performance, maintainability, and build-time constraints. These findings offer actionable guidance for adopting templates in large-scale C++ systems by balancing reuse gains against compilation and binary-size costs, supported by constrained designs such as C++20 Concepts.

References

[1] A. Imran and T. Kosar, "Software sustainability: a systematic literature review and comprehensive analysis," arXiv preprint arXiv:1910.06109, 2019.

[2] A. Mateen, S. Kausar, and A. R. Sattar, "A software reuse approach and its effect on software quality: An empirical study for the software industry, "arXiv preprint, arXiv:1702.00125, 2017.

[3] C. Gao, X. Hu, S. Gao, X. Xia, and Z. Jin, "The current challenges of software engineering in the era of large language models," ACM Transactions on Software Engineering and Methodology, vol. 34, no. 5, pp. 1–30, 2025.

[4] B. Stroustrup, Programming: Principles and Practice Using C++, 3rd ed. Boston, MA, USA: Addison-Wesley Professional, 2024.

[5] A. Alexandrescu, Modern C++ Design: Generic Programming and Design Patterns Applied. Boston, MA, USA: Addison-Wesley, 2001.

[6] S. Demeyer, "Maintainability versus performance: What’s the effect of introducing polymorphism," Universiteit Antwerpen, Edegem, Belgium, 2002.

[7] B. Stroustrup, The C++ Programming Language, 4th ed. Upper Saddle River, NJ, USA: Addison-Wesley, 2013.

[8] E. Gamma, R. Helm, R. Johnson, and J. Vlissides, Design Patterns: Elements of Reusable Object-Oriented Software. Reading, MA, USA: Addison-Wesley, 1995.

[9] J. Hughes, "Why Functional Programming Matters," Comput. J., vol. 32, no. 2, pp. 98–107, Apr. 1989, doi: 10.1093/comjnl/32.2.98

[10] R. W. Floyd, "The Paradigms of Programming," in ACM Turing Award Lectures, New York, NY, USA: ACM Press, 2007, pp. 131–142.

[11] O. J. Dahl, E. W. Dijkstra, and C. A. R. Hoare, Eds., Structured Programming. London, U.K.: Academic Press, 1972.

[12] B. Meyer, Object-Oriented Software Construction, 2nd ed. Upper Saddle River, NJ, USA: Prentice Hall, 1997.

[13] N. Dragoni et al., "Microservices: Yesterday, Today, and Tomorrow," IEEE Softw., vol. 34, no. 1, pp. 54–62, Jan./Feb. 2017, doi: 10.1109/MS.2017.11.

[14] L. Q. Lee and A. Lumsdaine, "Generic programming for high-performance scientific applications," Concurrency Comput.: Pract. Exper., vol. 17, no. 7–9, pp. 941–965, 2005, doi: 10.1002/cpe.851.

[15] J. C. Dehnert and A. Stepanov, “Fundamentals of generic programming,” in Generic Programming: Int. Seminar on Generic Programming, Dagstuhl Castle, Germany, Apr. 27–May 1, 1998, Selected Papers, Berlin, Germany: Springer, 2001, pp. 1–11.

[16] D. Abrahams and A. Gurtovoy, C++ Template Metaprogramming: Concepts, Tools, and Techniques from Boost and Beyond. Boston, MA: Addison-Wesley, 2004.

[17] A. Alexandrescu, Modern C++ Design: Generic Programming and Design Patterns Applied. Boston, MA, USA: Addison-Wesley, 2001.

[18] M. H. Austern, Generic Programming and the STL: Using and Extending the C++ Standard Template Library. Reading, MA, USA: Addison-Wesley, 1998.

[19] Y. Zhao, L. Xiao, A. B. Bondi, B. Chen, and Y. Liu, "A Large-Scale Empirical Study of Real-Life Performance Issues in Open Source Projects," IEEE Trans. Softw. Eng., vol. 49, no. 2, pp. 924–946, Feb. 2023, doi: 10.1109/TSE.2022.3164506.

[20] S. Unruh and E. V. Zudilova-Seinstra, "A Comparative Study of Template Metaprogramming and Object-Oriented Programming for High Performance Scientific Computing," in International Conference on Computational Science (ICCS), vol. 3991, Berlin, Germany: Springer, 2006, pp. 638–645.

[21] E. Kalliamvakou, G. Gousios, K. Blincoe, L. Singer, D. M. German, and D. Damian, "The promises and perils of mining GitHub," in Proc. 11th Working Conf. Mining Softw. Repositories (MSR), 2014, pp. 92–101.

[22] A. Alexandrescu, Modern C++ Design: Generic Programming and Design Patterns Applied. Boston, MA, USA: Addison-Wesley, 2001.

[23] M. B. Younes, O. A. Shqeer, I. Alsmadi, and N. Aljarrah, "Analyzing function overloading as a mechanism for compile-time polymorphism in modern C++," Eng. Technol. Appl. Sci. Res., vol. 16, no. 1, pp. 31004–31008, 2026.

Downloads

Published

2026-01-15

Issue

Section

Articles

How to Cite

[1]
M. B. Younes, I. Alsmadi, N. Aljarrah, R. Obeidat, and M. S. Sawah, “An Empirical Evaluation Of C++ Generic Programming For Reducing Code Duplication”, IJASIS, pp. 961–972, Jan. 2026, doi: 10.29284/sf7m6w45.

Share