草庐IT

Archive_Template

全部标签

c++ - append 到 gzip 压缩的 Tar-Archive

我写了一个程序,生成一个tarball,它被zlib压缩。每隔一段时间,同一个程序应该向tarball添加一个新文件。根据定义,tarball需要空记录(512字节block)才能在它的末尾正常工作,这已经表明了我的问题。根据文档gzopen无法在r+模式下打开文件,这意味着我不能简单地跳转到空记录的开头,append我的文件信息并用空记录再次密封。现在,我已经束手无策了。只要不涉及空记录,append就可以在zlib上正常工作,但我需要它们来“完成”我的压缩tarball。有什么想法吗?啊,是的,如果我能避免解压整个东西和/或解析整个tarball,那就太好了。我也对我可以实现的其他

c++ - Cryptic template 模板参数错误

我正在尝试创建一个从std::map或std::unordered_map获取键的函数。我可以使用简单的重载,但首先我想知道这段代码有什么问题。templateclassTContainer>std::vectorgetKeys(constTContainer&mMap){std::vectorresult;for(constauto&itr(std::begin(mMap));itr!=std::end(mMap);++itr)result.push_back(itr->first);returnresult;}当使用std::unordered_map调用它时,甚至手动指定所有模板

c++ - 嵌套类声明 : template vs non-template outer class

我有一个C++模板类,里面有一个嵌套类,比如:templateclassOuter_t{public:classInner;Inneri;};templateclassOuter_t::Inner{public:floatx;};intmain(){Outer_to_t;//3oranyarbitraryinto_t.i.x=1.0;return0;}编译没有任何问题。然而,一旦我声明了一个类似的非模板类,就像这样:classOuter_1{public:classInner;Inneri;};classOuter_1::Inner{public:floatx;};intmain(){

c++ - 错误 : 'Failed to specialize function template' C2893 'std::invoke'

我正在VisualStudio2013中编写MFC程序,但我不断收到以下两个错误错误C2893无法特化函数模板'unknown-typestd::invoke(_Callable&&,_Types&&...)'和错误C2672“std::invoke”:找不到匹配的重载函数错误与文件xthread第238行有关我是c++/MFC的新手,我正在尝试编写一个将在后台运行到系统时间的函数。这是我使用的代码:voidtask1(ExperimentTab&dlg){while(true){CStringshowtime=CTime::GetCurrentTime().Format("%H:%M

c++ - va_list 还在 C++ 中使用吗?还是鼓励使用 template<typename...T>?

在C中,定义可变长度参数的唯一方法是使用省略号声明其原型(prototype)并使用va_list、va_start、va_arg,va_end来提取它们。就像printf系列和scanf系列一样。在C++11中,引入了如下新方法。templatevoidfunc(Targ,MoreT...args){//Dosomestufffunc(args);}每种方法的优点和缺点是什么?在C++中是不鼓励使用还是鼓励使用它们中的任何一个? 最佳答案 在C++中强烈不鼓励使用C风格的可变参数函数。风格各不相同,但编写这些类型的函数会让您在某些

c++ - Curiously Recurring Template Pattern (CRTP) 是正确的解决方案吗?

场景考虑一个Logger类,它有一个为标准C++类型重载的成员函数write(),还有一些方便的函数模板,比如writeLine()内部调用write():classLogger{public:voidwrite(intx){...}voidwrite(doublex){...}...templatevoidwriteLine(Tx){write(x);...}...};进一步考虑一个子类FooLogger,它为特定于域的类型添加了额外的write()重载(我们称其中两个为FooType1和FooType2):classFooLogger:publicLogger{public:usi

c++ - 错误 : use of deleted function for overloaded template

我正在尝试模板特化,但无法确定为什么charconst*const无法在下面解析(尽管是有效类型)的原因。templateBfoo(A)=delete;templatevoidfoo(char*){}templatevoidfoo(charconst*const){}intmain(){{//typesOKcharconst*consta=nullptr;char*b=nullptr;}char*data;foo(data);//OKfoo(data);//ERRORreturn0;}错误error:useofdeletedfunction‘Bfoo(A)[withA=constcha

c++ - 了解 "template argument is invalid"错误消息

考虑代码:#include#includestructtest1{voidInvoke(){};};structtest2{templatevoidInvoke(){};};enumclassInvokableKind{NOT_INVOKABLE,INVOKABLE_FUNCTION,INVOKABLE_FUNCTION_TEMPLATE};templatestructget_invokable_kind{conststaticInvokableKindvalue=InvokableKind::NOT_INVOKABLE;};templatestructget_invokable_ki

c++ - template<> 用于成员枚举的显式特化

根据17.7.3[temp.expl.spec]第5段(N4659),...Membersofanexplicitlyspecializedclasstemplatearedefinedinthesamemannerasmembersofnormalclasses,andnotusingthetemplatesyntax.Thesameistruewhendefiningamemberofanexplicitlyspecializedmemberclass.However,templateisusedindefiningamemberofanexplicitlyspecializedm

c++ - 想要 : a C++ template idea to catch an issue, 但在编译时?

我们有一个常量结构数组,像这样:staticconstSettingsSuT_table[]={{5,1},{1,2},{1,1},etc};结构如下:size_bytes:num_items:其他“元数据”成员所以“总大小”是单个元素的size_bytes*num_items。所有这些信息都在const数组中,在编译时可用。但是,请注意,_table的总大小与EEPROM本身的大小无关。_table不镜像EEPROM,它只描述了布局、用途和我们需要的其他“元数据”类型的信息。但是,您可以使用此元数据来确定我们正在使用的EEPROM的数量。数组简单地描述了存储在外部EEPROM中的数据