哪些库使用通过编译时元编程技术实现的设计模式?

发布于 2024-08-31 03:57:23 字数 67 浏览 9 评论 0原文

有人知道有哪些库使用使用编译时技术(例如模板元编程)实现的设计模式吗?我知道 Loki 实现了一些,但我需要找到其他库。

Does anybody know of any libraries that use design patterns that are implemented using compile-time techniques e.g. template metaprogramming? I know that Loki implements a few but I need to find other libraries.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

顾忌 2024-09-07 03:57:23

Boost.Spirit 是一个相当大的。

Boost.Spirit is a pretty big one.

黯然#的苍凉 2024-09-07 03:57:23

这取决于您对哪种设计模式感兴趣。有些像“Active Object”和Dispose之类的设计模式在编译时很难实现。

“解释器”模式-> boost.ublas 和 blitz++ 都使用“表达式模板”

“桥接”模式 ->每个标准容器都带有一个“分配器”参数(Loki 的大部分也是桥接模式)

“策略”模式 -> STL 模板函数根据参数类型选择最佳实现。

所有这些中的唯一区别是模式的评估发生在编译器运行时,而不是可执行文件运行时。所以你需要稍微调整一下你的思路:模板就是程序,“C++编译器”运行并解释这个程序。该模板程序的输出是一个可供链接的目标文件。换句话说,当编译器运行时,模板代码的运行时是精确的。 C++ 模板是一种图灵完备的函数式语言,就像 lisp 或 XSLT 一样。

事实上,1993 年的第一个模板元程序的输出不是可执行文件,而是打印斐波那契数列或类似内容的一系列编译器错误。

It depends on what design pattern you are interested in. There are some like "Active Object" and Dispose that would have a hard time being implemented at compile time.

"interpreter" pattern -> boost.ublas and blitz++ both use "expression templates"

"bridge" pattern -> Every standard container takes an "allocator" argument (most of Loki is bridge patterns as well)

"strategy" pattern -> STL template functions choose the best implementation based on the argument types

The only difference in all of these is that the evaluation of the pattern happens when the compiler runs, rather then when the executable runs. So all you need is to adjust your thinking slightly: The templates are the program, and the "C++ compiler" runs and interprets this program. The output of this template program is an object file ready for linking. In other words, your template code's runtime is precisley when your compiler is running. C++ templates are a turing complete functional language, just like lisp or XSLT.

In fact the very first template metaprogram in 1993 had as its output not an executable, but a series of compiler errors that printed the fibonacii sequence or something like that.

清醇 2024-09-07 03:57:23

一些使用表达式模板的库:ublas、blitz、矩阵模板库、ftensor 或 Google C++ 模板矩阵以查找更多内容。

顺便说一句,ftensor 真的很灵活 http://www.gps.caltech .edu/~walter/FTensor/FTensor.pdf

Some libraries that use expression templates: ublas, blitz, matrix template Library, ftensor, or Google C++ template matrix to find even more.

by the way, ftensor is really slick http://www.gps.caltech.edu/~walter/FTensor/FTensor.pdf.

恋竹姑娘 2024-09-07 03:57:23

我认为您要求的库比使用设计模式的库更多地帮助使用设计模式,不是吗?

Boost 中有一些,但不是太多,比如 Flyweight - 管理大量高度冗余对象的设计模式。

尚未发布但已接受的库 Boost.Factory 和被拒绝的库 Boost.Singleton

还有一些实现 C++ 习惯用法的库,如 Boost.Pimpl(在审核计划中)、Scope Exit(已接受)、Memoizer。

I think that you are asking for libraries that help to use design pattern more that libraries using design patterns, isn't it?

There are some in Boost but not too much, like Flyweight - Design pattern to manage large quantities of highly redundant objects.

The not yet released but accepted library Boost.Factory and the rejected library Boost.Singleton

There are also some libraries that implements C++ idioms as Boost.Pimpl (on the review schedule), Scope Exit (accepted), Memoizer.

怎樣才叫好 2024-09-07 03:57:23

GPG 还好吗?

在 Loki 中实现的任何情况:
- 工厂摘要
- 工厂
- 辛格尔顿
- 访客
- Command

In boost Flyweight

在 STL 中你有迭代器和适配器,尽管我很确定它们不算数
由于是编译时?

原始规范有些模糊。

确保您没有将泛型编程(基于模板的实现)与其他编译时技术混淆。

有人知道上面的问题是什么意思吗?

Doen almal GPG hier?

Any case those implemented in Loki:
- Factory Abstract
- Factory
- Singleton
- Visitor
- Command

In boost Flyweight

In STL you have iterators, and adapters, although I'm pretty sure they don't count
due to being being compile-time?

The original specification is somewhat vague.

Make sure that you do not confuse generic programming (template-based implementations) with other compile-time techniques.

Anyone have a clue as to what the above question means?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文