小编use*_*078的帖子

在xpath/xslt中使用括号

我正在尝试使用括号来覆盖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方式来做同样的事情?

xslt xpath

11
推荐指数
2
解决办法
7043
查看次数

无法推导出模板参数

我不明白为什么在这种情况下无法推断出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)

c++ templates

9
推荐指数
1
解决办法
371
查看次数

应用中的性能下降很奇怪

我们有一个混合.NET 2.0和本机C++的应用程序.在我们的测试中,我们有一个模式可以自动循环一组项目.项目打开,运行,关闭,重复.这些步骤中的每一步都需要创建/销毁窗口(确切地说是winforms).最近我们在表演中遇到了一些奇怪的行为.运行几个小时后,打开和关闭部件减速(阻止gui线程并显示半画屏幕等).现在很容易将这个问题搞砸到资源泄漏...但是我们正在跟踪句柄和内存,虽然内存略有增长但没有任何迹象表明这个问题.手柄稳定.所以也许悬空的事件处理程序......仍然需要调查.但令我感到困惑的是,关闭应用程序并重新启动它并不能恢复最初的性能.在重新启动操作系统(赢得XP)之前,它仍然很慢,然后性能再次开始变得快速.这让我很困惑,因为我认为关闭应用程序将收回所有资源.有什么想法吗?

.net performance

5
推荐指数
1
解决办法
295
查看次数

gcc与visual studio宏扩展

给出以下代码:

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一样工作.有没有办法重构代码,以便它在两个编译器中以这种方式工作?

c++ gcc visual-studio-2010 c-preprocessor

5
推荐指数
1
解决办法
1596
查看次数

在c ++中,如何使用回退来包装默认标头

假设我的代码使用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也可能被认为是不好的做法,所以我对这个问题也很感兴趣.

c++ boost c++11

5
推荐指数
1
解决办法
256
查看次数

意外的std :: io_base :: failure异常

采取以下简单程序:

#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上我得到:

terminate called after throwing an instance of 'std::ios_base::failure'
  what(): basic_filebuf::underflow error reading the file
Aborted (cored dumped)
Run Code Online (Sandbox Code Playgroud)

我认为这与以下内容有关:https : //gcc.gnu.org/bugzilla/show_bug.cgi?id=53984

但是,我不明白为什么它可以在Ubuntu上运行。

有想法吗?

c++ gcc redhat

5
推荐指数
1
解决办法
851
查看次数

有什么方法可以解决这种类型的扣除?

对于以下情况,类型扣除失败.如果我为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)

c++ templates

4
推荐指数
1
解决办法
95
查看次数

在C ++中,是否可能使用带有或不带有编译时间常数的相同代码?

说你有一个像这样的功能:

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)

在优化时,这为诸如循环展开之类的事情提供了可能性。但是,有时您可能在编译时知道一些情况,而在运行时知道一些情况。或者,也许您有可以由用户更改的默认值...但是优化默认情况会很好。

我想知道是否有任何方法可以提供两个版本而基本上不复制代码或使用宏?

注意,以上是说明这一点的玩具示例。

c++

4
推荐指数
1
解决办法
172
查看次数