草庐IT

BOOST_STATIC_ASSERT

全部标签

C++1y/C++14 : Converting static constexpr array to non-type template parameter pack?

假设我有一个静态存储持续时间的constexpr数组(已知范围):constexprTinput[]=/*...*/;我有一个需要打包的输出类模板:templatestructoutput_template;我想像这样实例化output_template:usingoutput=output_template;一种方法是:templatestructmake_output_template{templatestaticconstexproutput_templatef(std::index_sequence){return{};};usingtype=decltype(f(std::m

c++ - boost::lexical_cast 无法识别重载的 istream 运算符

我有以下代码:#include#includestructvec2_t{floatx;floaty;};std::istream&operator>>(std::istream&istream,vec2_t&v){istream>>v.x>>v.y;returnistream;}intmain(){autov=boost::lexical_cast("1231.2152.9");std::cout我从Boost收到以下编译错误:Error1errorC2338:Targettypeisneitherstd::istreamablenorstd::wistreamable这看起来很简单,

c++ - boost 记录器刷新到文件

在执行每个日志记录代码行后,我需要boost日志记录。是否有可能以某种方式配置接收器以这种方式运行?目前日志是在程序结束后立即填充的。#include#include#include#include#include#include#include#include#include;namespacelogging=boost::log;namespacesrc=boost::log::sources;namespacesinks=boost::log::sinks;namespacekeywords=boost::log::keywords;voidinit(){logging::add

c++ - boost::optional 和类型转换

我想知道是否有一种优雅的方式来转换boost::optional到boost::optional什么时候B可以从A构建,尽管是明确的。这有效:#includeclassFoo{inti_;public:explicitFoo(inti):i_(i){}};intmain(){boost::optionali;...//igetsinitializedornotboost::optionalfoo;foo=boost::optional(bool(i),Foo(i.value_or(0/*unusedvalue*/)));return0;}但是需要将一些永远不会被使用的值放在那里似乎很尴

c++ - 散列任意精度值(boost::multiprecision::cpp_int)

我需要以任意精度获取一个值的散列值(来自Boost.Multiprecision);我用cpp_int后端。我想出了以下代码:boost::multiprecision::cpp_intx0=1;constautoseed=std::hash{}(x0.str());我不需要代码尽可能快,但我发现对字符串表示进行哈希处理非常笨拙。所以我的问题是双重的:保持任意精度,我可以更有效地散列值吗?也许我不应该坚持保持任意精度,我应该转换成一个我可以轻松散列的double(不过,我仍然会使用任意精度值进行哈希表所需的比较)? 最佳答案 您可以

c++ - 如何将主机名转换为 boost 地址或端点?

我在Boost之上使用C++Redis库。(https://github.com/nekipelov/redisclient)要连接,我必须给它一个单一的tcp端点:boost::asio::ip::tcp::endpoint或者地址+端口boost::asio::ip::address,unsignedshort目前,我开始:boost::asio::ip::addressaddress=boost::asio::ip::address::from_string(someIPVariable);并将其与端口一起传递,它工作正常并已连接。但是,我现在需要通过主机名而不是IP来完成。如果

c++ - 使用 Boost ptree 将 JSON 数组解析为 std::string

我有这段代码,我需要解析/或获取JSON数组作为std::string以在应用程序中使用。std::stringss="{\"id\":\"123\",\"number\":\"456\",\"stuff\":[{\"name\":\"test\"}]}";ptreept2;std::istringstreamis(ss);read_json(is,pt2);std::stringid=pt2.get("id");std::stringnum=pt2.get("number");std::stringstuff=pt2.get("stuff");需要的是像这样检索的“东西”std::s

c++ - Boost 程序选项 bool 总是 True

通过程序选项,我正在检查参数的有效组合。但出于某种原因,gpu参数是一个bool,无论我是否在命令行上将其设置为false,它始终为true。如果我在命令行上指定了gpu选项,有没有办法让它为false?我希望能够创建一个bool变量来表示是否使用了命令行上的选项。我也找不到任何关于variables_map的count()的文档。它是std::map函数吗?部分代码:namespacepo=boost::program_options;po::options_descriptiondesc("AllowedOptions");desc.add_options()("help,h","

c++ - 向上转换时的隐式转换与 static_cast

假设我有三个类:A(母亲,抽象),B和C,A的child。所以B和C继承自A(公有继承)。我有一个指向A的指针列表,我用B或C的指针填充它。问题是:在进行转换/转换时,哪种风格是首选?classA{};classB:publicA{};classC:publicA{};B*objB=newB();C*objC=newC();std::listmyList;//OptionA:staticcastconversionmyList.push_back(static_cast(objB));myList.push_back(static_cast(objC));//OptionB:impli

c++ - 将 boost spirit 用于基于堆栈的语言

我需要解析一种相当简单的基于堆栈的语言,例如12add31sub我在这里面临两个选择:为标记编写我自己的词法分析器,然后继续解析它使用boostspirit我从未使用过boostspirit,但根据我所阅读的内容(文档和示例),我仍然不能确定使用boostspirit来lex和解析这种简单的语言是否会过大,或者如果使用它而不是推出我自己的词法分析器和解析器是有意义的(我认为这应该不会太难)。将boostspirit用于像上面那种基于堆栈的简单语言会有返回吗(因为我需要先学习它才能使用它)? 最佳答案 在“详尽探索”类别中,让我添加一