在c ++ 03及更早版本中禁用有关未使用参数的编译器警告我通常使用这样的代码:
#define UNUSED(expr) do { (void)(expr); } while (0)
Run Code Online (Sandbox Code Playgroud)
例如
int main(int argc, char *argv[])
{
UNUSED(argc);
UNUSED(argv);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
但宏不是c ++的最佳实践,所以.c ++ 11标准是否有更好的解决方案?我的意思是我可以摆脱宏吗?
谢谢大家!
如何从GitHub/Bitbucket中删除远程主分支?
我尝试着:
# git push bb --delete master
remote: bb/acl: user is allowed. accepted payload.[K
remote: error: refusing to delete the current branch: refs/heads/master[K
To ssh://git@bitbucket.org/user/reponame.git
! [remote rejected] master (deletion of the current branch prohibited)
error: failed to push some refs to 'ssh://git@bitbucket.org/user/reponame.git'
Run Code Online (Sandbox Code Playgroud)
我也试过了
git push bb :master
Run Code Online (Sandbox Code Playgroud)
但这一切都行不通.
如何通过标准的msys功能将Windows目录路径(比方说c:/libs/Qt-static)转换为正确的POSIX目录路径(/c/libs/Qt-static)?反之亦然?
constexpr说明noexcept符是否意味着函数的说明符?对类似问题的回答对说明者说"是" inline,但Eric Niebler的文章让我想知道对当前问题的可能答案.在我看来,答案取决于使用constexpr函数的上下文:是常量表达式上下文还是运行时上下文,即在编译时是否已知函数的所有参数.
我希望答案是"是",但简单的检查表明情况并非如此.
constexpr
bool f(int) noexcept
{
return true;
}
constexpr
bool g(int)
{
return true;
}
static_assert(noexcept(f(1)));
static_assert(noexcept(g(2))); // comment this line to check runtime behaviour
#include <cassert>
#include <cstdlib>
int
main(int argc, char * [])
{
assert(noexcept(f(argc)));
assert(noexcept(g(argc)));
return EXIT_SUCCESS;
}
Run Code Online (Sandbox Code Playgroud) 为什么std::optional(目前std::experimental::optional在libc ++中)没有引用类型的专门化(与之相比boost::optional)?
我认为这将是非常有用的选择.
是否有一些对象引用了STL中可能已存在的对象语义?
我建立铛由铛反对的libc ++,的libc ++ ABI,编译器RT在下面的步骤:
要下载(和更新)llvm和子项目,我使用以下脚本:
svn co http://llvm.org/svn/llvm-project/llvm/trunk llvm
cd llvm/tools
svn co http://llvm.org/svn/llvm-project/cfe/trunk clang
svn co http://llvm.org/svn/llvm-project/clang-tools-extra/trunk clang/tools/extra
svn co http://llvm.org/svn/llvm-project/lldb/trunk lldb
svn co http://llvm.org/svn/llvm-project/lld/trunk lld
svn co http://llvm.org/svn/llvm-project/polly/trunk polly
cd ../projects/
svn co http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
svn co http://llvm.org/svn/llvm-project/libunwind/trunk libunwind
svn co http://llvm.org/svn/llvm-project/openmp/trunk openmp
svn co http://llvm.org/svn/llvm-project/libcxxabi/trunk libcxxabi
svn co http://llvm.org/svn/llvm-project/libcxx/trunk libcxx
Run Code Online (Sandbox Code Playgroud)首先,我使用gcc对libgcc和libstdc ++构建llvm,clang,libunwind并安装它们.在除了最后一个步骤之外的所有以下步骤中,我使用这个新鲜/ . …
以下(建议!)语法是否有任何缺点?
template< typename T >
void f() static_assert(std::is_same< T, int >::value)
{ ; }
Run Code Online (Sandbox Code Playgroud)
而不是SFINAE(看起来像拐杖):
template< typename T, typename = typename std::enable_if< std::is_same< T, int >::value >::type >
void f() { ; }
Run Code Online (Sandbox Code Playgroud)
甚至更糟:
template< typename T >
typename std::enable_if< std::is_same< T, int >::value >::type
f()
{ ; }
Run Code Online (Sandbox Code Playgroud)
禁止使用auto扣除结果类型.
是否有任何警告,让我们知道在海湾合作委员会中是否进行了NRVO/RVO?
我发现-fno-elide-constructors关闭NRVO/RVO,但NRVO/RVO有自己的条件发生,有时不会发生.当需要额外的复制构造时,需要知道是否发生了NRVO/RVO.
我对编译时功能特别感兴趣.如果有一些特定的#pragma GCC...(它会立即激活诊断)或使用静态断言机制的东西会很好.
#include <cassert>
#include <cmath>
int main()
{
struct point_of_cone
{
double x, y;
double z = [&] { using std::sqrt; return sqrt(x * x + y * y); }();
};
point_of_cone p = {3.0, 4.0};
assert(p.z == 5.0);
}
Run Code Online (Sandbox Code Playgroud)
适用于clang++来自中继的工作正常,但是g++从中继失败并出现错误消息(链接):
错误:没有为此lambda函数捕获'this'
point_of_conein namespace范围的定义适用于两者.
使用[this]lambda捕获进行略微修改的定义也适用于全局或局部范围.
哪个编译器是对的?
在统一初始化期间使用尾随逗号时是否存在任何潜在的语义差异?
std::vector< std::size_t > v1{5, }; // allowed syntax
std::vector< std::size_t > v2{10};
Run Code Online (Sandbox Code Playgroud)
我可以使用尾随逗号来使编译器选择std::vector::vector(std::initializer_list< std::size_t >)构造函数而不是std::vector::vector(std::size_t, const std::size_t &)或者是否有任何其他提及语法的技巧?
我可以使用它来检测是否有 - std::initializer_list构造函数重载?
考虑以下代码,必须选择哪个构造函数?
struct A { A(int) { ; } A(double, int = 3) { ; } };
A a{1};
A b{2, };
Run Code Online (Sandbox Code Playgroud)
此代码是由受理gcc 8并A(int)在两种情况下被选中.