小编Mey*_*sam的帖子

为什么auto_ptr构造不能使用= syntax

我遇到了一个对我没有多大意义的编译器错误:

#include <memory>
using namespace std;

auto_ptr<Table> table = db->query("select * from t");
Run Code Online (Sandbox Code Playgroud)

错误:从'Table*'转换为非标量类型'std :: auto_ptr <Table>'

但是,以下行确实有效:

auto_ptr<Table> table(db->query("select * from t"));
Run Code Online (Sandbox Code Playgroud)

这个构造函数的定义是什么阻止它像我期望的那样工作?我认为初始化声明使用了构造函数.

这是我auto_ptr的构造函数(来自SGI STL):

explicit
auto_ptr(element_type* __p = 0) throw() : _M_ptr(__p) { }
Run Code Online (Sandbox Code Playgroud)

c++ gcc stl auto-ptr

9
推荐指数
3
解决办法
3330
查看次数

CMake:如何拥有复制文件的目标

我在每次编译后使用以下命令将配置文件复制到构建目录中.

# Gather list of all .xml and .conf files in "/config"
file(GLOB ConfigFiles ${CMAKE_SOURCE_DIR}/config/*.xml
                      ${CMAKE_SOURCE_DIR}/config/*.conf)

foreach(ConfigFile ${ConfigFiles})
  add_custom_command(TARGET MyTarget PRE_BUILD
                     COMMAND ${CMAKE_COMMAND} -E
                         copy ${ConfigFile} $<TARGET_FILE_DIR:MyTarget>)
endforeach()
Run Code Online (Sandbox Code Playgroud)

每次编译项目时都会触发此操作.是否可以在CMakeLists.txt中创建目标来复制文件而无需编译任何东西?像"制作副本"之类的东西.

cmake

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

与参数一起使用时如何优化"OR"子句的使用(SQL Server 2008)

我想知道是否有任何明智的方法来重写以下查询,以便优化器使用列上的索引?

Create Procedure select_Proc1
    @Key1 int=0,
    @Key2 int=0
As
BEGIN
    Select key3
    From Or_Table
    Where (@key1 =0 OR Key1 =@Key1) AND
          (@key2 =0 OR Key2 =@Key2)
END
GO
Run Code Online (Sandbox Code Playgroud)

即使WHERE子句中的列被索引覆盖,SQL Server也无法使用这些索引.这提出了一个问题,即是否有任何东西"阻止"索引的使用.这个问题的答案是肯定的 - 罪魁祸首是参数和"或"条件.索引不包含这些参数,这意味着SQL Server无法使用任何索引来评估"@ key1 = 0"(同样适用于@ key2 = 0的条件).实际上,这意味着SQL Server无法使用索引来评估子句"@ key1 = 0 OR Key1 = @ key1"(因为"OR"子句是两个条件所涵盖的行的并集).同样的原则也适用于其他条款(re.key2).这导致SQL Server得出结论,没有索引可用于提取行,使SQL Server能够利用下一个最佳方法 - 聚簇索引扫描

如您所见,如果WHERE子句中的谓词为"OR",则SQL优化器将不使用列上的索引.针对此问题的一种解决方案是使用IF子句为所有可能的参数组合分隔查询.

请阅读这篇简短的文章,以便更好地了解问题:http://www.sql-server-performance.com/articles/per/optimize_or_clause_p1.aspx

现在我的问题是,如果可能的组合只有三到四个,我们该怎么办?为每个组合编写单独的查询似乎不是一个合理的解决方案.这个问题还有其他解决方法吗?

sql-server indexing performance clause

8
推荐指数
2
解决办法
1万
查看次数

是否一个分支合并到干线被认为关闭?

将它合并到树干后是否需要明确关闭分支?或者在合并之后隐含地被认为是封闭的?在前一种情况下,我应该怎么做才能关闭分支机构?这是否意味着我必须删除它?

svn tortoisesvn branching-and-merging

8
推荐指数
1
解决办法
3531
查看次数

CMake:"make depend"的用法是什么?

生成的目标之一cmakedepend:

以下是此Makefile的一些有效目标:
... all(默认情况下,如果没有提供目标)
... clean
... depend
... edit_cache
... rebuild_cache

执行"make depend"会产生什么影响?

c++ makefile cmake target

8
推荐指数
1
解决办法
1850
查看次数

如何获取进程的内存使用百分比?

使用以下代码,我可以获得MiB中给定进程的内存消耗:

def memory_usage_psutil():
    # return the memory usage in MB
    import psutil
    process = psutil.Process(os.getpid())
    mem = process.get_memory_info()[0] / float(2 ** 20)
    return mem
Run Code Online (Sandbox Code Playgroud)

如何更改此值以返回内存消耗百分比?

更新:我需要在终端中为特定进程%MEM执行top命令时获取列的当前值.

示例:我需要此函数返回14.2以获取VirtualBox进程的进程ID.

在此输入图像描述

python linux psutil

8
推荐指数
1
解决办法
1万
查看次数

是否可以从参数列表中删除项目?

def foo(name, *args, **kwargs):
Run Code Online (Sandbox Code Playgroud)

*args如果它的长度 ( len(args)) 大于 2,我需要删除 的前两个参数。可以这样做吗?

这就是我需要这样做的原因:我有以下功能:

def foo(name, xml='my.xml', xsd='my.xsd', *otherfiles):
    print('name: ' + name)
    print('xml: ' + xml)
    print('xsd: ' + xsd)
    print(otherfiles)
Run Code Online (Sandbox Code Playgroud)

我需要向该函数的参数添加一个可选的布尔参数,而不破坏向后兼容性。所以我将函数更改为:

def foo2(name, *otherfiles, **kwargs):
    kwargs.setdefault('relativePath', True)
    if len(otherfiles)>0:
        xml = otherfiles[0]
    else:
        kwargs.setdefault('xml', 'my.xml')
        xml = kwargs['xml']

    if len(otherfiles)>1:
        xsd = otherfiles[1]
    else:
        kwargs.setdefault('xsd', 'my.xsd')
        xsd = kwargs['xsd']
    print('name: ' + name)
    print('xml: ' + xml)
    print('xsd: ' + xsd)
    print(otherfiles)
Run Code Online (Sandbox Code Playgroud)

foo现在我通过检查和 的输出是否foo2相同来测试向后兼容性:

foo('my_name', '../my.xml', …
Run Code Online (Sandbox Code Playgroud)

python python-2.7

8
推荐指数
1
解决办法
1万
查看次数

如何用css突出两个文本的区别?

我知道如何使用此脚本使用CSS突出显示文本的一部分:

span.highlight {
    background-color: #B4D5FF;
}
Run Code Online (Sandbox Code Playgroud)

现在我想强调两个字符串的区别.例如,给出以下两个字符串:

这是第123号

这是124号

我需要像我在这里展示的那样突出显示文本.有人可以帮助我实现这个目标吗?

span.highlight {background-color: #B4D5FF}
Run Code Online (Sandbox Code Playgroud)
<p>this is number 123</p>
<p>
th<span class="highlight">at</span> is number 12<span class="highlight">4</span>
</p>
Run Code Online (Sandbox Code Playgroud)

html javascript css jquery

8
推荐指数
2
解决办法
7569
查看次数

Xamarin“Resource.Layout”不包含“Tabbar”错误的定义

我已经创建了一个基本xamarin.forms项目(使用 PCL 代码共享策略),并且在以下两行中出现错误MainActivity::OnCreate()

TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;
Run Code Online (Sandbox Code Playgroud)

CS0117“Resource.Layout”不包含“Tabbar”的定义
CS0117“Resource.Layout”不包含“工具栏”的定义

资源文件以Resources\layout\Tabbar.axml和 的形式存在,并且Resources\layout\Toolbar.axml它们的构建操作都设置为AndroidResource.

我怀疑我的 android SDK 安装有问题。目前安装了以下软件包:

在此处输入图片说明

但是RunVisual Studio 2015 中的按钮仍然显示Android 6.0 API 23并且无法更改它:

在此处输入图片说明

我还将Target FrameworkAndroid 项目的版本设置为 7.1:

在此处输入图片说明

项目结构如下:

在此处输入图片说明

我已经按照本教程逐步创建了示例项目。

我怎样才能修复错误?

c# xamarin xamarin.forms visual-studio-2015 android-sdk-manager

8
推荐指数
1
解决办法
1万
查看次数

Boost测试:如何编写参数化测试用例

我有一个加速测试案例.无论参数如何,都会执行此测试用例的大多数行.但是有些部分是根据提供的参数执行的.我想避免编写两个单独的测试用例,除了一些小部分外几乎完全相同.所以我需要使用类似以下方法的方法来创建参数化测试用例:

BOOST_FIXTURE_TEST_CASE(caseA, Fixture)
{
    TestFunction("parameterA");
}

BOOST_FIXTURE_TEST_CASE(caseB, Fixture)
{
    TestFunction("parameterB");
}

void TestFunction(string param)
{
    // ...
    // lots of common checks regardless of parameters
    // ...
    if(param == "parameterA")
        BOOST_CHECK(...);
    else if(param == "parameterB")
        BOOST_CHECK(...);
}
Run Code Online (Sandbox Code Playgroud)

有没有其他方法可以更方便的方式实现我的目标?我可以找到BOOST_PARAM_CLASS_TEST_CASE宏,但我不确定它在这种情况下是否相关.

boost unit-testing boost-test parameterized-unit-test

7
推荐指数
1
解决办法
2068
查看次数