草庐IT

the_struct

全部标签

C++标准写法: Does "through all iterators in the range" imply sequentiality?

ThisSOquestion引发了关于std::generate和标准做出的保证的讨论。特别是,你能否使用具有内部状态的函数对象并依赖于generate(it1,it2,gen)来调用gen(),将结果存储在*it,再调用gen(),存入*(it+1)等,还是可以从后面开始,比如?标准(n3337,§25.3.7/1)是这样说的:Effects:Thefirstalgorithminvokesthefunctionobjectgenandassignsthereturnvalueofgenthroughalltheiteratorsintherange[first,last).Thes

c++ - MacOS 中是否有针对 "struct timeval"的 nanosleep 函数?

我在MacOS(OSXElCapitan10.11.2)中记录时间间隔(至少以毫秒为单位)时遇到问题。显然,基本思想是记录两次时间并进行减法。当我发现“sys/time.h”中有gettimeofday()和这个函数的结构-structtimeval时,问题就发生了。然后拿到时间间隔,想让它按照时间间隔休眠。但是,似乎nanosleep()或usleep()没有时间类型的参数(忽略sleep(),因为我至少需要毫秒)。我应该转换timeval以适应nanosleep()或usleep()还是有更好更简单的方法? 最佳答案 此示例使用

c++ - boost 异步读/写失败, "Insufficient system resources exist to complete the requested service"

我(貌似)随机收到错误:"Insufficientsystemresourcesexisttocompletetherequestedservice"当使用boost::asio::async_read_until或boost::asio::async_write串口时。将串行端口声明为:boost::asio::serial_portmSerialPort;在这个错误之后,我尝试try{mSerialPort.cancel();mSerialPort.close();}catch(boost::system::system_errorerror){;}其中一个(尚不确定是哪个)挂起并

c++ - Size of the Byte 是否可以大于 octet 8 bits

我正在浏览http://www.parashift.com/c++-faq/index.html在那里我发现字节也可以是64位http://www.parashift.com/c++-faq/very-large-bytes.html.一个字节的那么多存储容量有什么用? 最佳答案 重点不在于大字节“本身”的用处,而在于,对于标准而言,字节是系统上的最小可寻址数量1;如果系统无法以小于64位的单位寻址其内存,则char将为64位。显然,在现代通用计算机上几乎不可能找到这种奇怪的东西,这些奇怪的东西出现在非常专业的硬件上(我听说DSP特

c++ - 振奋 spirit : What type names should be used for the built in terminals?

我正在重构一个类型系统(类型模型),它使用spirit进行字符串序列化。我正在使用类型特征的编译时建模构造。templatetype_traits{typedefboost::spirit::qi::int_parserstring_parser;}templatetype_traits{typedefboost::spirit::ascii::stringstring_parser;}在这个例子中,我展示了原始解析器,但我希望也加入规则。int4类型有效,但这是因为(home/qi/numeric/int.hpp+27):namespacetag{templatestructint_

c++ - dynamic的动态数组(array of struct)

我有一个名为person的结构,如下所示:structperson{intheight,weight;};我还创建了一个person数组,如下所示:structArrayofperson{intlen;//indicatesthelengthofthisarray(itssupposedtobedynamic)person*p;//thisissupposedtobethedynamicarrayofperson.};我对person的数组执行此操作,如下所示:structArray_2d_ofperson{intlen;//indicatesthelengthofthisarray(

c++ - VS2013 : How to disable warnings for included header files outside of the project

在我的项目中,我包含了一个由外部库提供的头文件。使用/W3,所有内容都可以在没有警告的情况下编译。但是,我希望我的项目能够使用/W4进行干净地编译。这对我的代码来说没有问题,但外部header会发出大量警告。我知道我可以做这样的事情:#pragmawarning(push)#pragmawarning(disable:####)//includehere#pragmawarning(pop)但是有一长串要禁用的警告。有没有一种方法可以在包含此header时将警告级别设置回/W3,同时仍使用/W4编译我的其余代码?谢谢! 最佳答案 #

c++ - 使用省略号的回退函数 : can we force the size of the parameters pack?

考虑以下代码:#include#includestructS{templateautof(A&&...args)->decltype(std::declval().f(std::forward(args)...),void()){std::coutvoidf(...){std::cout(42);//->hasf(int)s.f(42);//->hasnotf(int)//oopss.f();//->hasnotf(int)}如示例所示,对f的第三次调用工作正常,即使参数数量错误,因为对于回退函数来说它根本没有错.当以这种方式涉及省略号时,有没有办法强制参数的数量?我的意思是,我可以在

c++ - 几个线程 : catching the moment when they all finish work

我有几个线程,我需要捕获它们全部完成工作的时刻。怎么做?for(inti=1;i 最佳答案 考虑在forblock之外创建std::thread对象并调用join()而不是detach()://empty(nothreadsassociatedtothemyet)std::arraythreads1,threads2;for(inti=0;i不调用detach()意味着必须在std的析构函数之前调用join()::thread对象被调用(无论线程是否已经完成)。出于这个原因,我将std::thread对象放在了forblock之外。

c++ - C 和 C++ header : Define global struct inside of another struct

我有一些C代码,其中有一些结构如下所示:typedefstructmy_library_a_tmy_library_a_t;typedefstructmy_library_b_tmy_library_b_t;typedefstructmy_library_c_tmy_library_c_t;structmy_library_a_t{structmy_library_b_t{intdata;structmy_library_c_t{intdata;}c;}b;intdata;};这在C++中不起作用,因为在C中structmy_library_b_t定义了一个全局structmy_lib