草庐IT

c++ - clang/g++ 与私有(private)继承和使用声明的区别

考虑以下代码:#includestructParams{};templatestructBase{intdata()const{return42;}};templateclassD,classP>structMiddle:privateD//mustbe'public'forg++{};structFinal:publicMiddle{usingBase::data;};intmain(){Finalf;std::cout此代码编译成功并打印42clang并在gcc上给我编译时错误'intBase::data()const[withT=Params]'isinaccessible在这种

c++ - 是否对 boost 进行了优化以使用 C++11 中的可变参数模板?

我找不到关于(1)Boost是否已经在使用C++11的可变参数模板而不是使用MPL的版本中可用的信息,以及(2)在制作“典型”时可能期望减少什么样的编译时间在常见平台(MSVC2013、clang、gcc)上使用常见的Boost习语(ptr、tuple、pair、mutex等)。谢谢! 最佳答案 (Boost)Hana似乎是那个主动。许多子库选择只做他们的“下一个”版本c++11(Spirit、Fusion、Proto-0x和其他?)。所以如果你愿意的话,有一种远离MPL的运动。我不认为MPL在不久的将来会被“取代”。对于选择退出c

c++ - Clang (3.6.0) 忽略包含头文件的警告

似乎clang忽略了包含的头文件中出现的警告://what.hppclassWhat{public:What(){intx=x;}};//main.cpp#include#include"what.hpp"intmain(){inty=y;std::cout用g++(4.9.2)编译得到:$g++-dumpversion&&g++-Wall-Wextramain.cpp-omain4.9.2Infileincludedfrommain.cpp:3:0:what.hpp:Inconstructor‘What::What()’:what.hpp:5:17:warning:‘x’isused

c++ - 在 clang 格式的控制语句之后中断

我在我的.clang-format文件中使用了BreakBeforeBraces:Allman,但在控制语句(例如if、for,while,...)没有放在它们自己的行上。//Currently:voidfoo(){while(true){bar();}}//WhatIwant:voidfoo(){while(true){bar();}}I'vereadthat您可以在BraceWrapping中为大括号设置嵌套配置类,但我无法找出正确的YAML语法(以及sublimetext插件的JSON语法),也找不到任何现有示例。有什么办法吗? 最佳答案

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++ - 为派生类专门化 std::hash 在 gcc 中工作,而不是 clang

我正在尝试为派生类专门化std::hash。目前最好的方法是基于thisanswer:#include#include#includenamespacefoo{templateusingfirst=T;structhashable{};structbar:publichashable{};}namespacestd{templatestructhash::value>>>{size_toperator()(constT&x)const{return13;}};}intmain(){std::unordered_setbaz;return0;}使用g++5.2.0编译时没有警告(-Wal

c++ - 使用 libtooling 获取完全限定的模板模板参数名称

我正在尝试使用libtooling打印CXXRecordDecl具有模板模板参数的模板类的实例化。不幸的是,模板模板参数的字符串表示不完全限定(例如,它缺少namespace)。我正在打印CXXRecordDecl使用此代码:clang::PrintingPolicypolicy=compiler_instance->getLangOpts();std::stringname=decl->getTypeForDecl()->getCanonicalTypeInternal().getAsString(policy);这是一个我希望输出为ns::A的示例,但我得到ns::A:namesp

c++ - Boost.Program_options 在 Clang 下没有正确链接

以下初始示例来自Boost.Program_options文档//CopyrightVladimirPrus2002-2004.//DistributedundertheBoostSoftwareLicense,Version1.0.//(SeeaccompanyingfileLICENSE_1_0.txt//orcopyathttp://www.boost.org/LICENSE_1_0.txt)/*Thesimplestusageofthelibrary.*/#includenamespacepo=boost::program_options;#include#includeusi

c++ - 模板参数中是否禁止使用 SFINAE,还是我遇到了 clang 错误?

以下是我在实际代码中遇到的问题的简化版本。精简版:只看gcc.godbolt.org处的代码和错误/长版:继续阅读;)假设我想要一个带有模板参数setting和方法intfunc(int)的类,例如:当setting为false时,func返回其参数当setting为true时,func将其参数加倍最简单的方法是专门化类模板:templatestructA{intfunc(x)const{return2*x;}};templatestructA{intfunc(x){returnx;}};这种方法的问题是,如果我有一堆不依赖于setting的其他方法,我将不得不在两个特化中复制粘贴它们

c++ - 强制使用预定义宏的 gcc 标志

我的问题如下。我正在尝试为mips构建一个项目。当我从它的存储库下载它时,构建它没有问题,但是当我将它作为一个更大项目的一部分构建它时,我收到以下错误:error:expected‘,’or‘...’beforenumericconstant我发现这是一个问题,因为某些变量称为mips,而同一变量在gcc编译器中被定义为预定义宏。#definemips1我验证了它:mipsel-linux-gnu-g++-dM-E-所以,我的问题是,是否有人知道是否有特定的编译器标志或其他什么强制使用此宏?奇怪的是,当我从存储库下载相同的代码时没有构建问题。这两个项目都是使用相同的工具链构建的,我已经