草庐IT

make_new_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++ - 模板函数的 'typedef' (boost::make_shared)

我正在将我的项目迁移到C++11,我正在尝试使用尽可能多的标准库。在完成迁移之前,我需要一种快速的方法来在shared_ptr的boost和STL实现之间切换(以进行基准测试、单元测试等)。所以我为shared_ptr定义了一个别名,如下所示:#ifdef_USE_BOOST_templateusingshared_ptr=boost::shared_ptr#elsetemplateusingshared_ptr=std::shared_ptr#endif现在我需要为make_shared做同样的事情...但是怎么做呢?宏观?wrapper?我真的不喜欢他们中的任何一个。有哪些替代方案

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++ - 如何在 `make uninstall` 期间从 QT5 中的 qmake 运行自定义命令?

我有一个QT项目,它在运行makeinstall时向系统安装服务。.pro文件的相关部分如下:init.path=/etc/init.d/init.files=myservicenameupdaterc.path=/etc/init.d/updaterc.extra=chmod755$$init.files;\update-rc.d$$init.filesdefaults9703;\service$$init.filesstartINSTALLS+=target...initupdaterc这会正确安装服务,然后启动它。但是,当我运行makeuninstall时,虽然安装的文件被正确删

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++ - 由 placement-new 创建的普通类型的生命周期从什么时候开始?

在深入研究动态内存的过程中,我发现微不足道的类型如何开始其生命周期似乎是矛盾的。考虑片段void*p=::operatornew(sizeof(int));//1//2new(p)int;//3int什么时候开始它的生命周期?只获取存储,指定::operatornew有效果(来自[new.delete.single])Theallocationfunctionscalledbyanew-expressiontoallocatesizebytesofstorage.[...]allocatesstoragesuitablyalignedtorepresentanyobjectofthat