量纲误用是科学计算应用程序中一种常见的错误,对计算结果的正确性影响很大。在此提出一种基于模板元编程的量纲检测方法TADA,能够有效完成C和C^++程序代码的量纲检测工作。该方法利用程序设计语言自身的模板元编程功能,通过定义相关的量纲模板及其计算和标注方法,依靠编译器在编译期间完成量纲分析和检测,无需任何运行开销,有效解决了传统量纲检测系统中解方程组的计算量瓶颈等问题。
Misuse of measurement units is a common mistake in many scientific computing applications. It greatly influences the correctness of the application results. TADA,a tool that effectively detects errors of this kind for C/C^++ programs is proposed. Making use of the function of template meta - programming in the language itself, TADA analyses the dimensional units and detects mismatches only by a standard C++ compiler in compile time without any runtime overhead. It avoids the computational bottleneck of solving linear equations introduced by traditional methods.