我已经迷失在boost property_tree的头文件中,并且由于缺少关于较低层的文档,我决定问一下简单的方法是覆盖流转换器来改变如何解析布尔值.
问题是在属性树的输入端有用户,他们可以修改配置文件.可以通过多种方式指定布尔值,例如:
dosomething.enabled=true
dosomething.enabled=trUE
dosomething.enabled=yes
dosomething.enabled=ON
dosomething.enabled=1
Run Code Online (Sandbox Code Playgroud)
默认行为是检查0或1,然后使用
std::ios_base::boolalpha
Run Code Online (Sandbox Code Playgroud)
让流尝试以适当的方式解析当前语言环境的值...如果我们尝试将配置文件发送给国际客户,这可能是疯了.
那么什么是覆盖这种行为或bool的最简单方法呢?不仅最容易实现,而且最容易使用 - 因此我的类的用户从iptree派生而来不需要为布尔值做一些特殊的事情.
谢谢!
我在这个陌生的领域徘徊,并且我想从Danny Kalev关于此事的教程中尝试一个简单的例子.代码非常简单:
template<> struct Count<> { static const int value = 0;};
template<typename T, typename... Args>
struct Count<T, Args...> //partial specialization
{
static const int value = 1 + Count<Args...>::value;
};
Run Code Online (Sandbox Code Playgroud)
但gcc 4.4.7甚至4.7.0抱怨(尽管-std = c ++ 0x -std = gnu ++ 0x flags):
/src/tests/VTemplates.h:12:8: error: 'Count' is not a template
/src/tests/VTemplates.h:12:18: error: explicit specialization of non-template 'Count'
/src/tests/VTemplates.h:16:8: error: 'Count' is not a template
/src/tests/VTemplates.h:16:26: error: 'Count' is not a template type
Run Code Online (Sandbox Code Playgroud)
我错过了什么?