小编seh*_*ehe的帖子

在Vim中删除单词组

我在vim编辑python文件,你怎么能删除序列throw=it,?在线搜索后,我看到命令daw,但这不适用于这个单词组.

one two three throw=it, now
Run Code Online (Sandbox Code Playgroud)

vim

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

每个附加条件

我想知道:有没有可能为每个添加额外的条件?我正在考虑类似的事情:

int i=0;
for(auto &it : list; i++)
    if(it.ID == 25)
        return i;
Run Code Online (Sandbox Code Playgroud)

或者

for(auto &it : list, int i=0; i++)
    if(it.ID == 25)
        return i;
Run Code Online (Sandbox Code Playgroud)

c++ c++11

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

我需要从Bitbucket Git repo中检出单个文件夹

我有一个包含大约20个文件夹的repo,当我从SVN转换为Git时创建.是否可以从Git存储库(在Bitbucket上)签出单个文件夹?或者我必须将每个文件夹作为单独的回购?

git bitbucket

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

boost asio Deadline_timer async_wait(N秒)在N秒内两次导致操作取消

我想要的是当一个消息队列接收到一个 int N 时,处理函数将在 N 秒后被调用。下面是我的代码。

如果两个近消息队列的持续时间秒数大于 int N,则运行正常,但是当两个接收到的消息队列之间的持续时间秒数小于 N 时,处理程序将在一个处理程序中打印“操作已取消”,这不是我想要的想。

如果您有任何帮助,我将不胜感激。

#include <boost/asio.hpp>
#include <zmq.h>
#include <boost/thread.hpp>
#include <iostream>

boost::asio::io_service io_service;

void* context = zmq_ctx_new();
void* sock_pull = zmq_socket(context, ZMQ_PULL);


void handler(const boost::system::error_code &ec) {
    std::cout << "hello, world" << "\t" << ec.message() << std::endl;
}

void run() {
    io_service.run();
}

void thread_listener() {

     int nRecv;
     boost::asio::deadline_timer timer(io_service, boost::posix_time::seconds(0));
     while( true ) {
         zmq_recv(sock_pull, &nRecv, sizeof(nRecv), 0);
         std::cout << nRecv << std::endl;
         timer.expires_from_now(boost::posix_time::seconds(nRecv));
         timer.async_wait(handler);
     }

 }

 int main(int argc, …
Run Code Online (Sandbox Code Playgroud)

c++ boost-asio zeromq

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

提升进程间和valgrind

这是我用来在共享内存上分配映射的一段代码,我使用的是 boost::interprocess 和托管共享内存段,现在的问题是我遇到了内存泄漏。下面给出的是顶部输出。

顶部输出:

PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
1.  27594 tpmon     20   0 46132 2140 1664 S  0.0  0.0   0:00.00 test_stub
2.  27594 tpmon     20   0 46132 2176 1664 S  0.0  0.0   0:00.01 test_stub
3.  27594 tpmon     20   0 46264 2248 1664 S  0.0  0.0   0:00.01 test_stub
4.  27594 tpmon     20   0 46264 2280 1664 S  0.0  0.0   0:00.01 test_stub
Run Code Online (Sandbox Code Playgroud)

从顶部输出可以明显看出常驻内存在不断增加,在共享内存映射中,我只有下面列出的条目,作为三元组:

Deb0 0 150520 DEB1 1 150520 Deb10 10 150520 Deb11 11 …

c++ memory boost valgrind

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

从boost :: asio :: streambuf到std :: string的高效数据副本

我需要将(boost :: asio::) streambuf的内容复制到std :: string.

以下代码有效,但我认为_msg和临时std :: string之间存在不必要的副本:

Msg (boost::asio::streambuf & sb, size_t bytes_transferred) :
    _nBytesInMsg    (bytes_transferred)
{
    boost::asio::streambuf::const_buffers_type buf = sb.data();

    _msg = std::string(
        boost::asio::buffers_begin(buf),
        boost::asio::buffers_begin(buf) + _nBytesInMsg);
}
Run Code Online (Sandbox Code Playgroud)

我尝试用以下内容替换:

     _msg.reserve(_nBytesInMsg);
     std::copy(
        boost::asio::buffers_begin(buf),
        boost::asio::buffers_begin(buf) + _nBytesInMsg,
        _msg.begin()
    );
Run Code Online (Sandbox Code Playgroud)

在编译时,它不会将任何内容复制到_msg字符串.

编译器(gcc4.4.7)会优化这种情况 - 例如将streambuf直接复制到_msg而不使用临时的吗?

是否有一个迭代器,我可以使用boost :: asio :: streambuf :: const_buffers_type,以使std :: copy工作?

c++ boost boost-asio c++11

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

C++用户输入限制,没有"goto"正确重试

我有以下代码:

qstn:
  cout << "Input customer's lastname: ";
  getline(cin, lname);

  if (lname.find_first_not_of("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ") != string::npos) {
      cout << "You can only input alpha here!\n";
      cin.clear();
      goto qstn;
  } else if (lname.empty()) {
      cout << "Please enter your firstname!\n";
      cin.clear();
      goto qstn;
  }

  int lnamel = lname.length();
  int strl = str.length();
  int is = 0;

  for (int i = 1; i < strl;) {
      i++;
      is++;

      if (lname[i] == lname[is] && lname[i] == ' ' || lname[0] == ' ') { …
Run Code Online (Sandbox Code Playgroud)

c++ validation iostream goto istream

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

如何编写一个boost :: spirit :: qi解析器来解析从0到std :: numeric_limits &lt;int&gt; :: max()的整数范围?

我尝试使用qi::uint_parser<int>()。但这是一样的qi::uint_。它们都匹配从0到的整数std::numeric_limits<unsigned int>::max()

qi::uint_parser<int>()设计成这个样子?我应该使用什么解析器来匹配从0到的整数范围std::numeric_limits<int>::max()?谢谢。

c++ parsing numeric boost-spirit boost-spirit-qi

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

使用语义操作填充嵌套结构

(从Spirit-general邮件列表中解除的问题)

你好,

我正在使用精神气的解析器.语法运行良好,但是我有一些问题用Semantic Actions填充我的struct实例.

使用直接结构属性,如"Request.id"和"Request.url",代码正常工作.但我不知道如何填充嵌套结构"Info"中的属性,也不知道如何在"Request.list"中推送值.

这是我的代码(要解析的字符串可以包含任何顺序的值):

#include <boost/spirit/include/qi.hpp>
#include <boost/fusion/include/adapt_struct.hpp>
#include <boost/spirit/include/phoenix.hpp>

#include <iostream>
#include <vector>
#include <string>

struct Request
{
    std::string id;
    std::string url;
    std::vector<std::string> list;

    struct Info
    {
        std::string id;
        std::string desc;
    };
    Info info;
};

BOOST_FUSION_ADAPT_STRUCT(
    Request,
    (std::string, id)
)

template <typename Iterator>
struct request_parser : boost::spirit::qi::grammar<Iterator, Request(), boost::spirit::ascii::space_type>
{      
        request_parser() : request_parser::base_type(start)
        {
            using namespace boost::spirit::qi;
            namespace ascii = boost::spirit::ascii;
            namespace phx = boost::phoenix;

            quoted_string %= lexeme['"' >> +(char_ - '"') >> '"'];

            start …
Run Code Online (Sandbox Code Playgroud)

c++ parsing boost-spirit boost-spirit-qi

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

使用 BOOST 进程在单独的线程中读取子进程标准输出

我有一个主程序,它使用 boost 进程库来生成一个打印的子进程

Hello World !
Run Code Online (Sandbox Code Playgroud)

每 5 秒在其标准输出上。

我想在主进程中读取/监视子进程的标准输出,当它与在主程序中执行其他操作一起可用时。

我已经尝试了boost asynchronous IOhttp://www.boost.org/doc/libs/1_66_0/doc/html/boost_process/tutorial.html)的示例,但所有这些似乎都阻止了主程序,直到子进程退出。

我们是否需要在单独的线程中读取孩子的标准输出?有人可以提供一个示例,其中主程序可以同时做其他事情而不是阻止来自孩子的 stdout 吗?

c++ boost boost-thread boost-asio boost-process

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