摘 要: C++11、C++14、C++17等新标准发布后,涌现出许多泛型抽象工厂的设计方案。不过,一般泛型抽象 工厂的设计,都要求入参列表与用参列表必须一致。本文将在以往设计的基础之上,基于闭包封装和序列展开、使用 C++1x的std::integer_sequence、lambda表达式、tuple等新技术,通过数据结构和代码设计的优化,给出一种“可选 用参泛型抽象工厂”的实现方式。测试结果显示,该方式复用性更好、更为精简高效,优雅地实现了对产品类型可变、 异类组合、参数可变、可选用参等需求的支持。该实现方式及代码具有较强实用价值,可以实际应用到软件项目中。 |
关键词: 闭包封装;序列展开;integer_sequence;可选用参;泛型抽象工厂 |
中图分类号: TP311.1
文献标识码: A
|
基金项目: 国家自然科学基金(61202195),四川省教育厅科研基金(13ZA0198). |
|
Implementation of Generic Abstract Factory of Optional Reference Parameter Based on Closures Encapsulation and Sequence Expansion |
MIN Jun,QIN Fengqing1,2
|
1.( 1.Library, Yibin University, Yibin 644000, China;2. 2.Recruitment and Employment Office, Yibin University, Yibin 644000, China)
|
Abstract: After the release of new standards,such as C++11,C++14,and C++17,many designs of generic abstract factory have emerged.However,the design of general generic abstract factory requires the import parameter list and the reference parameter list to be consistent.Based on the previous design,this paper proposes an implementation of Generic Abstract Factory of Optional Reference Parameter based on closures encapsulation and sequence expansion.This scheme have implemented a configurable object factory by using new technologies such as C++1x std::integer_sequence,lambda expressions,tuple,optimizing data structures and code design.The test results show that the scheme is more reusable,more simplified and efficient.The scheme can gracefully implements support for variable product types,heterogeneous combinations,variable parameters,and optional reference parameter.This scheme and code have more practical values and can actually be applied in software projects. |
Keywords: closures encapsulation;sequence expansion;integer_sequence;optional reference parameter;generic abstract factory |