草庐IT

c++ - 为什么 C++ 设计者选择不允许非成员运算符 ()()?

我只是在玩std::function和operators,使C++语句看起来像函数式语言(F#),发现operator()之间有区别和operator.我的代码:函数1(运算符重载):functionoperator>>(functionf1,functionf2){functionf3=[=](intx){returnf1(f2(x));};returnf3;}函数2(运算符重载):functionoperator>>(functionf1,functionf2){functionf3=[=](intx,inty){returnf2(f1(x,y));};returnf3;}函数3(

c++ - 没有优化的 g++ 4.9 上静态 constexpr 的 undefined reference

我有以下代码:#include#includeusingnamespacestd::chrono_literals;#defineMSG"hello"#defineDUR1000msclassmwe{public:staticconstexprautomsg=MSG;staticconstexprautodur_1=DUR;staticconstexprstd::chrono::millisecondsdur_2=DUR;staticconststd::chrono::millisecondsdur_3;staticconstexprdecltype(DUR)dur_4=DUR;};c

c++ - Fedora 22 - 编译 - __atomic_is_lock_free

我尝试在Fedora22上编译一个软件(SuperCollider),但我遇到了一个问题:libsupernova.a(server.cpp.o):Infunction`std::atomic::is_lock_free()const':/usr/include/c++/5.1.1/atomic:212:undefinedreferenceto`__atomic_is_lock_free'collect2:error:ldreturned1exitstatusserver/supernova/CMakeFiles/supernova.dir/build.make:96:recipefo

c++ - 在 ubuntu 14.04 LTS 上编译 fileZilla

我正在尝试从其源代码编译FileZilla。它需要C++14支持,而gcc4.9是必需的。4.8以上的版本,我都尝试安装,没有任何变化。难道上面的ubuntu版本没有gcc4.9吗?我得到的错误是:checkingwhetherg++supportsC++14featuresbydefault...nocheckingwhetherg++supportsC++14featureswith-std=gnu++14...nocheckingwhetherg++supportsC++14featureswith-std=gnu++1y...nocheckingwhetherg++suppor

c++ - 'default_random_engine' 不是 std 的成员

我发现了很多关于这个主题的问题,但所有问题似乎都与不使用C++11编译有关。我的代码是#includeintmain(intargc,char*argv[]){std::default_random_enginegenerator;return0;}即使我用编译gcc-std=c++0xtestmain.cpp给出default_random_engine不是std成员的错误。该程序是在远程机器上编译的,我自己不维护,但gcc-v生成4.4.7版本。有什么想法吗? 最佳答案 对于其他人:检查您是否真的在#include中包含了随机数

c++ - sscanf 中 uint16_t 的正确且可移植的 (Clang/GCC) 修饰符是什么?

当我尝试编译这段代码时收到一条警告消息sscanf(value,"%h"PRIu16"B",&packet_size)使用Clang600.0.57(OSX)。warning:formatspecifiestype'unsignedchar*'buttheargumenthastype'uint16_t*'(aka'unsignedshort*')[-Wformat]if(sscanf(value,"%h"PRIu16"B",&packet_size)==1){~~~~^~~~~~~~~~~~但是如果我删除修饰符“h”,那么我会在GCC4.8.3(ScientificLinux7)中收

c++ - enable_if 的句法模式

我一直以这种近似的方式对各种版本的GCC(最高5.2)使用enable_if:template...>voidfn(){std::cout...>voidfn(){std::cout();fn();但是,事实证明,Clang3.7不接受这一点(“对‘fn’的调用不明确”)。Q1。谁是对的,为什么?当然还有其他方法可以做到,但我有点不喜欢templatestd::enable_if_tfa(){std::cout及其类似的方法使函数签名的正常部分更难阅读,并且template=0>voidfd(){std::cout用于涉及不相关的元素(类型和值)。Q2。还有哪些其他(正确、更易读、更少

具有位字段的结构的 C++ 大小

我有以下三个union:typedefunion{struct{uint16_t:2;uint16_tnumberOfWords:10;uint16_t:4;uint16_tdataFormat:8;uint16_t:8;}bf;uint32_tdw;}HeaderT;typedefunion{struct{uint16_t:4;uint16_tlsb:8;uint16_t:4;uint16_tmsb:8;uint16_t:8;}bf;uint32_tdw;}RegisterT;typedefunion{struct{uint16_t:2;uint16_tlsb:10;uint16_t

c++ - std::experimental::optional inside constexpr 函数

我想在我的constexpr函数中使用可选的习惯用法来轻松地阐明变量是否已设置。我对std::experimental::optional的尝试:constexprboolcall(){std::experimental::optionalr;r=true;//Error//Similarerrorwith://r=std::experimental::optional(true);if(!r){returnfalse;}return*r;}我得到错误:调用非constexpr函数-所以赋值是不可能的,因为这个操作不能是constexpr(Example)。但如果我实现自己的(非常丑陋

c++ - 编译器是否可以优化两个原子负载?

这个问题在这里已经有了答案:Whydon'tcompilersmergeredundantstd::atomicwrites?(9个回答)CanatomicloadsbemergedintheC++memorymodel?(2个答案)关闭5年前。在这种情况下,两个负载会合二为一吗?如果这取决于体系结构,那么来自英特尔的现代处理器会是什么情况?我相信原子负载等同于英特尔处理器中的正常负载。voidrun1(){autoa=atomic_var.load(std::memory_order_relaxed);autob=atomic_var.load(std::memory_order_r