草庐IT

sequence-points

全部标签

c++ - SSE 和 iostream : wrong output for floating point types

测试.cpp:#includeusingnamespacestd;intmain(){doublepi=3.14;cout当使用g++-mno-ssetest.cpp在cygwin64位上编译时,输出为:pi:0但是,如果使用g++test.cpp编译,它可以正常工作。.我有GCC版本5.4.0。 最佳答案 是的,我复制了这个。嗯,主要是。我实际上没有得到0的输出,而是一些其他的垃圾输出。所以我可以重现无效的行为,并且我已经查明了原因。您可以看到GCC5.4.0使用-m64-mno-sse标志hereonGoldbolt'sComp

c++ - 删除指向不完整类型的指针 'Point' ;没有调用析构函数

我有2个文件:Point.h:classPoint{intx;inty;char*name;public:Point(){name=newchar[5];}~Point(){delete[]name;}};和:Line.h:classPoint;classLine{Point*p;public:Line(){p=newPoint[2];.......}~Line(){delete[]p;}};但是当我编译时,我得到了下一个错误:deletionofpointertoincompletetype'Point';nodestructorcalled感谢任何帮助!

c++ - 对象成员的迭代器 "pointing"

我承认我很难对此做出合理的描述。我想不出一个好词来准确描述我正在寻找的东西。也许这可以称为切片迭代器。假设我有这样的东西:structS{inti;char*s;floatf;};std::vectorv(10);我正在寻找一种构造迭代器的方法,它将指向S的成员。我希望能够将它传递给std::min_element之类的东西,而无需在每种情况下都创建谓词。可能看起来像这样的东西:std::min_element(slicing_iterator(v.begin(),S::f),slicing_iterator(v.end(),S::f));我可以使用任何模板技巧来实现这一目标吗?或者它

c++ - g++ 和 clang++ 在 `std::make_index_sequence` 和 `std::index_sequence` 用于模板参数默认类型时的不同行为

另一个“g++和clang++之间谁是正确的?”C++标准专家的问题。给定以下代码#includetemplate>structfoo;templatestructfoo>{};templatevoidbar(fooconst&){}intmain(){bar(foo{});}我看到g++编译时clang++给出了以下错误tmp_003-14,gcc,clang.cpp:32:4:error:nomatchingfunctionforcallto'bar'bar(foo{});^~~tmp_003-14,gcc,clang.cpp:27:6:note:candidatetemplate

c++ - std::chrono:将自定义持续时间添加到 time_point

以下代码可以编译(g++4.7.2):#includetypedefstd::chrono::durationdouble_prec_seconds;typedefstd::chrono::time_pointtimepoint_t;voiddo_something(consttimepoint_t&tm){//...}intmain(intargc,char**argv){timepoint_tt0=std::chrono::system_clock::now();timepoint_tt1=t0+std::chrono::seconds(3);//timepoint_tt3=t0+

c++ - 如何将分数纪元时间戳( double )转换为 std::chrono::time_point?

我有一个小数纪元时间戳,表示为double,我想将其转换为适当的std::chrono::time_point。纪元是自1/1/1970以来的常用UNIX纪元。我知道存在std::chrono::system_clock::from_time_t,但是time_t没有小数部分。使用C++11方法执行此操作的最佳方法是什么?这个问题与unixtimestamptoboost::posix_time::ptime有关,除了它要求的是C++11而不是它的Boost版本。 最佳答案 假设纪元与已知的时钟类型相同,您可以使用具有double表

c++ - "release sequence"是什么意思?

我不明白,为什么没有releasesequence会出问题,如果我们在下面的示例中有2个线程。我们对原子变量count只有2个操作.count如输出所示,按顺序递减。来自安东尼威廉姆斯的C++ConcurrencyinAction:Imentionedthatyoucouldgetasynchronizes-withrelationshipbetweenastoretoanatomicvariableandaloadofthatatomicvariablefromanotherthread,evenwhenthere’sasequenceofread-modify-writeopera

c++ - 将 steady_clock::time_point 转换为 time_t

我正在使用steady_clock来保存一些消息的时间戳。出于调试目的,拥有日历(或类似的东西)很有用。对于其他时钟,有静态函数to_time_t,但在GCC(MinGW4.8.0)上,此函数不存在。现在我打印类似的东西:Timestamp:26735259098242对于时间戳,我需要一个steady_clock,所以我不能使用system_clock或其他。编辑之前的打印是从time_since_epoch().count()给出的 最佳答案 假设您需要内部计算的稳定行为,而不是显示,这里有一个函数可用于转换为time_t以供显

c++ - 获取 POSIX 纪元作为 system_clock::time_point

我知道std::chrono::system_clock::time_point的默认值是时钟的纪元,但我在C++11标准中找不到任何规定system_clock的纪元与POSIX纪元(1970-01-01T00:00:00Z)相同。在Linux和Windows上假设是这种情况是否安全?或者使用std::chrono::system_clock::from_time_t(0)会更聪明吗? 最佳答案 标准离开std::chrono::system_clock::time_point的纪元未指定。std::chrono::system_

c++ - 将 std::integer_sequence 作为模板参数传递给元函数

如何将std::integer_sequence作为模板参数传递给元函数(即不是函数模板)?给出例如以下用例(但不限于此):我想使用整数序列从参数包中删除最后的N类型。我想我可以使用thisSOquestion中的selector,但我未能将整数序列传递给此元函数。#include#includetemplatestructselector{usingtype=std::tuple::type...>;};templatestructremove_last_n{usingIndices=std::make_index_sequence;usingtype=typenameselecto