草庐IT

is_iterator

全部标签

c++ - forward_list::splice_after( const_iterator pos, forward_list& other, const_iterator i ) 功能

我正在阅读有关此功能工作方式的不同解释。cplusplus.com说这个函数应该“直接在i之后移动元素”。然而cppreference.com表示它拼接元素ATi。MSvisualstudio同意cplusplus.com。但是,实际上正确的行为是什么?我倾向于认为“在i之后”移动更合乎逻辑(&不需要N时间来找到前面的节点)。(PS:没有forward-list标签?) 最佳答案 23.3.4.6voidsplice_after(const_iteratorposition,forward_list&x,const_iterator

C++ directory_iterator

自从我使用C++以来已经有一段时间了,请原谅我的新手问题。我编写了以下代码来获取目录内容的列表,它运行良好:for(directory_iteratorend,dir("./");dir!=end;dir++){std::cout“*dir”返回什么,一个“字符数组”指针,一个指向“字符串”对象的指针,还是一个指向“路径”对象的指针?我想将“*dir”(如果它以.cpp结尾)传递给另一个function(),它将在稍后(异步)对其进行操作。我想我需要复制“*dir”。我写了下面的代码:path*_path;for(directory_iteratorend,dir("./");dir!

c++ - 使用 std::istream_iterator 读取最多 N 个值

如果我确定我的输入流包含10个值,我可以读取它们std::copy_n(std::istream_iterator(input),10,output);如果我不知道我有多少值,我可以读取所有值std::copy(std::istream_iterator(input),std::istream_iterator(),output);我的问题是如何读取最多10个值。我在这里尝试对I/O错误保持鲁棒性,但似乎copy_n将尝试读取输入的末尾(它不知道它应该停止),并且copy不会在10个值处停止.我必须推出自己的copy_at_most吗?(嗯,显然对copy_n还是有些混淆:std::i

c++ - 调试断言失败_BLOCK_TYPE_IS_VALID(pHead->nBlockUse)

我遇到了这个问题:调试断言失败!文件:f:\dd\vctools\crt_bld\self_x86\crt\dbgdel.cpp第52行表达式“_BLOCK_TYPE_IS_VALID(pHead->nBlockUse)我的程序正确地将所有值返回到我期望的屏幕,但是这个问题让我紧张...#include#include#includeusingnamespacestd;double*wsk1;double*wsk2;double*wsk3;double*kopiowanie(double*wsk1,double*wsk2,double*wsk3);double*zaladuj(doub

c++ - 谷歌模拟 : Is it ok to use global mock objects?

在所有关于gmock的文档中,我总是发现要在测试中实例化模拟对象,就像这样:TEST(Bim,Bam){MyMockClassmyMockObj;EXPECT_CALL(MyMockObj,foo(_));...}因此,对象在每次测试时都会被创建和销毁。我相信为每个测试夹具创建和销毁对象也完全没问题。但我想知道是否也可以拥有模拟对象的文件全局实例,就像这样:MyMockClassmyMockObj;TEST(Bim,Bam){EXPECT_CALL(MyMockObj,foo(_))...}我试过了,到目前为止我完全没有问题,一切似乎都很好。但也许我应该知道什么?只是因为我偶然发现了t

C++ 在 ‘value_type’ 中没有名为 ‘struct std::iterator_traits<int>' 的类型

你好。我正在尝试运行以下代码(仅用于培训目的):#include#includetemplate>classkont>typenamestd::iterator_traits::value_typefoo_test(typenamekont::iteratorb){return*b;}templatetypenamestd::iterator_traits::value_typeminimum(Iterb,Itere){Iterm=b;/*CODE*/return*m;}intmain(void){std::listx;x.push_back(10);x.push_back(100);

c++ - std::is_trivially_equality_comparable_v<T>

相关但比C++11staticassertforequalitycomparabletype?神秘得多—JFBastien的论文N4130"PadThyAtomics!"让我想到如果我们要使用atomic::compare_exchange_weak()其中T是类或者结构类型,比如structCount{intstrong_count;intweak_count;};然后我们真的想静态断言两件事:首先,T实际上是无锁原子的:templatestaticconstexprboolis_lockfree_atomic_v=std::atomic::is_always_lock_free;其

c++ - boost::interprocess : cout a string variable when iterating through a map that references an object from a struct

我正在使用boost::interprocess在进程之间共享对象。我有两个文件,一个生成结构对象并将该对象传递到具有int索引的映射中的“server.cpp”;和一个“client.cpp”文件,它检索内存数据并遍历数据,输出到控制台。结构看起来像这样:structmydatao{stringMY_STRING;intMY_INT;};和对象:mydatao;o.MY_STRING="hello";o.MY_INT=45;服务器和客户端都能正确编译。但是出于某种原因,如果我尝试访问客户端中的字符串而不是float或整数,客户端可执行文件会抛出段错误。例如下面的second.MY_I

c++ - `reverse_iterator`的限制原因

关于thecppreferencepageofreverse_iterator我发现以下评论std::reverse_iteratordoesnotworkwithiteratorsthatreturnareferencetoamemberobject(so-called"stashingiterators").Anexampleofstashingiteratorisstd::filesystem::path::iterator.这种说法正确吗?而且,如果是,那是为什么?对我来说,限制是没有意义的,因为我假设反向迭代器基本上交换了operator++和operator--(并存储底层

c++ - boost static_vector 而不是 std::is_trivially_destructible

根据thisexample(左例)#include#includestructX{intk;std::arraya;boost::container::static_vectorb;~X()=default;};inthuh(){std::arrayx;return0;}看起来像boost::container::static_vector当T时可以轻易破坏是(当b被销毁时,不会在X上循环)。huh优化为xoreax,eax;ret(即return0不遍历数组。当我改用具有非平凡析构函数的包含类型时(右例)#include#includestructY{~Y();};structX{i