通常认为将参数作为指针而不是作为值传递时更好吗?显然它在很大程度上取决于情况,但是当有选择时,使用指针会更好吗?
这只是出于记忆的原因吗?
如果它是真的,指针或引用,最好通过什么?
我的目标是让我的qi::grammar返回属性.spirit::lexer尽管如此,我在这方面遇到了很大的困难.
我希望用下面给定的语法,如果我用它来调用它spirit::qi::parse(begin, end, grammar, output);,struct ident output它将具有解析的lexeme的内容.
该错误似乎主要流出这一行: start %= lexer.identifier;
g++ -g -c -O0 -Wall -DBOOST_SPIRIT_DEBUG -DBOOST_SPIRIT_LEXERTL_DEBUG -DBOOST_SPIRIT_USE_PHOENIX_V3 -DBOOST_SPIRIT_ACTIONS_ALLOW_ATTR_COMPAT reduced.cpp
Run Code Online (Sandbox Code Playgroud)
#include <boost/fusion/include/adapt_struct.hpp>
#include <boost/spirit/home/lex.hpp>
#include <boost/spirit/home/lex/lexer/lexertl/lexer.hpp>
#include <boost/spirit/home/qi.hpp>
namespace spirit = boost::spirit;
struct ident {
std::string value;
};
BOOST_FUSION_ADAPT_STRUCT(ident,
(std::string, value)
)
struct my_lexer : spirit::lex::lexer< spirit::lex::lexertl::actor_lexer<> > {
spirit::lex::token_def<std::string> identifier;
};
struct my_grammar : spirit::qi::grammar<my_lexer::iterator_type, ident()> {
my_grammar(const …Run Code Online (Sandbox Code Playgroud) #include<iostream>
using namespace std;
class abc
{
int a;
};
class xyz : public virtual abc
{
int b;
};
int main()
{
abc obj;
xyz obj1;
cout<<endl<<sizeof(obj);
cout<<endl<<sizeof(obj1);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
答案将取决于编译器,但当我看到这个结果时,我感到很惊讶
~/Documents/workspace/tmp ‹.rvm-› $ ./class_sizes
4
16
Run Code Online (Sandbox Code Playgroud)
如果我删除虚拟关键字,那么分配的大小分别为4和8,这正是我的预期.
为什么额外的空间被准确占用?我怀疑它是针对vptr表或其他类似但不确定的.
我正在使用boost::asio从客户端到服务器来回传输数据。我在客户端有一个读取器线程来读取在客户端的套接字上接收到的数据。请注意,我boost::asio::read在客户端和boost::asio::write服务器端使用。不使用async_read或async_write。一切都很好。
但是,当我关闭我的应用程序时,该应用程序有 2 次 10 次没有完全拆除或正确关闭。它在关闭时挂起问题如下:
当我的应用程序关闭期间调用析构函数时,我的关闭函数被调用。以下是关闭函数的代码:
socket.cancel();
socket.close();
boost::system::error_code ec;
socket.shutdown(boost::asio::ip::tcp::socket::shutdown_both, ec);
Run Code Online (Sandbox Code Playgroud)
问题是boost::asio::read当它没有获得任何数据时调用不会返回并继续等待它。只要我可以取消它,这应该没问题。我正在尝试socket.cancel在退出时取消所有读取操作。但是,它似乎不起作用。我在一些论坛上读到socket.cancel只取消async_read操作。是这样吗 ?那么当我的应用程序需要退出时取消 boost::asio::read` 操作的方法是什么?
我正在研究Boost.Beast库。我尝试提出一个请求,其响应为:
HTTP/1.1 301 Moved Permanently
Cache-Control: public
Content-Type: text/html; charset=UTF-8
Location: https://www.example.com/target/xxx/
Run Code Online (Sandbox Code Playgroud)
然后,我尝试使用此位置字段发出请求,但收到错误的请求响应。
我该如何进行重定向?有例子吗?
这是我的代码:
boost::asio::io_service ios;
tcp::resolver resolver{ios};
tcp::socket socket{ios};
auto const lookup = resolver.resolve( tcp::resolver::query(host, port) );
boost::asio::connect(socket, lookup);
// Set up an HTTP GET request message
http::request<http::string_body> req{http::verb::get, target, 11};
req.set(http::field::host, host);
req.set(http::field::user_agent, BOOST_BEAST_VERSION_STRING);
// Send the HTTP request to the remote host
http::write(socket, req);
// This buffer is used for reading and must be persisted
boost::beast::flat_buffer buffer;
// Declare a container to hold the response
http::response<http::dynamic_body> …Run Code Online (Sandbox Code Playgroud) 请检查此缩减示例(增强1.68):
#include <boost/smart_ptr/shared_ptr.hpp>
#include <boost/range.hpp>
#include <vector>
void f(std::vector<boost::shared_ptr<int>>& c) {
using std::advance;
auto it = c.begin();
advance(it, 1);
}
Run Code Online (Sandbox Code Playgroud)
这段代码无法在gcc-8和clang-6上编译同样的错误,对advance()的调用是不明确的.
这两个候选人:
candidate: ‘constexpr void std::advance(_InputIterator&, _Distance)
[with _InputIterator =
__gnu_cxx::__normal_iterator<boost::shared_ptr<int>*, std::vector<boost::shared_ptr<int> > >; _Distance = int]’
advance(_InputIterator& __i, _Distance __n)
candidate: ‘constexpr void boost::iterators::advance_adl_barrier::advance(InputIterator&, Distance) [with InputIterator =
__gnu_cxx::__normal_iterator<boost::shared_ptr<int>*, std::vector<boost::shared_ptr<int> > >; Distance = int]’
advance(InputIterator& it, Distance n)
Run Code Online (Sandbox Code Playgroud)
第二个候选是由boost :: range引入的,不幸的是我不能简单地删除它,因为它被另一个依赖项(boost :: geometry)包含.
非限定调用由另一个库(范围-v3)执行,并且它是为了利用ADL而故意制作的
这显然是一个与ADL相关的问题,但我想念为什么编译器找到了第二个候选者,因为没有涉及boost :: range类型.
我对 linux 比较陌生,并且疯狂地尝试精益 bash,最终是 zsh。无论如何,目前这让我很难过:
#!/bin/bash
history -s "a_string"
Run Code Online (Sandbox Code Playgroud)
.... 不起作用。我已经对这个想法尝试了十几种变体,但没有任何效果。有任何想法吗?
我的应用程序提取数据并将其附加到文本文件,但我需要找出如何以编程方式查看文本文件的第一行,看它是否与以下文本匹配:
日期时间,VirtualIP,VirtualPort,VirtualName,DestinationIP,DestPort,状态,期望
如果它确实然后继续执行正常功能(下面的代码段),如果第一行与上面不同,那么我想在第一行插入上面的内容而不覆盖当前的那些.我怎样才能做到这一点?(基本上把所有东西都按下一行,这样我就可以在第一行添加我想要的东西了)...顺便说一句,这是保存为可以在excel中打开的csv文件.
try
{
// ...
for (int j = 0; j < memberStatus.Result.Count; j++)
{
VirtualMemberStatus status = memberStatus.Result[j];
//text += String.Format("Name: {4}, Member: {0}:{1}, Status: {2}, Desired: {3}" + Environment.NewLine, status.Member.Address, status.Member.Port, status.EffectiveStatus, status.DesiredStatus, virtualKey.Key);
text += String.Format("{5},{4},{0},{1},{2},{3}" + Environment.NewLine, status.Member.Address, status.Member.Port, status.EffectiveStatus, status.DesiredStatus, virtualKey.Key.Replace(":", ","), DateTime.UtcNow);
}
}
catch
{
//ERROR CODE 2
//MessageBox.Show("Error occurred, check device name (case senstive) and admin group. This error may also occur due to connection loss, try again.");
errors += …Run Code Online (Sandbox Code Playgroud) 我正在寻找实现variadic函数的最简单方法,它采用boost :: spirit :: qi规则列表并将列表扩展为格式表达式:rule1 | rule2 | rule3 | ....让我们假设规则不合成任何属性.非常感谢您的帮助.
#include <boost/config/warning_disable.hpp>
#include <boost/spirit/include/qi.hpp>
#include <string>
#include <iostream>
#include <boost/spirit/include/phoenix_operator.hpp>
namespace qi = boost::spirit::qi;
namespace ph = boost::phoenix;
namespace ascii = boost::spirit::ascii;
using boost::spirit::qi::phrase_parse;
using boost::spirit::qi::ascii::space;
using boost::spirit::iso8859_1::char_;
typedef qi::rule<std::string::const_iterator,ascii::space_type> mrule_t;
typedef qi::rule< std::string::const_iterator,std::string() > wrule_t;
Run Code Online (Sandbox Code Playgroud)
//How to deduce expandBitwise() return type ?
template<typename T>
T expandBitwise(T& t)
{
return t.rule_;
}
template<typename T,typename ...Tail>
T expandBitwise(T& t,Tail& ...tail)
{
return t.rule_ | expandBitwise(tail...);
}
struct TStruct
{
mrule_t …Run Code Online (Sandbox Code Playgroud) 在boost :: spirit中,我添加了基于示例roman的错误处理代码.
#include <boost/spirit/include/qi.hpp>
#include <boost/spirit/include/phoenix_operator.hpp>
#include <boost/spirit/include/phoenix_core.hpp>
#include <boost/spirit/include/phoenix_fusion.hpp>
#include <boost/spirit/include/phoenix_object.hpp>
#include <boost/foreach.hpp>
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
namespace qi = boost::spirit::qi;
namespace ascii = boost::spirit::ascii;
namespace phoenix = boost::phoenix;
template <typename Iterator>
struct roman : qi::grammar<Iterator>
{
roman() : roman::base_type(start)
{
using qi::eps;
using qi::lit;
using qi::lexeme;
using qi::_val;
using qi::_1;
using ascii::char_;
// for on_error
using qi::on_error;
using qi::fail;
using phoenix::construct;
using phoenix::val;
start = +(lit('M') ) >> "</>";
on_error<fail>
(
start
, …Run Code Online (Sandbox Code Playgroud) c++ ×7
boost ×4
boost-spirit ×3
.net ×1
bash ×1
beast ×1
boost-asio ×1
boost-beast ×1
boost-fusion ×1
c# ×1
c++11 ×1
coding-style ×1
csv ×1
formatting ×1
sockets ×1