1
2
听起来您正在尝试编写另一种形式的printf()。我不确定这是个好主意,但是如果你决定这样做,你一定要把它作为一个自由函数来写,因为操纵器的问题(与使用格式字符串格式化无关)已经消失了。我还将避免从模板开始,并简单地设计和编写字符串版本:
在编写这样一个函数之前,您必须在您的头脑中非常清楚它的语义是什么,我还不相信您是这样的。 |
2
2
你可以看看 boost::format 图书馆。 这样的事情应该管用(如果你能负担得起先把绳子分开的话)
|
3
0
这里有两个问题。 其中一个处理流操纵器,遵循引用。 另一个处理格式问题。 格式化是很困难的,尤其是您指示它的方式,因为它涉及到能够解析格式并生成一个AST表示,然后调用该表示来实际格式化字符串。解析意味着您需要定义一个小语法等… 有一些库像boost.spirit处理解析/生成,它们比“simple”boost.format(它本身并不那么简单)复杂得多。 现在,你能放弃解析吗?
此类的优点是多方面的:
然后,您可以通过创建一个小的格式化引擎来对格式执行相同的操作。
这里,你放弃解析。当然,这意味着格式是硬编码的… |
4
0
这是我所做的初步解决方案。唯一的问题是我仍然不能将它模板化。如果我这样做了,那么给图片格式化程序打电话应该是
|
John Smith · Java按值对映射进行分组,其中值为列表 1 年前 |
r3k0j · 在c++中有没有办法将输入字符串转换为输入流? 2 年前 |
Ankur · 猛击猫管据称行为不端 2 年前 |
Ksenia Alexeeva · 什么是产量控制器。流动 2 年前 |
tooFastForSatan · 组合两个流并调用方法 2 年前 |
Logan Lee · 通过在jq中一对一比较两个流进行过滤 2 年前 |
Lev · 使用jOO按属性总结BigDecimal分组 6 年前 |