草庐IT

vector-class-library

全部标签

c++ - Boost Graph Library astar和导航网格

我在做一个项目SFML/C++,我需要生成一个图来连接它们之间的障碍物以方便寻路,所以我有兴趣生成一个导航网格,我将应用boostA*算法。有点像这样:但是我在使用BoostGraphLibrary实现它时遇到了很多问题(如果您有一个更合适的库,我很感兴趣)。首先,我创建一个具有适当结构的adjacency_list:structWayPoint{sf::Vector2fpos;};structWayPointConnection{floatdist;};typedefboost::adjacency_listWayPointGraph;typedefWayPointGraph::ve

使用 vector/初始化列表的任何类型的 C++11 动态多维数组

如何创建维度在运行时确定的多维数组(矩阵)。最好的方法似乎是采用维度vector进行构建,同时采用偏移量vector来访问各个元素这也将允许使用初始化列表:这应该采用在编译时确定的类型矩阵,因此模板有意义C++11的特性要酌情使用,lambda加分示例用法:intmain(int,char**){staticconststd::size_td1{2};staticconststd::size_td2{3};staticconststd::size_td3{4};multi_vecq({d1,d2,d3});for(std::size_ti1=0;i1" 最佳

c++ - 如何使用存储在 c++ 中的 std vector 中的 std::list 迭代器制作复制安全容器?

对于我的GUI,我需要一个具有以下用途的类来管理控件(窗口、按钮等)通过[index]随机访问元素通过["key"]随机访问元素指针稳定性,因此ptr=&container[index]不会因添加或删除元素而改变复制安全。如果像container2=conatiner1(深层复制)那样使用“=”,则所有元素都必须存储在容器中并进行复制列表中元素的顺序必须可变,但指向元素的指针必须保持有效。如果ptr1=container[1]和ptr2=container[2],那么交换1和2的顺序后,ptr1==container[2]和ptr2==container[1]我得出的结论是std::l

c++ - g++ 错误 : specialization after instantiation (template class as friend)

考虑以下C++代码:templateclassSingleton{};classConcreteSingleton:publicSingleton{templatefriendclassSingleton;};intmain(){}Singleton应该是ConcreteSingleton的friend:它适用于Microsoft的可视化C++编译器。但是,我不能用g++4.8.4编译它。错误是:error:specializationof‘Singleton’afterinstantiationtemplatefriendclassSingleton;有什么办法可以解决吗?

c++ - 试图理解 C++ 标准中的 [class.qual]/2

根据我得到的答案here,尽管clang和vs2015接受它,但下面的代码格式错误。#includeclassA{public:A(){std::cout尽管如此,下面的代码似乎适用于所有3个编译器(参见liveexample)。AFAICT,根据[class.qual/2]代码格式错误。或者我在这里遗漏了什么?#includestructB{B(){std::cout此外,根据[class.qual]/2,下面的代码格式正确,在这种情况下,所有3个编译器都会产生预期的输出(参见示例here)。includestructB{B(){std::cout输出:B()A()B()但我想知道u

c++ - 如何使用 Cereal 序列化 boost::ptr_vector?

是否可以使用cereal序列化boost::ptr_vector实例?如果是,怎么办? 最佳答案 绝对有可能。您可以在存档和指针类型上创建外部save()和load()模板函数,如下所示:#include#include#include#include#include//Sampleserializableobject.structMyRecord{std::strings_;MyRecord(conststd::strings=std::string()):s_(s){}templatevoidserialize(Archive&

c++ - 如何使用删除函数按索引删除 std::vector<> 中的多个元素?

我有一个vectora存储值[01235]和其他vectorremovelist存储要删除的索引[012]以便在最后留下[35]。当我执行以下代码时,它会意外删除项目,因为vectora将在此过程中更改顺序。我有什么方法可以实现我的目标吗?for(inti=0;i 最佳答案 颠倒删除值的顺序,即使用removelist的反向迭代器。这当然依赖于removelist被排序。也许是这样的std::sort(removelist.begin(),removelist.end());//Makesurethecontainerissorte

c++ - boost::split 即使使用 token_compress_on 也会将空字符串推送到 vector

当输入字符串为空时,boost::split返回一个包含一个空字符串的vector。是否可以让boost::split返回一个空vector?MCVE:#include#include#includeintmain(){std::vectorresult;boost::split(result,"",boost::is_any_of(","),boost::algorithm::token_compress_on);std::cout输出:1期望的输出:0 最佳答案 压缩会压缩相邻的分隔符,不会避免空标记。如果您考虑以下几点,您就会

c++ - 编译cuda文件报错: "runtime library" mismatch value 'MDd_DynamicDebug' doesn't match value 'MTd_StaticDebug' in vectorAddition_cuda. o

我尝试在Qt5.2和MSVC2012环境下编译一个cuda文件。在开始我的项目之前,我仔细阅读了问题并回复:CompilingCudacodeinQtCreatoronWindows.但是即使我简单地复制代码并在qt中生成2个文件,仍然会弹出一些错误/main.cpp/vectorAddition.cu错误是:errorLNK2038:mismatchdetectedfor'RuntimeLibrary':value'MDd_DynamicDebug'doesn'tmatchvalue'MTd_StaticDebug'invectorAddition_cuda.o我完全不知道如何修复这

c++ - 如何测量共享内存中 boost 进程间 vector 的大小?

我正在使用boost::interprocess::vector在进程之间共享一些字符串,我想确保我不会溢出它所在的共享内存段。我如何找到vector在内存中占用多少空间,以及一个特殊的段分配字符串将占用多少内存?typedefboost::interprocess::managed_shared_memory::segment_managerSegmentManager;typedefboost::interprocess::allocatorCharAllocator;typedefboost::interprocess::basic_string,CharAllocator>Sh