草庐IT

ZN5boost

全部标签

c++ - boost::asio 只能接收完整的 UDP 数据报吗?

我正在使用boost::asio构建的UDP服务器上工作,我从tutorial开始根据我的需要定制。当我调用socket.receive_from(boost::asio::buffer(buf),remote,0,error);时,它会用数据包中的数据填充我的缓冲区,但是,如果我的理解是正确的,它会丢弃任何不适合缓冲区的数据。对receive_from的后续调用将接收下一个可用的数据报,因此在我看来,在没有通知的情况下丢失了一些数据。我是不是理解错了?我试着一遍又一遍地阅读boost::asio文档,但我没有设法找到关于我应该如何以正确的方式做到这一点的线索。我想做的是读取一定数量的

c++ - 构造一个包含变量类型索引中第 n 类型值的 boost 变量?

我想构造包含默认构造值的boost::variant,用类型索引指定-而无需在类型索引上编写我自己的switch语句。我认为这一定可以通过MPL以某种方式实现?澄清一下,索引不是编译时常量表达式。用例是我需要构造一个变体,稍后将用包含正确值的变体替换,但此时我只知道类型索引。将其视为惰性反序列化问题。 最佳答案 您需要使用variant::typestypedef。这为您提供了一个MPL兼容序列,然后我们可以将其与mpl::at和一个模板一起使用来进行我们的出价。这样做的诀窍:#include#include#include#inc

c++ - 使用 boost::enable_shared_from_this 时出现不完整的类型错误

在下一行classSymbol:publicboost::enable_shared_from_this{我得到错误:错误:不完整类型的无效使用structboost::enable_shared_from_this/usr/include/boost/smart_ptr/shared_ptr.hpp:63:错误:声明structboost::enable_shared_from_this知道为什么我会收到此错误。Symbol是一个抽象类(如果重要的话) 最佳答案 哎呀。错误是因为我没有包含定义enable_shared_from_

c++ - boost::asio::yield_context:意外的 forced_unwind 异常

我正在尝试为boost::asio编写自定义异步函数,如here所述.但是我在result.get上遇到了boost::coroutines::detail::forced_unwind异常#include#include#include#include#includenamespaceasio=::boost::asio;templateautomy_timer(Timer&timer,Token&&token){typenameasio::handler_type::typehandler(std::forward(token));asio::async_resultresult(

c++ - Boost 库中的 Io_context 错误

我正在尝试使用BoostLibraries构建聊天室。但是当我尝试使用asio::io_context时,编译器说:io_contextisnotanmemberofasio.我构建了4次Boost,我认为问题可能是由于我的安装失败造成的,但事实并非如此。#include#include#include#include#include#include#includeusingboost::asio::ip::tcp;std::stringmake_daytime_string(){usingnamespacestd;//Fortime_t,timeandctime;time_tnow=

c++ - 我如何使用 boost::spirit::qi 解析行尾?

不应该是一个简单的eol成功了吗?#include#include#include#includeusingboost::spirit::ascii::space;usingboost::spirit::lit;usingboost::spirit::qi::eol;usingboost::spirit::qi::phrase_parse;structfix:std::unary_function{fix(std::string&result):result(result){}voidoperator()(charc){if(c=='\n')result+="\\n";elseif(c

c++ - 如何遍历 boost::mpl::list?

这就是我所得到的,#include#includenamespacempl=boost::mpl;classRunAround{};classHopUpAndDown{};classSleep{};templateintdoThis();templateintdoThis(){/*runrunrun..*/return3;}templateintdoThis(){/*hophophop..*/return2;}templateintdoThis(){/*zzz..*/return-2;}intmain(){typedefmpl::listacts;//std::for_each(mpl

C++ boost函数重载模板

我无法弄清楚为什么这个段给出Unresolved重载函数错误(gcc版本4.3.4(Debian4.3.4-6)):#include#include//thisdoesnotworkintmain1(){typedefboost::functionmax;maxm(&std::max);}//thisdoesnotworkintmain2(){typedefboost::function2max;maxm(static_cast(&std::max));}你能帮帮我吗,谢谢test.cpp:Infunctionâintmain()â:test.cpp:7:error:nomatchin

c++ - 如何让 boost::make_shared 成为我类(class)的 friend

我编写了一个带有protected构造函数的类,因此只能使用静态create()函数生成新实例,该函数将shared_ptr返回我的类。为了提供有效的分配,我想在create函数中使用boost::make_shared,但是编译器提示说我的类构造函数在boost::make_shared中受到保护。我决定让我的boost::make_shared成为我类的friend,但我对语法感到困惑。我试过了templatefriendboost::shared_ptrboost::make_shared(constConnectionManagerPtr&,conststd::string&)

c++ - Dijkstra 最短路径与 VertexList = ListS in boost graph

我对Boost图还很陌生。我正在尝试改编一个示例来查找使用VertexList=vecS的Dijkstra最短路径算法。我将顶点容器更改为ListS。我了解到,如果我们使用listS,我们必须为算法提供我们自己的vertex_index才能工作。intmain(int,char*[]){typedeffloatWeight;typedefboost::propertyWeightProperty;typedefboost::propertyNameProperty;typedefboost::propertyIndexProperty;typedefboost::adjacency_l