草庐IT

Rolling_std

全部标签

c++ - 用于 Arduino IDE (xtensa-lx106-elf-gcc) 和 std::map 链接错误的 ESP8266

是否可以将ESP8266的map用于Arduino包?这是我的代码:#includetypedefstd::mapItems;voidsetup(){Itemsitems;items[2]=5;//items.emplace(4,5);}voidloop(){}这是编译/链接错误:Arduino:1.6.5(Windows8.1),Board:"GenericESP8266Module,Serial,80MHz,40MHz,DIO,115200,512K(64KSPIFFS)"sketch_oct31a.cpp.o:Infunction`loop':C:\ProgramFiles(x8

使用 std::atomic 的 C++ 线程安全增量,带模而不带互斥锁

我需要一个以循环方式使用的线程安全缓冲区对象池。我通常会在其中放置一个互斥锁以使增量和模线程安全,但是是否可以使用std::atomic来编写它?这是一个示例界面。如果它使事情变得更容易,缓冲区的总数可以是2的幂。永远不会在类外访问下一个缓冲区索引。classBuffer;classBufferManager{public:BufferManager(size_ttotalBuffers=8):mNextBufferIndex(0),mTotalBuffers(totalBuffers){mBuffers=newBuffer*[mTotalBuffers];}Buffer*GetNex

c++ - std::type_index 跨 DLL 是否安全

假设我有一个主DLL,其中有一个这样的类:classTest{public:typedefstd::unordered_mapMap;templatevoidSetValue(intval){SetValue(std::type_index(typeid(T)),val);}templateintGetValue(){returnGetValue(std::type_index(typeid(T)));}protected://Definedin.cppfilevoidSetValue(conststd::type_index&idx,intval){m_Map[idx]=val;}/

c++ - std::unique_ptr 使用带有少量参数的自定义删除器

我想知道是否可以使用多个参数(标准删除器签名)为std::unique_ptr指定自定义删除器。我知道std::shared_ptr存在std::bind的解决方法,这使得它成为可能但是std::unique_ptr存在一些技巧吗?对我来说似乎不是因为根据http://en.cppreference.com/w/cpp/memory/unique_ptr:Typerequirements-DeletermustbeFunctionObjectorlvaluereferencetoaFunctionObjectorlvaluereferencetofunction,callablewit

c++ - std::map 通过变换替换现有元素

我有一个代码:std::vectorvector={1,3,5,7,9};usingmy_type=std::pair;std::map>map;for(constauto&i:vector){map[i]=boost::none;}constmy_typeval={1,5};std::transform(vector.cbegin(),vector.cend(),std::inserter(map,map.end()),[&val](constint&i){returnstd::make_pair(i,boost::optional(val));});一切正常,但std::trans

c++ - 为什么在抛出 'std::bad_alloc' 实例后调用终止?

每1秒,函数工作一次。我的系统是linux。奔跑突然死亡。-----global-------staticintarrayNum[33000];-------------------function(){unsignedshortint**US_INT;US_INT=newunsignedshortint*[255];for(inti=0;i程序停止。和留言↓在抛出“std::bad_alloc”的实例后终止调用what():std::bad_alloc 最佳答案 bad_alloc异常是由内存分配失败触发的(因此您的new之一)。

c++ - 将 std::bitset 分成两半?

我正在实现DES算法,我需要拆分std::bitsetpermutationKey分成两半。std::bitsetpermutationKey(0x133457799BBCDF);std::bitsetleftKey;std::bitsetrightKey;std::bitsetdivider(0b00000000000000000000000000001111111111111111111111111111);rightKey=permutationKey÷r;leftKey=(permutationKey>>28)÷r;我试着打字bitset至bitset但

c++ - 将 initializer_list 插入 std::vector 时出现 "Invalid iterator range"

此代码在Ideone上按预期编译并运行良好:#include#include#includeintmain(){std::vectorstrVec;strVec.insert(strVec.end(),{L"black",L"white",L"red"});strVec.insert(strVec.end(),{L"blue",L"green"});//STLexceptionfor(auto&i:strVec){std::wcout但是,在MSVC(VisualStudio2013)中因“无效的迭代器范围”而失败。有什么见解吗?顺便说一句,插入更多元素是可行的,例如在第二个插入中,这

c++ - Valgrind 下 Mac OS 上的 std::thread.join() SIGSEGV

以下简单代码(C++11)将仅在MacOS和Linux上运行:#include#include#includevoidthreadFunction(){for(intcc=0;cc但是,在Valgrind中包装执行:valgrind--leak-check=full--show-reachable=no--track-fds=yes--error-exitcode=1--track-origins=yes./theexecutable...它现在可以在Linux上运行,但不能在MacOSX上运行,失败:==47544==Processterminatingwithdefaultacti

c++ - 为什么我需要在临时 dynamic_bitset 上调用 std::move?

我在这里讲一个冗长的背景故事,因为除了直接回答之外,我还想知道我导致这种情况的推理是否正确。我有一个接受dynamic_bitset的函数参数(来自Boost.dynamic_bitset)。说它看起来像这样。voidfoo(boost::dynamic_bitsetdb){//dostuff}碰巧它只被临时调用,从构造函数构建,如foo(boost::dynamic_bitset{5}.set())(使用5位位集调用所有位集)。我的位集只有少量的位(少于32)。所以起初,我想“我只是按值传递它;拷贝比指针小。”但后来我想“它是动态的,所以它必须在堆上分配空间。我想避免不必要的分配和释