小编ice*_*ime的帖子

一旦成为标准的一部分 - 将提升库失去其boost命名空间并将被移动到std?

一旦Boost库(我已经读过十个Boost库被认为是标准库的一部分)成为标准库的一部分 - 它是否会保留它的boost命名空间或代码最终会在std命名空间中?

如果是后者 - 你将如何解决代码中潜在的命名空间冲突.

干杯.

c++ standards boost c++11

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

如何在运行时确定c ++对象的内存

我试图在运行时确定对象的大小.sizeof不起作用,因为它在编译时返回大小.这是我的意思的一个例子:

class Foo 
{
public:
    Foo() 
    {
        c = new char[1024*1024*1024];
    }
    ~Foo() 
    { 
        delete[] c; 
    }

private:
    char *c;
};
Run Code Online (Sandbox Code Playgroud)

在这种情况下,sizeof(Foo)将是4个字节而不是〜1GB.如何在运行时确定Foo的大小?提前致谢.

c++ memory memory-management runtime

7
推荐指数
2
解决办法
4607
查看次数

logging.info和logging.getLogger().info之间有什么区别?

我是蟒蛇的新人.

如果logging.info()足以进行日志记录,为什么我们必须使用getLogger()方法实例化记录器?

python logging

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

Valgrind C++内存泄漏

我有这个可证明的代码:

#include <cstdlib>
#include <cstdio>

int main() {
    int ** matrix = NULL;
    int c = 1, input = 0;

    printf("Enter first row of the matrix:\n");
    while (!feof(stdin)) {
        input = fgetc(stdin);

        matrix = (int**) realloc(matrix, 1 * sizeof (int*));
        if (matrix == NULL) {
            printf("Troubles with memory allocation!\n");
            return 0;
        }
        matrix[0] = (int *) realloc(matrix[0], c * sizeof (int));
        matrix[0][c-1] = (int) input;

        c++;
    }

    free(matrix[0]);
    free(matrix);

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

这导致Valgrind出错,但我真的不知道这是什么意思以及如何解决它......任何人都可以给我一个建议吗?

==30031== 1 errors in context 1 of …
Run Code Online (Sandbox Code Playgroud)

c++ valgrind

6
推荐指数
1
解决办法
1894
查看次数

在boost :: lambda中使用boost :: format

出于某种原因,我无法使用boost::formatboost::lambda.这是(希望)可编译的代码简化:

#include <algorithm>
#include <iomanip>
#include <iostream>

#include <boost/assign/list_of.hpp>
#include <boost/format.hpp>
#include <boost/lambda/lambda.hpp>

namespace bl = boost::lambda;

int main()
{
    const std::vector<int> v = boost::assign::list_of(1)(2)(3);
    std::for_each(v.begin(), v.end(), bl::var(std::cout) << std::setw(10) << bl::_1);
    std::for_each(v.begin(), v.end(), bl::var(std::cout) << boost::format("%10d") % bl::_1);
}
Run Code Online (Sandbox Code Playgroud)
  • 第一个std::for_each产生预期的输出
  • 第二个std::for_each只输出没有任何数字的空格

这是为什么 ?我真的不熟悉boost::lambda所以我可能会错过这里明显的.

请不要建议std::copy基于答案:我的实际代码不起作用,std::vector但实际上是boost::fusion::vector(并且std::for_each实际上是a boost::fusion::for_each).

c++ boost-lambda boost-format

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

RegEx匹配正数

我需要编写一个正则表达式,只允许正数(整数或小数).我发现了这个:

/^(?!(?:0|0\.0|0\.00)$)[+]?\d+(\.\d|\.\d[0-9])?$/  
Run Code Online (Sandbox Code Playgroud)

但它只接受最多2位小数.我必须做出哪些更改,以便它可以接受任意数量的小数位?

在哪里可以找到学习正则表达式的好教程.

先谢谢

regex

5
推荐指数
2
解决办法
4万
查看次数

python的".format"函数

最近,我发现''.format函数非常有用,因为与%格式化相比,它可以提高可读性.试图实现简单的字符串格式化:

data = {'year':2012, 'month':'april', 'location': 'q2dm1'}

year = 2012
month = 'april'
location = 'q2dm1'
a = "year: {year}, month: {month}, location: {location}"
print a.format(data)
print a.format(year=year, month=month, location=location)
print a.format(year, month, location)
Run Code Online (Sandbox Code Playgroud)

虽然两个第一次打印的格式符合我的预期(是的,something=something看起来很难看,但这只是一个例子),最后一个会提高KeyError: 'year'.在python中有没有创建字典的技巧,所以它会自动填充键和值,例如somefunc(year, month, location)输出{'year':year, 'month': month, 'location': location}

我是python的新手,无法找到关于这个主题的任何信息,但是像这样的技巧会大大改善和缩小我当前的代码.

提前谢谢并原谅我的英语.

python string formatting dictionary

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

总是在异常时总是调用python调试器的一般方法

我希望post_mortem()在遇到异常时让我的调试器运行,不必修改我正在处理的源.我看到很多例子涉及在try/except块中包装代码,但我想让它始终运行,无论我在做什么.

我研究了一个python包装器脚本,但是它变得丑陋且几乎无法使用.

我使用pudb,它与pdb的API等价,所以pdb特定的答案很好.我在我的编辑器(vim)中运行代码,并希望在遇到异常时让pm出现.

python vim exception-handling pdb pudb

4
推荐指数
2
解决办法
297
查看次数

引用容器对象的子集

我有一个关于引用集合子集的快速问题.考虑我有一个对象矢量.现在我想创建另一个向量,它是此向量的子集,我不想创建对象子集的副本.

我正在考虑的方法之一是创建一个vector<auto_ptr<MyClass> >.这是一个好方法吗?如果您认为在这种情况下任何其他容器或习语或模式会有所帮助,请建议.谢谢

c++ auto-ptr

3
推荐指数
1
解决办法
1058
查看次数

Scrapy不会抓取所有页面

这是我的工作代码:

from scrapy.item import Item, Field

class Test2Item(Item):
    title = Field()

from scrapy.http import Request
from scrapy.conf import settings
from scrapy.selector import HtmlXPathSelector
from scrapy.contrib.linkextractors.sgml import SgmlLinkExtractor
from scrapy.contrib.spiders import CrawlSpider, Rule

class Khmer24Spider(CrawlSpider):
    name = 'khmer24'
    allowed_domains = ['www.khmer24.com']
    start_urls = ['http://www.khmer24.com/']
    USER_AGENT = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.97 Safari/537.22 AlexaToolbar/alxg-3.1"
    DOWNLOAD_DELAY = 2

    rules = (
        Rule(SgmlLinkExtractor(allow=r'ad/.+/67-\d+\.html'), callback='parse_item', follow=True),
    )

    def parse_item(self, response):
        hxs = HtmlXPathSelector(response)
        i = Test2Item()
        i['title'] = (hxs.select(('//div[@class="innerbox"]/h1/text()')).extract()[0]).strip(' \t\n\r') …
Run Code Online (Sandbox Code Playgroud)

python scrapy

3
推荐指数
1
解决办法
3997
查看次数