使用泛型概念对领域知识进行抽象是泛型程序设计方法的基础.在新的C++0x标准中泛型概念将成为一个新的语言设施,这将为设计可复用、可扩展的泛型软件提供坚实的基础.为了更好地利用C++0x的新特性,有必要识别C++遗产代码中的泛型概念,并通过重构得到符合C++0x标准的代码.文中提出了一种基于代码静态分析的泛型概念自动识别方法,通过对泛型程序中类型参数的使用分析,从遗产代码中提取有效表达式约束和关联类型约束,进而推导出泛型概念.将该方法应用于C++标准模板库STL,可以识别出STL算法中绝大部分潜在的泛型概念,表明该方法有助于识别遗产代码中的泛型概念.
Using Concepts to abstract domain knowledge is the basis for generic programming. Concept will be a new language feature in C++0x, which provides solid base for developing reusable and extendable generic software. To make better use of new generic programming features of C++0x, it is necessary to identify Concepts in legacy C++ programs, and refactor them to C++0x programs. This paper presents an automatic method to identify Concepts with static analysis, analyzes the usages of type parameters in legacy programs to extract valid expression constraints and associate type constraints. Concepts can be inferred by these constraints. The approach is applied to the C++ Standard Template Library to identify most of the potential Concepts in STIr. The study convinces that this method is helpful to identify Concepts in legacy C++ programs.