草庐IT

list_type

全部标签

c++ - std::map<key_type, value_type>::find(different_key_type)

我有一张map:std::mapmyMap;但是,在某些情况下,我想通过比较TyString==TyStringRef来std::map::find一个条目,即myMap.find(TyStringRef("MyString"));原因是TyString包装了一个它自己分配和释放的constchar*。但是,为了只找到一个条目,我不喜欢分配一个新的字符串,而是我只想使用引用(TyStringRef只包装一个constchar*而不分配或释放内存)。当然,我可以将TyStringRef转换为TyString,但这样我就有了上述的内存开销。有解决这个问题的智能方法吗?谢谢!

C++ 仿函数和模板 : error: declaration of 'class List<T>'

我在模板类中有一个嵌套模板,用于名为List::find()的方法。此方法获取一个仿函数作为输入,即:“函数条件”。templateclassList{....templateIteratorfind(Functioncondition)const;....};templatetypenameList::IteratorList::find(Functioncondition)const{List::Iteratorit=this->begin();for(;it!=this->end();++it){if(condition(*it)){break;}}returnit;}错误是:.

c++ - 删除时 std::list end() 迭代器位置是否改变?

在下面的循环中,我使用了一个预先计算好的结束迭代器:std::list::iteratorend=MyList.end();for(std::list::iteratorit=MyList.begin();it!=end;)it=MyList.erase(it);当删除std::list中的元素时,MyList.end()是否可以更改其值以便end!=MyList.end()不再存在? 最佳答案 没有。n337623.3.5.4iteratorerase(const_iteratorposition);iteratorerase(c

c++ - 如何将 boost::graph 算法与 listS、setS 作为顶点/边缘容器一起使用?

使用boost::graph库的boost示例通常使用像这样的图usingnamespaceboost;typedefadjacency_list,property>graph;因此它们工作得很好。但我有一个图表typedefadjacency_listgraph;并且算法不是开箱即用的。在大多数情况下,必须提供用于查找特定顶点索引(整数值)的vertex_descriptor的映射。我想检查我的图是否是平面图并计算它的平面嵌入。我提供了一个顶点索引图,它确实以这种方式工作,例如connected_components算法,但显然不适用于boyer_myrvold_planarity_

c++ - 为什么 list<unique_ptr> 中的 unique_ptr 的 std::move() 没有真正 move 它?

usingPtr=std::unique_ptr;Ptrf(boolarg){std::listlist;Ptrptr(newint(1));list.push_back(std::move(ptr));if(arg){Ptr&&obj1=std::move(list.front());//Here|obj1|and|list.front()|stillpointtothesamelocation!list.pop_front();returnstd::move(obj1);}else{Ptrobj2=std::move(list.front());list.pop_front();r

c++ - C/C++ 下划线 t/type (_t/_type) 和类名?

我理解下划线t(_t)是用来标识类型的,下划线type(_type)也是,通常在typedef语句中.用法是否略有不同(例如,模板使用下划线类型,非模板使用下划线t)?为什么不在声明中使用它们?例如:classperson_t{};enumerror_t{};这与之前关于下划线t的问题不同,因为它还要求区分下划线类型。此外,(盲目地)很明显,这两个后缀只是约定俗成,但不清楚为什么它们都用于C++标准。例如,std::size_t与std::istream::pos_type。 最佳答案 对于您的第一个问题,我不知道有任何答案,我相信

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++ - 将 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++ - 增强融合 : convert adapted struct type to text

给定一个这样的结构:structFoo{intx;inty;doublez;};BOOST_FUSION_ADAPT_STRUCT(Foo,x,y,z);我想生成这样的字符串:"{intx;inty;doublez;}"我已经看到如何printthevaluesFusion改编的结构,但在这里我只需要打印类型和名称。我怎样才能最简单地做到这一点?如果有更好的方法,我不会嫁给Boost.Fusion。 最佳答案 我认为您可以通过对thisanswer中的代码稍作修改来获得与您想要的类似的东西。.您可以使用boost::fusion::

c++ - std::list<bool> 的实现

是否std::list具有类似的疯狂,像std::vector这样的明确特化?是std::vector唯一受此影响的C++标准库容器?是否有某种traits我可以用来检测特化吗? 最佳答案 如标准所示,std::vector有它自己的段落来规定它的实现。std::list的要求有一个不存在,但这并不意味着不允许实现不但是有一个。据我所知,std::vector是唯一需要具有bool特化的容器. 关于c++-std::list的实现,我们在StackOverflow上找到一个类似的问题: