【24h】

Compile time recursive objects in C++

机译:C ++中编译时间递归对象

获取原文

摘要

The article explores the possibilities of generic programming offered by the template features of C++. We define compile time recursive objects as instances of class templates which contain other instances of the same template as member variables. With such templates we can define containers that contain objects of arbitrary types, but where the type of each element is known at compile time. The structure of the container is therefore fixed. The technique mimics the polymorphism achieved with dynamic binding and inheritance using static binding and template specialisation. It is obviously less flexible but offers considerable performance gains at runtime. We give the template definitions for compile time recursive lists and explain how to perform operations on these lists. As an example application, we use compile time lists in the definition of templates for special sparse vectors and matrices. In these vectors and matrices, the sparseness pattern can be arbitrary but must be known at compile time. The tracking of zero and nonzero elements is performed at compile time. This allows the programmer to use abstract vector and matrix expressions and still reach performance equal to hand coded operations. This is possible since the compiler can locate the elementary expressions between zero entries and discard them entirely from the resulting code.
机译:文章探讨了C ++的模板功能提供的通用编程的可能性。我们将编译时递归对象定义为包含与成员变量相同的模板的其他实例的类模板的实例。使用这种模板,我们可以定义包含任意类型的对象的容器,但是每个元素的类型在编译时都是已知的。因此,容器的结构是固定的。该技术模仿了使用静态结合和模板专业化的动态结合和遗传实现的多态性。它显然不那么灵活,但在运行时提供了相当大的性能。我们为编译时间递归列表提供模板定义,并解释如何在这些列表上执行操作。作为示例应用程序,我们在特殊稀疏向量和矩阵的模板定义中使用编译时列表。在这些向量和矩阵中,稀疏模式可以是任意的,但必须在编译时已知。在编译时执行零和非零元素的跟踪。这允许程序员使用抽象矢量和矩阵表达,并且仍然达到等于手工编码操作的性能。这是可能的,因为编译器可以在零条目之间找到基本表达式并完全从结果代码丢弃它们。

著录项

相似文献

  • 外文文献
  • 中文文献
  • 专利
获取原文

客服邮箱:kefu@zhangqiaokeyan.com

京公网安备:11010802029741号 ICP备案号:京ICP备15016152号-6 六维联合信息科技 (北京) 有限公司©版权所有
  • 客服微信

  • 服务号