函数模板作为一种泛型编程方法,对科学与工程计算具有重要现实意义.首先,探讨了C++函数模板的实现机制,揭示了函数模板与重载函数间的关系;运用Fortran 90泛型接口块结合外部例程,对C++重载函数进行了模拟;然后,在C++环境中添加包装子以实例化函数模板,并将函数模板实例转化成接口一致的"重载"例程,进而在Fortran 90环境中使用C++函数模板.辅以示例程序,对相关的处理方法给予详细说明,也为其它语言借用C++函数模板提供了借鉴.
The function template is a kind of generic programming, which possesses important practical signifi- cance in scientific and engineering computing. First,the implementing mechanism of C ++ function template is explored,and the relationship between function templates and overloaded functions is disclosed. C ++ overloa- ded functions are modeled with the generic interface block plus external procedures of Fortran 90. Then, a wrapper of C ++ function templates is appended in order to instantiate function templates, convert function template instances into "overloaded" procedures, and make use of C ++ function templates in Fortran 90. The above-mentioned methods are particularly demonstrated with a demo. The research will also be helpful in ap- plying C ++ function templates in other languages.