我正在尝试使用括号来覆盖xslt中的xpath表达式中的默认运算符优先级而没有运气.例如:
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:exsl="http://exslt.org/common"
extension-element-prefixes="exsl"
version="1.0">
<xsl:output encoding="utf-8" standalone="yes"/>
<xsl:template match="/">
<xsl:apply-templates select="*"/>
</xsl:template>
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<!--these should work but don't-->
<xsl:template match="//(X|Y|Z)/AABBCC"/>
<xsl:template match="(book/author)[last()]"/>
</xsl:stylesheet>
Run Code Online (Sandbox Code Playgroud)
Visual Studio 2010不会编译此返回:
意外的标记'('在表达式.// - >(< - X | Y | Z)/ AABBCC中
意外的标记'('在表达式中. - >(< - book/author)[last()]
然而第二个例子来自MSDN:
http://msdn.microsoft.com/en-us/library/ms256086.aspx
许多参考文献都说你可以用这种方式使用括号:
http://saxon.sourceforge.net/saxon6.5.3/expressions.html
http://www.stylusstudio.com/xsllist/200207/post90450.html
http://www.mulberrytech.com/quickref/XSLT_1quickref-v2.pdf
这是一个xpath 1.0 vs 2.0的事情......还是还有其他我缺少的东西?如果它是一个xpath 2.0的东西,是否有一个很好的xpath 1.0方式来做同样的事情?
我不明白为什么在这种情况下无法推断出T:
template<class T>
class MyType
{
T * data;
};
class MyOtherType
{
};
template<typename T>
struct MyType_OutArg
{
typedef MyType<T> & type;
};
template<typename T>
void
DoSomething(typename MyType_OutArg<T>::type obj)
{
}
void func(MyType_OutArg<MyOtherType>::type obj)
{
DoSomething(obj);
}
Run Code Online (Sandbox Code Playgroud)
从GCC 4.7.1和-std = c ++ 14
<source>: In function 'void func(MyType_OutArg<MyOtherType>::type)':
26 : <source>:26:20: error: no matching function for call to 'DoSomething(MyType<MyOtherType>&)'
DoSomething(obj);
^
26 : <source>:26:20: note: candidate is:
19 : <source>:19:1: note: template<class T> void DoSomething(typename MyType_OutArg<T>::type)
DoSomething(typename MyType_OutArg<T>::type obj) …Run Code Online (Sandbox Code Playgroud) 我们有一个混合.NET 2.0和本机C++的应用程序.在我们的测试中,我们有一个模式可以自动循环一组项目.项目打开,运行,关闭,重复.这些步骤中的每一步都需要创建/销毁窗口(确切地说是winforms).最近我们在表演中遇到了一些奇怪的行为.运行几个小时后,打开和关闭部件减速(阻止gui线程并显示半画屏幕等).现在很容易将这个问题搞砸到资源泄漏...但是我们正在跟踪句柄和内存,虽然内存略有增长但没有任何迹象表明这个问题.手柄稳定.所以也许悬空的事件处理程序......仍然需要调查.但令我感到困惑的是,关闭应用程序并重新启动它并不能恢复最初的性能.在重新启动操作系统(赢得XP)之前,它仍然很慢,然后性能再次开始变得快速.这让我很困惑,因为我认为关闭应用程序将收回所有资源.有什么想法吗?
给出以下代码:
void doSomething(int one, int two, int three)
{
//something here
}
#define ONE 1,2,3
#define TWO(arg) doSomething(arg);
#define THREE(arg) TWO(arg)
void doSomethingElse()
{
TWO(ONE)
THREE(ONE)
}
Run Code Online (Sandbox Code Playgroud)
visual studio 2010具有以下预处理器输出(省略一些空白行):
void doSomething(int one, int two, int three)
{
}
void doSomethingElse()
{
doSomething(1,2,3);
doSomething(1,2,3);
}
Run Code Online (Sandbox Code Playgroud)
而gcc 4.2给出以下内容:
void doSomething(int one, int two, int three)
{
}
void doSomethingElse()
{
doSomething(1,2,3);
myFile.cpp:17:13: error: macro "TWO" passed 3 arguments, but takes just 1
TWO
}
Run Code Online (Sandbox Code Playgroud)
我不确定哪个是标准的,但我希望它像visual studio一样工作.有没有办法重构代码,以便它在两个编译器中以这种方式工作?
假设我的代码使用std :: array,我想这样做:
file:array
#pragma once
#ifdef MY_TOOLSET_HAS_STD_ARRAY
#include <array> //recursive include here?
#else
#include <boost/array.hpp>
namespace std
{
using boost::array;
}
#endif
Run Code Online (Sandbox Code Playgroud)
这样我的项目可以使用std :: array而无需关心编译器/平台.一个问题(至少)是当std :: array可用时,include将是递归的,当我真正想要的是(语义上)"包括如果这个包括不存在则将包括的头".
关于如何做到这一点的任何想法?我知道把boost :: array拉到std也可能被认为是不好的做法,所以我对这个问题也很感兴趣.
采取以下简单程序:
#include <fstream>
int main()
{
std::ifstream in(".");
int x;
if (in)
in >> x;
}
Run Code Online (Sandbox Code Playgroud)
在Redhat 6,gcc 4.4.7上运行,没有错误
在Ubuntu 14.04 LTS,gcc 4.8.2上运行,没有错误
在Redhat 7,gcc 4.8.2上我得到:
Run Code Online (Sandbox Code Playgroud)terminate called after throwing an instance of 'std::ios_base::failure' what(): basic_filebuf::underflow error reading the file Aborted (cored dumped)
我认为这与以下内容有关:https : //gcc.gnu.org/bugzilla/show_bug.cgi?id=53984
但是,我不明白为什么它可以在Ubuntu上运行。
有想法吗?
对于以下情况,类型扣除失败.如果我为someFunc指定模板参数,它会编译.我肯定会看到这是一个奇怪的情况,但如果我能让它发挥作用会很好.是否有另一种方法可以在没有提供模板参数的情况下编译它?C++ 17解决方案很好.
#include <type_traits>
template<typename T>
using choose_arg_type = typename std::conditional<std::is_fundamental<T>::value,T,const T &>::type;
template<typename T>
T someFunc(choose_arg_type<T> arg)
{
return arg + arg;
}
int main()
{
auto result = someFunc(0.0);
return 0;
}
Run Code Online (Sandbox Code Playgroud) 说你有一个像这样的功能:
double do_it(int m)
{
double result = 0;
for(int i = 0; i < m; i++)
result += i;
return result;
}
Run Code Online (Sandbox Code Playgroud)
如果您在编译时知道m,则可以执行以下操作:
template<size_t t_m>
double do_it()
{
double result = 0;
for(int i = 0; i < t_m; i++)
result += i;
return result;
}
Run Code Online (Sandbox Code Playgroud)
在优化时,这为诸如循环展开之类的事情提供了可能性。但是,有时您可能在编译时知道一些情况,而在运行时知道一些情况。或者,也许您有可以由用户更改的默认值...但是优化默认情况会很好。
我想知道是否有任何方法可以提供两个版本而基本上不复制代码或使用宏?
注意,以上是说明这一点的玩具示例。