我在gcc-4.9.2上有一个奇怪的编译错误,其中相同的代码在其他编译器上运行,例如gcc-4.8或任何我可以抓住的clang.该问题与非类型模板参数有关.所以考虑一下:
#include <iostream>
#include <cstddef>
int templateParam;
template <int &D> struct TestTemplate {
int value() {}
};
template <> int TestTemplate<templateParam>::value() {
return templateParam;
}
TestTemplate<templateParam> testVariable;
int main() {
std::cout << testVariable.value() << "\n";
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我用gcc-4.9.2得到以下错误:
prog.cpp:10:17: error: prototype for 'int TestTemplate<D>::value() [with int& D = (* & templateParam)]' does not match any in class 'TestTemplate<(* & templateParam)>'
template <> int TestTemplate<templateParam>::value() {
^
prog.cpp:7:9: error: candidate is: int TestTemplate<D>::value() [with int& D = (* …Run Code Online (Sandbox Code Playgroud) 如何过滤掉某些类型的元素,这些元素没有具有魔术值的属性并保留文档的其余部分?所有这些使用xmlstarlet?
我到底要做的是:
cat << EOF > database.xml
<?xml version="1.0"?>
<database>
<some name="A" />
<some name="B" />
<some name="C" />
<text>this is some text to be applied...</text>
<project>
<test deeper="structure"/>
</project>
</database>
EOF
Run Code Online (Sandbox Code Playgroud)
和
xmlstarlet sel -t -m "*" -c "*[not(self::some[@name != 'A'])]" database.xml
Run Code Online (Sandbox Code Playgroud)
产量
<some name="A"/><text>this is some text to be applied...</text><project>
<test deeper="structure"/>
</project>
Run Code Online (Sandbox Code Playgroud)
但这隐藏了我的宝贵<database> tag.除了缩进,这不是一个问题...并且当<some>不是例如<database>孩子的直接后裔时不起作用<project>.
我想是数据库,因为它是,但都<some>删除,除了指定的一个A:
<database>
<some name="A" /> …Run Code Online (Sandbox Code Playgroud)