我尝试使用boost属性树为自定义linux编译。我在文件json_parser_read.hpp(第105行)
上有错误struct a_literal_val
{
context &c;
a_literal_val(context &c): c(c) { }
void operator()(It b, It e) const
{
BOOST_ASSERT(c.stack.size() >= 1);
c.stack.back()->push_back(std::make_pair(c.name, Str(b, e)));
c.name.clear();
c.string.clear();
}
};
这段代码无法编译。
输出为:/path/to/boost/property_tree/detail/json_parser_read.hpp:105: error: no matching function for call to 'boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> >::push_back(std::pair<std::basic_string<char>, std::basic_string<char> >)'
c.stack.back()->push_back(std::make_pair(c.name, Str(b, e)));
^
我正在使用boost v1.49
我使用其他电脑进行了测试,它可以正确编译1.58版本
感谢您的帮助。
答案 0 :(得分:0)
这是你应该创建的SSCCE。我看不出你的问题¹,²:
<强> Live On Coliru 强>
public override bool AuthorizeHubConnection(HubDescriptor hubDescriptor,
IRequest request)
{
//This should be sent in the Header - but will not work with
//Websockets, if a custom header is required, ensure the transport type is "LongPolling" for demo purposes, QueryString was chosen.
var token = request.QueryString.Get("Token");
if (string.IsNullOrWhiteSpace(token))
return false;
//Logic omitted to perform checks and the validity of a request
if (client == null)
return false;
//build the claims identity
Claim clientIdClaim = new Claim("Id", "SignalR: " + client.Id.ToString());
Claim clientNameClaim = new Claim(ClaimTypes.Name, "SignalR: " + client.ClientName);
List<Claim> claims = new List<Claim>
{
clientIdClaim,
clientNameClaim,
};
//"Basic" is required to ensure IsAuthenticated is set, amongst others.
ClaimsIdentity identity = new ClaimsIdentity(claims, "Basic");
// set the authenticated user principal into environment so that it can be used in the future
request.Environment["server.User"] = new ClaimsPrincipal(identity);
return true;
}
public override bool AuthorizeHubMethodInvocation(IHubIncomingInvokerContext hubIncomingInvokerContext, bool appliesToMethod)
{
var connectionId = hubIncomingInvokerContext.Hub.Context.ConnectionId;
// check the authenticated user principal from environment
var environment = hubIncomingInvokerContext.Hub.Context.Request.Environment;
var principal = environment["server.User"] as ClaimsPrincipal;
if (principal == null ||
principal.Identity == null ||
principal.Identity.IsAuthenticated == false)
return false;
// create a new HubCallerContext instance with the principal generated from token
// and replace the current context so that in hubs we can retrieve current user identity
hubIncomingInvokerContext.Hub.Context = new HubCallerContext(new ServerRequest(environment), connectionId);
return true;
}
打印
#include <boost/property_tree/ptree.hpp>
#include <deque>
using boost::property_tree::ptree;
struct context {
std::string name, string;
std::deque<ptree *> stack;
};
struct a_literal_val {
using Str = std::string;
context &c;
a_literal_val(context &c) : c(c) {}
template <typename It>
void operator()(It b, It e) const {
BOOST_ASSERT(c.stack.size() >= 1);
c.stack.back()->push_back(std::make_pair(c.name, ptree{Str(b, e)}));
c.name.clear();
c.string.clear();
}
};
#include <boost/property_tree/json_parser.hpp>
#include <iostream>
int main() {
boost::property_tree::ptree pt;
context ctx { "field1", "", { &pt } };
a_literal_val visitor {ctx};
std::string const value = "hello world";
visitor(value.rbegin(), value.rend()); // reverse, for fun
write_json(std::cout, pt);
}
除了你可能滥用Boost属性作为XML或JSON库之外,¹。 Boost 没有 XML或JSON库。
²是的,我知道你的样本更复杂。很可能你正在为你的接口代码编写一个“通用”序列化器。在我的水晶球更深处,我可以猜测你正在使用Boost Fusion改编的结构来处理嵌套的对象图。以前都做过。关键是,你需要提出你所遇到的问题,或者没有人知道。