arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2510.08969cs.PLcs.SE
收藏

C++ 中基于概念(Concept)的泛型编程

Concept-Based Generic Programming in C++

Columbia University(哥伦比亚大学)

Bjarne Stroustrup

AI总结:

本文通过示例展示 C++ 中基于概念(Concept)的泛型编程技术,强调其作为语言核心部分的实用性,并阐述概念设计的关键理由与起源。

摘要:

我们提出编程技术,以说明使用概念(Concept)的 C++ 泛型编程的工具与原理。概念是 C++ 对泛型代码表达约束的方式。作为初始示例,我们提供了一个简单的类型系统,它消除了窄化转换,并在不增加不必要的记法或运行时开销的情况下提供范围检查。概念贯穿始终,用于为用户定义的类型系统扩展提供支持。其目的是展示它们的实用性和背后的基本思想,而非提供对 C++ 泛型编程语言支持或标准库广泛支持的详细或完整解释。泛型编程是 C++ 的组成部分,而非孤立的子语言。特别是,关键工具同时支持一般编程和泛型编程(例如,类型的统一记法、lambda、可变参数模板以及 C++26 静态反射)。最后,我们给出概念设计关键部分的设计理由和起源,包括使用模式、与面向对象编程的关系、值参数、记法、概念类型匹配和定义检查。

英文摘要:

We present programming techniques to illustrate the facilities and principles of C++ generic programming using concepts. Concepts are C++'s way to express constraints on generic code. As an initial example, we provide a simple type system that eliminates narrowing conversions and provides range checking without unnecessary notational or run-time overheads. Concepts are used throughout to provide user-defined extensions to the type system. The aim is to show their utility and the fundamental ideas behind them, rather than to provide a detailed or complete explanation of C++'s language support for generic programming or the extensive support provided by the standard library. Generic programming is an integral part of C++, rather than an isolated sub-language. In particular, key facilities support general programming as well as generic programming (e.g., uniform notation for types, lambdas, variadic templates, and C++26 static reflection). Finally, we give design rationales and origins for key parts of the concept design, including use patterns, the relationship to Object-Oriented Programming, value arguments, notation, concept type-matching, and definition checking.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑