草庐IT

Archive_Template

全部标签

c++ - Boost Serialization - 不再反序列化损坏的数据时没有 archive_exception?

几个月前我实现了一个组件,它通过UDP网络接收数据,通过Boost::Serialization反序列化它并开始处理传入的对象。在使用这个组件一段时间后发生了随机崩溃,当我发现其他人正在向我的UDP端口发送数据时我可以解决这个问题。我通过简单地在反序列化周围添加一个try/catch解决了这个问题:try{boost::archive::text_iarchiveinputArchive(incomingData);inputArchive>>givenElements;//theactualdeserialization,heretheexceptionhasbeenthrownin

C++ 概念 : Can I define a concept that is itself a template?

抱歉,如果问题不太清楚。我不确定表达它的最佳方式(随意编辑!)。我认为一个例子是最清楚的:我试图根据Haskelldefinition定义一个Monad概念.绑定(bind)运算符(>>=)要求A类型的Monad可以绑定(bind)到接受A并返回B类型的Monad。我可以根据value_typetypedef定义A,但是如何在我的概念中定义类型B?templateconceptboolMonad(){returnrequires(Mm,Function>f){//(>>=)::ma->(a->mb)->mb{m>>=f}->M}}在上面的例子中,我用什么来代替Function概念中的_

c++ - 在模板参数列表中使用 sizeof... 时为 "too few template arguments"(MSVC 2017)

以下最小示例不基于当前的MSVC2017(19.16)。它确实基于MSVC2015和2017(19.14)的旧版本、GCC、Clang和ICC。所以我怀疑这是一个编译器错误。有效吗?如果不是,为什么?#include#includetemplateautofoo(std::integer_sequence){returnstd::array{Is...};}std::arraybar(){returnfoo(std::make_integer_sequence());}有效的变体:投入unsigned(sizeof...(Is))在参数列表中作为默认参数替换unsigned(...)与

c++ - boost::serialization Archive::register_type 如何工作?

boost::serialization能够序列化它们最派生类的多态对象,即使这些对象由指向基类的引用/指针指向。这不需要虚函数。要做到这一点,boost::serialization需要知道存在的多态类型:Archive::register_type必须在Archive用于序列化的对象。Thisexample展示了如何注册类型以及如何序列化它们。我想知道这是如何实现的。我试图查看boost::serialization源代码但失败了:我不太擅长模板元编程。 最佳答案 boost.serialization可以使用typeid()或

C++ 微软 : How to associate uuid/guid with template specialization

我想将uuid/guid与模板特化相关联。以下代码可用于将uuid与非模板接口(interface)(类、结构)相关联:__interface__declspec(uuid("CECA446F-2BE6-4AAC-A117-E395F27DF1F8"))ITest{virtualvoidTest()=0;};GUIDguid=__uuidof(ITest);//OK现在我有了一个模板化的界面template__interfaceITemplateTest{virtualvoidTest(Tt)=0;};我想做以下工作:GUIDtemplateGuid=__uuidof(ITemplat

c++ - 如何在 C++ 中避免 "template template template"模板

我已经尝试实现一个“模板模板模板”——模板类来满足我的需求(我对使用模板元编程很陌生)。不幸的是,我发现以下主题为时已晚:TemplateTemplateParameters不过,我需要实现如下所列的内容。根据编译器,最后一个typedef不工作。我不确定,但我认为这是由于3x模板限制的限制。在这个简单的示例中是否有可能绕过3xtemplate定义?templateclassITTranslator{public:ITTranslator()=0;virtual~ITTranslator()=0;virtualvoiddoSomething()=0;}templateclassTCon

c++ - 为什么我收到错误 "non-template ' f' used as template”

我正在尝试了解在哪里使用template和typename我遇到了一个我无法完全解决的问题。我有一个模板函数f它使用传递给它的类型(将是一个类)来调用模板成员函数.f.我想我使用typename在函数体中是正确的,但是,我不断收到以下错误:source.cpp:Infunction'voidf()':source.cpp:11:19:error:non-template'f'usedastemplatesource.cpp:11:19:note:use'typenameT::C::templatef'toindicatethatitisatemplatestructA{structC{

c++ - boost::archive::binary_oarchive 如何处理枚举?

我有以下枚举enumExample:uint8_t{First=1,Second=2,};和一个字符串流:std::stringstreamstream;boost::archive::binary_oarchivear(stream);现在我注意到,如果我序列化一个枚举:arboost序列化4字节(在本例中为0x01、0x00、0x00、0x00)位,而不是uint8_t所需的8位(0x01)。有什么办法可以避免这种情况吗?我的意思是,我知道我可以将该枚举转换为uint8_t,但这种接缝不是很巧妙(如果必须这样做,我必须更改很多东西)。谢谢和问候 最佳答案

c++ - 为什么 static const char * template struct 成员没有初始化

我有一些C++11模板代码,我正在尝试移植到VisualC++Compiler2015。原始代码工作得很好,但是我需要重写它以解决constexpr的问题。Theoriginalcode(simplifiedexample)#includestructString{staticconstexprconstchar*value{"STRING"};};templateclassDerived{public:staticconstexprconstchar*value{Base::value};};templatestructFoo{staticconstexprconstchar*val

c++ - Xcode C++ vector : Implicit instantiation of undefined template

我在不同的IDE上运行这段代码,它成功了。出于某种原因,我在Xcode上收到上述错误消息。我假设我缺少某种标题,但我不确定是哪一个。#include#include#include#includeintmain(){vectorlistRestaurants;//error:Implicitinstantiationofundefinedtemplatereturn0;} 最佳答案 Xcode10.2.1向我展示了错误Implicitinstantiationofundefinedtemplate'std::__1::vector,