草庐IT

atomic-values

全部标签

c++ - 根据 value_type 调用适当的构造函数 : integer or float

我有一个函数,它使用均匀分布将最小值和最大值之间的随机值填充到容器中。#include#include#include#includetemplatevoiduniform_random(TContainer&container,consttypenameTContainer::value_typemin,consttypenameTContainer::value_typemax){std::random_devicerd;std::mt19937gen(rd());//Belowlinedoesnotworkwithintegerscontainerstd::uniform_rea

c++ - 如何在 while 循环中计算 "std::cin>>value"?

目前正在自学C++Primer5th。这里有一些我不确定的东西。(我在F.A.Q上找不到确切的相关问题)。考虑这个while循环:while(std::cin>>value){...}\\valueherewasdefinedasint.课本上说:Thatexpressionreadsthenextnumberfromthestandardinputandstoresthatnumberinvalue.Theinputoperator(§1.2,p.8)returnsitsleftoperand,whichinthiscaseisstd::cin.Thiscondition,there

c++ - 错误 C2106 : '=' : left operand must be l-value

查看有关错误C2106的其他问题,我仍然不知道我的代码有什么问题。编译时出现以下错误:c:\driver.cpp(99):errorC2106:'=':leftoperandmustbel-valuec:\driver.cpp(169):errorC2106:'=':leftoperandmustbel-value代码行如下:payroll.at(i)=NULL;//Line99payroll.at(count++)=ePtr;//Line169我不明白为什么会抛出这个错误。在这个项目中,我将我的driver.cpp从员工对象指针数组更改为我制作的自定义Vector模板。我声明Vect

c++ - Ada 到 C++ : Pass an unsigned 64-bit value

我需要将2条数据从Ada程序传递给一些C++代码进行处理。数据-双倍。时间-无符号64位。我能够使用Long_Float(在C++中为double)和Integer(在C++中为int,但显然不是64位)在Ada中创建一个与我的C++方法一起工作的过程。我使用了以下代码(代码不在我身上,所以语法可能略有偏差):proceduresend_data(this:inhidden_ptr;data:inLong_Float;time:inInteger);pragmaimport(CPP,send_data,"MyClass::sendData");现在它正在运行,我正在尝试将时间扩展到完整

c++ - 什么时候需要在 Ruby C 扩展中声明 volatile VALUE?

我找不到很多文档来说明何时适合在Ruby扩展中将VALUE声明为volatile以避免对正在使用的对象进行过早的垃圾回收。这是我到目前为止学到的东西。任何人都可以填空吗?当volatile不需要使用时:在C++对象成员中(因为它们永远不会在堆栈上?)在不调用RubyAPI的C/C++方法中(因为GC在调用RubyAPI之前不会打开)当volatile确实需要使用在调用任何RubyALLOC或malloc宏/函数的C/C++方法中(因为当内存高度碎片化时这些会触发GC)在调用任何Ruby函数的C/C++方法中(例如,rb_funcall、rb_ary_new等)其他避免GC的方法标记正在

c++ - 统一和值(value)初始化

这个问题在这里已经有了答案:g++4.9rejectsvalidaggregateinitializationinC++14(1个回答)关闭7年前。我尝试对构造函数使用值初始化的成员使用值初始化(我不知道我是否真的使用了好的术语......)所以...当我定义:structA{inta_;};我可以使用:Aa{5};assert(m.a_==5);但是,如果我想使用成员大括号初始化器和初始化列表构造器structB{intb_{1};};这无法编译(c++14:http://ideone.com/MQ1FMU):Bb{2};这里是错误:prog.cpp:19:7:error:nomat

c++ - GCCs atomic builtins - 支持哪些处理器

Thisdocument说:Notalloperationsaresupportedbyalltargetprocessors.有人知道哪个处理器支持哪个操作吗? 最佳答案 不是直接的答案,但链接页面中的以下片段提供了线索(重点是我的):Notalloperationsaresupportedbyalltargetprocessors.Ifaparticularoperationcannotbeimplementedonthetargetprocessor,awarningwillbegeneratedandacallanexter

c++ - 为什么 weak_ptr 没有 atomic_{store,load}?

为什么C++标准包含atomic_store或atomic_load重载shared_ptr而不是weak_ptr?这只是一个疏忽,还是有没有为weak_ptr提供原子操作的实际原因? 最佳答案 这似乎是一个疏忽。HerbSutter为atomic_shared_ptr/atomic_unique_ptr/atomic_weak_ptr提出了一个C++(17?)标准设计提案,该文档还解释了现有方法的缺点,其中包含用于shared_ptr的免费函数atomic_load/atomic_store:http://www.open-std

c++ - std::atomic 不受 clang 支持?

我正在尝试将std::atomic与clang一起使用。但是,每当我尝试包含头文件原子(#include)时,我都会收到消息“找不到原子”。请注意,我包括-std=c++11-stdlib=libc++编译时。我错过了什么?我使用的clang版本是3.2。 最佳答案 TheversionofclangI'musingis3.2.Clang根据LLVMCXXStatus添加了跨两个不同版本的原子支持.第一个是Clang3.1,第二个是Clang3.2。我认为您可以使用以下方式检查它:#ifdefined(__clang__)#if__

c++ - while (std::cin >> value) 如何工作?

在C++Primer中给出的示例中,#includeusingnamespacestd;intmain(){intsum=0,value=0;while(std::cin>>value){sum+=value;//equivalenttosum=sum+value}std::cout(std::cin>>value)如何返回true?什么是“文件结尾”?看来我必须理解该术语才能理解我的主要问题。谢谢! 最佳答案 overloadedoperator>>function返回对流本身的引用,流有anoverloadedoperator这