草庐IT

Archive_Template

全部标签

c++ - 使用 boost::archive 和 boost::iostreams 来压缩数据

我想为一个可以选择性地压缩数据的类编写一个序列化函数。我想使用boost::iostreams中提供的压缩工具。有谁知道如何做到这一点?structX{X(){}templatevoidserialize(Archive&ar,constunsignedintversion){ar&compression;if(compression==0){ar&data;}elseif(compression==1){//useboost::iostreamcompression//facilitiestoserializedata}}intcompression;std::vectordata;

c++ - 嵌套命名空间 : where should default template arguments go? 中模板类的前向声明

我在嵌套命名空间中有一个模板类的前向声明namespacen1{namespacen2{templatestructA;}usingn2::A;}接着是一个定义,实际上它在不同的文件中,中间有一些东西:structX{};namespacen1{namespacen2{templatestructA{};}usingn2::A;}那么以下总是可以的:n1::n2::Aa;但是这个捷径n1::Aa;在clang中给出编译错误error:toofewtemplateargumentsforclasstemplate'A'除非我删除前向声明;g++两者都接受。clang似乎保留在第一个不包含

c++ - g++ 错误 : specialization after instantiation (template class as friend)

考虑以下C++代码:templateclassSingleton{};classConcreteSingleton:publicSingleton{templatefriendclassSingleton;};intmain(){}Singleton应该是ConcreteSingleton的friend:它适用于Microsoft的可视化C++编译器。但是,我不能用g++4.8.4编译它。错误是:error:specializationof‘Singleton’afterinstantiationtemplatefriendclassSingleton;有什么办法可以解决吗?

C++ template-id 不匹配任何模板?

我用模板和特化写了一个简单的代码:#includetemplateintHelloFunction(constT&a){std::coutintHelloFunction(constchar*&a){std::cout我认为char*特化是正确的,但是g++报告:D:\work\test\HelloCpp\main.cpp:11:5:error:template-id'HelloFunction'for'intHelloFunction(constchar*&)'doesnotmatchanytemplatedeclaration请帮我找出错误。 最佳答案

c++ - 错误 : C2988: unrecognizable template declaration/definition

我的两个模板的标题中出现错误。两者都有类似的声明和定义如下:templatevoidsetVideoCodecOption(T1AVCodecContext::*option,T2(CR2CVideoCodecSettings::*f)()const);templatevoidEncoderPrivate::setVideoCodecOption(T1AVCodecContext::*option,(CR2CVideoCodecSettings::*f)()const){T2value=(m_videoSettings.*f)();if(value!=-1){m_videoCodecC

c++ - 模板特化站点报告 "too few template-parameter-lists"错误

代码某处有错误,但我不知道如何解决。它说“模板参数列表太少”。我不明白哪个是错误的。代码如下:#if!defined(VECTOR_H_INCLUDED)#defineVECTOR_H_INCLUDED#include//forsize_tnamespaceVec{classVector_base{public:explicitVector_base(){}};templateclassVector:publicVector_base{typedefVectorME;explicitVector(T,T,T);doubledot(constME&v)const;T&operator[]

C++:专门化成员需要 «template<>» 语法

我做错了什么?templateclassBinder{public:staticstd::vector*>all;Node*from;Node*to;Binder(Node*fnode,Node*tonode){from=fnode;to=tonode;Binder::all.push_back(this);}};std::vector*>Binder::all=std::vector*>();//hereitis谢谢。 最佳答案 静态成员的定义被编译器解释为一个特化(实际上,它是一个特化:你给出了一个特定于T=int的声明)。这可

c++ - template-parameter-list of template parameter 是什么意思

引用3.3.9/1中的一句话:Thedeclarativeregionofthenameofatemplateparameterofatemplatetemplate-parameteristhesmallesttemplate-parameter-listinwhichthenamewasintroduced.你能举个例子来理解上面的定义吗?我也想知道模板参数的模板参数列表是什么意思?示例会有所帮助。 最佳答案 template//thedeclarativeregionendshereclassq//hencethenamema

c++ - 如何将 `std::array` 用作 `template<typename> class` 形式的模板参数?

请考虑以下tree类templateclassTuple>classtree{private:Tm_value;Tuplem_children;};templateusingstatic_tree=tree>;定义不明确。std::array不是Tuple的合适模板参数.我假设static_tree的意图清楚了。我们可以做类似的事情templatestructhelper{templateusingtype=std::array;};templateusingstatic_tree=tree::templatetype>;没有helper还有其他选择吗?类(class)?

c++ - 什么是 "template<class T> using owner = T;"?

以下摘自Microsoft的gsl库(https://github.com/microsoft/gsl)的gsl.h:namespacegsl{////GSL.owner:ownershippointers//usingstd::unique_ptr;usingstd::shared_ptr;templateusingowner=T;...};我无法理解以下别名模板的含义:templateusingowner=T;有什么解释吗? 最佳答案 这意味着对于每个T,owner是T的别名. 关于