草庐IT

std-span

全部标签

用std :: vector< std :: string&gt填充虚拟listView;

我有成千上万个字符串的向量:std::vectora;充满了一些算法。遵循描述的方法这里,这是我创建一个ListView作为“虚拟列表”:hList=CreateWindowEx(0,WC_LISTVIEW,L"",WS_CHILD|WS_VISIBLE|LVS_REPORT|LVS_OWNERDATA,0,0,800,400,hWnd,(HMENU)ID_LISTVIEW,hInst,NULL);LV_COLUMNlvcol;...ListView_InsertColumn(hList,0,&lvcol);ListView_SetItemCountEx(hList,100000,LVSICF

c++ - std::bool_constant 背后的基本原理

我想知道,引入std::bool_constant背后的基本原理是什么?及其随后用于std::true_type和std::false_type(以及在头文件中定义的比较结构,参见N4389)在C++17中?到目前为止,我只能找到包含以下措辞的论文:http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4334.htmlhttp://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4389.html虽然这两篇论文都提到了“基本原理”——https://issues.isocp

C++:使用 "Undefined symbols for architecture x86_64"时出现 "std"错误

我是一名新的C++程序员,我正在尝试运行一个简单的我已经创建了一个文件“test.cpp”,我正在使用gcc在命令行上对其进行编译。命令是“gcctest.cpp-otest”。然后我运行“./test”。(是的,这个过程听起来很基本。)文件如下:#includeintmain(){printf("HelloWorld!");std::cout当我包含包含std的行时,gcc返回以下长错误:Undefinedsymbolsforarchitecturex86_64:"std::__1::locale::use_facet(std::__1::locale::id&)const",ref

c++ - std::static_pointer_cast 与 static_cast<std::shared_ptr<A>>

我有一个类层次结构,其中B源自A像这样:classA:publicstd::enable_shared_from_this{};classB:publicA{voidf(){//thecodebelowcompilesstd::shared_ptrcopyOfThis=std::static_pointer_cast(shared_from_this());//thecodebelowdoesnotstd::shared_ptrcopyOfThis=static_cast>(std::make_shared(shared_from_this()));}};所以实际上我想了解为什么我不能

C++:std "magically"在那里吗?总是?

作为一名C++初级程序员,我注意到无论您使用什么IDE/编译器,您都不需要显式包含STL(标准模板库)。这是否意味着我可以依赖STL“始终可用”?我的意思是如果我想使用std::cout例如,我只包括iostreamSTL的一部分:#include...并且不需要做类似#include的事情首先继续进行类似的操作:std::cout此外:我可以依赖STL的一致性吗?STL的每个函数/方法是否总是以相同的方式运行?或者C++版本、操作系统或编译器之间是否有任何变化?我问这个是因为当您不知道某些陷阱时,其他库有时真的很痛苦。例如,Eigen(用于线性代数的东西)对我来说真的很难让它继续下去

c++ - std::reduce 似乎将结果转换为整数

这个问题在这里已经有了答案:C++std::accumulatedoesn'tgivetheexpectedsum(6个答案)关闭3年前。我正在比较这两个函数:doublepolynomials(constvector&coeffs,doublex){doublesum=0.0;doublefactor=1.0;for(doublecoeff:coeffs){sum+=coeff*factor;factor*=x;}returnsum;}和doublealgorithm_polynomials(constvector&coeffs,doublex){returnreduce(execu

c++ - 在模板中返回 std::set<T>::iterator 时出错

我正在围绕std::set制作一个模板包装器。为什么Begin()函数声明会出错?templateclassCSafeSet{public:CSafeSet();~CSafeSet();std::set::iteratorBegin();private:std::set_Set;};错误:类型“std::set,std::allocator>”不是从类型“CSafeSet”派生的 最佳答案 尝试typename:templateclassCSafeSet{public:CSafeSet();~CSafeSet();typenames

c++ - std::map 中的元素是否保证有序?

这只是实现的副作用(红黑树)还是顺序由c++标准保证? 最佳答案 有序迭代不是实现细节;它由C++标准保证。它是所有关联容器的基本属性(C++03§23.1.2/9):Thefundamentalpropertyofiteratorsofassociativecontainersisthattheyiteratethroughthecontainersinthenon-descendingorderofkeyswherenon-descendingisdefinedbythecomparisonthatwasusedtoconstr

c++ - Std::deque 直到程序退出才释放内存

在linux上,std::deque直到程序退出才释放内存。完整代码如下。任何帮助将不胜感激!#include#include#include#include#include#include#include#include#includetypedefboost::shared_ptr>VecPtr;typedefstd::dequeQueueType;charbuf[1024];charline[1024];intmain(){{intv=0;QueueTypedeq;for(inti=0;i);deq.push_back(p);}std::cout0){deq.pop_front(

c++ - 将 `std::vector` 替换为 `std::array`

我有一个代码如下:intn;intget_the_number();voidsome_computations();intmain(){n=get_the_number();some_computations()return(0);}get_the_number函数获取一些输入并返回整数n,它在调用后不会被修改。在some_computation函数中有如下代码std::vectormy_array;for(inti=0;i问题:由于my_array的大小是先验已知的,是否可以用替换std::vector>std::array?此外,在肯定的情况下,我是否应该期望在效率方面有所提高?我