草庐IT

Size_type

全部标签

c++ - CRTP + 特征类 : "no type named..."

我尝试使用模板化类实现CRTP,但在使用以下示例代码时出现错误:#includetemplateclassTraits{public:typedeftypenameT::typetype;//'staticconstunsignedintm_const=T::m_const;staticconstunsignedintn_const=T::n_const;staticconstunsignedintsize_const=T::m_const*T::n_const;};templateclassCrtp{public:typedeftypenameTraits::typecrtp_typ

c++ - std::string::max_size() 作为静态成员

为什么max_size不是std::string的静态成员?这可以编译,但我觉得奇怪的是所有字符串共有的属性只能通过字符串的实例访问:std::size_tmax_size=std::string().max_size();为什么会这样实现? 最佳答案 Whyisn'tmax_sizeastaticmemberofstd::string?因为max_size返回值取决于字符串实例内部使用的分配器实例。 关于c++-std::string::max_size()作为静态成员,我们在Stac

c++ - std::string 的 type_traits 段错误

从UsingSFINAEtocheckforglobaloperator收集信息和templates,decltypeandnon-classtypes,我得到了以下代码:http://ideone.com/sEQc87基本上,我将两个问题的代码结合起来,如果它有ostream声明,则调用print函数,否则调用to_string方法。摘自问题1namespacehas_insertion_operator_impl{typedefcharno;typedefcharyes[2];structany_t{templateany_t(Tconst&);};nooperatorstruct

c++ - 对于具有默认分配器的标准容器,std::container::size_type 是否保证为 size_t?

喜欢:std::string::size_typestd::list::size_typestd::map::size_typestd::vector::size_type等等两者都是cplusplus.com和cppreference.com说他们通常是size_t,但它们是否真正、明确地保证为size_t的标准除非使用自定义分配器? 最佳答案 对于STL容器-不。[container.requirements.general]中标准的表96,其中列出了任何容器的容器要求X,解释得很清楚:但是,对于basic_string,siz

c++ - 获取错误 : 'mutex' in namespace 'std' does not name a type in MinGW mysys prompt

我已经从官方网站下载了MinGW并将其安装在我的Windows8.1机器上。运行g++--version给我g++.exe(GCC)4.8.1。我正在尝试在MinGW编译器中编译现有的代码库,但它因以下错误而失败:error:'mutex'innamespace'std'doesnotnameatypeprivate:std::mutexm_Mutex;^error:'condition_variable'innamespace's还有更多与锁定和线程相关的错误。!我能够在Cygwin-64中编译相同的代码库,没有任何问题。我需要在MinGW中成功构建和编译,以便创建一些与MSVS兼容

c++ - std::vector::resize(size_type) 需要 CopyInsertable?

这个问题是在我回答thisanotherquestion的时候提出的.N333723.3.6.3“vector容量”说(在770页):voidresize(size_typesz);Effects:Ifsz,equivalenttoerase(begin()+sz,end());.Ifsize(),appendssz-size()value-initializedelementstothesequence.Requires:TshallbeCopyInsertableinto*this.然而,clang++saysit'sokaythoughTisnotcopyable.我认为resiz

c++ - type 不提供调用操作符

我有这个功能,order,返回vectorvectororder(vectornodes,vector>dependencies){Graphgraph=buildGraph(nodes,dependencies);vectororder=buildOrder(graph.getNodes());returnorder;}我这样调用它:vectororder2=order(nodes,deps);然而,编译器给出了这个错误:error:type'std::__1::vector>'doesnotprovideacalloperatorvectororder2=order(nodes,d

c++ - 对于类型 Class::Type,我可以从 const Class 派生 const Class::Type 吗?

我正在实现一个容器,例如:templateclassContainer{public:usingvalue_type=T;...};是否有从constContainer派生constvalue_type的好方法?背景:我已经通过嵌套模板类实现了迭代器类型:templateclassiterator_base{public:...Value&operator*()const;private:Container*c;};usingiterator=iterator_base;usingconst_iterator=iterator_base;工作正常,但iterator_base的第二个模

c++ - 制作 std::vector capacity>=N 和 size=0 的最佳方法?

给定一个std::vector,其大小和容量可以是任意的,将其大小更改为0并将容量更改为至少N(给定数字)的最佳做法是什么?我的直接想法是:voidf(vector&t,intN){t.clear();t.reserve(N);}但是我注意到了Areallocationisnotguaranteedtohappen,andthevectorcapacityisnotguaranteedtochange(whenstd::vector::cleariscalled).所以我想知道当原始容量大于给定的N时如何避免重新分配? 最佳答案 w

盘点手机Type-c充电接口5个实用功能

目录1、手机通过Type-c转HDMI,高清输出电视 2、通过OTGType-c扩展手机功能 3、实现手机通过网卡有线上网 4、电脑通过手机Type-C有线上网 5、手机通过Type-C收听高清音频 今天给大家聊聊手机Type-c充电接口的5个实用功能,希望对大家日常使用手机带来一些帮助!1、手机通过Type-c转HDMI,高清输出电视 虽然现在的手机可以通过乐播等投屏软件,把手机屏幕投屏到电视或电脑上,实现小屏变大屏,但是,采用这种方式投屏播放电视剧电影的清晰度不太理想,甚至时常还会有卡顿或画面延迟的情况。我们手机Type-c转HDMI来实现电视投屏的功能,画面清晰、不卡顿也不用再去花冤枉钱