草庐IT

fixed-size-types

全部标签

c++ - 为什么 GCC 中 std::list O(n) 的 size() 方法?

在GCC中,std::list的size()方法是O(n)。为什么?对于C++11,标准是size()oflistshouldbeO(1)但是在glibc中我们有以下内容:/usr/include/c++/4.6.3/bits/stl_list.htemplate>classlist:protected_List_base{...size_typesize()const{returnstd::distance(begin(),end());}问题是:为什么三年前的要求还没有在GCC中实现?编辑:gcc5改变了这一点:尽管以ABI改变为代价;这意味着使用gcc5.0编译的C++代码将无法

c++ - LNK1112 : module machine type 'x64' conflicts with target machine type 'X86' : Qt creator

我有一个在linux上运行的应用程序,我正试图将其导入到windows上。我已经设置了所有库并对.pro文件进行了更改。现在,当我尝试构建项目时出现此错误:error:LNK1112:modulemachinetype'x64'conflictswithtargetmachinetype'X86'我不确定是什么导致了这个问题。我正在使用32位Qtcreator。我知道有几个链接讨论了更改项目属性,但所有这些都与在VisualStudio中更改它们有关。我正在使用Qtcreator并通过QtUI运行项目。所以我不确定如果必须解决这个问题,必须通过Qt对项目属性进行哪些更改。

C++ 调试窗口显示“<incomplete type> for string variable

据我所知,我正在以一种相当正常的方式初始化一个字符串,当我调试时,我的IDE(CLion)中的变量窗口将其值显示为.我有一些简单的代码导致字符串变量Bob出现问题.#includeintmain(){std::stringBob="thisdoesn'tshowupinthevariableswindow";std::cout我不知道它有什么影响,但我会包含CMakeLists文件,它似乎是我可以使用的最简单的文件。cmake_minimum_required(VERSION3.8)project(testing123)set(CMAKE_CXX_FLAGS"${CMAKE_CXX_F

c++ - 迭代器模式 - 错误 C2679 : binary '<<' : no operator found which takes a right-hand operand of type 'std::string'

这个问题在这里已经有了答案:errorC2679:binary'(1个回答)关闭5年前。我正在尝试使用迭代器模式进行迭代和打印,但出现错误这里是错误:errorC2679:binary'couldbe'std::basic_ostream&std::operator>(std::basic_ostream&,constchar*)'这是错误的来源std::coutgetName();#ifndef_ROBOT1_#define_ROBOT1_namespaceguitars{namespaceComposite{namespaceInventoryParts{usingnamespac

具有非 size_t 整数的 std::array 的 C++ 模板参数推导

我正在尝试调整Avoidingstructinvariadictemplatefunction中提供的解决方案根据我的需要。但是,我无法理解G++的行为。考虑以下功能:templateintnextline(consttypenamestd::arrayar){return0;}然后调用nextline(std::array{1,0});与GCC提示不匹配eslong.cpp:Infunction‘intmain()’:eslong.cpp:10:38:error:nomatchingfunctionforcallto‘nextline(std::array)’nextline(std

c++ - 为什么随机访问迭代器的算术运算符接受/返回 int 而不是 size_t?

由于std::vector上的大多数操作都需要/返回size_t-这就是我用于索引的类型。但现在我已经启用所有编译器警告来修复一些我知道的有符号/无符号转换问题,这条消息让我感到惊讶:warningC4365:'argument':conversionfrom'size_t'to'__w64int',signed/unsignedmismatch它是由这段代码生成的:std::vectorv;size_tidx=0;v.insert(v.begin()+idx+1,0);我收到很多其他类似的消息,建议迭代器的算术运算符接受并返回int。为什么不是size_t?修复所有这些消息很痛苦,并

如何正确地从函数(type_traits)提供向量

我如何返回std::vector由此operator+()?#include#include#include#include#includetemplatestructis_std_vector:std::false_type{};templatestructis_std_vector>:std::true_type{};templatestd::enable_if_t>::value>operator+(T&&vec1,T&&vec2){for(inti=0;i(vec2.at(i)));returnvec1;}intmain(){std::vectorvec1{1,2,3,4,5};std

c++ - 如何在 C++11 中将容器 std::array<type, size> 用于多维数组?

例如,包含三个整数的一维数组可以定义为std::arraymyarray或myarray[3].有没有像std::array这样的容器对于像myarray[3][3]这样的多维数组? 最佳答案 一个关键部分是确保{}初始化工作类似于std::array,并尽可能合理地让自己保持pod状。与std::array的兼容性也很重要,什么比std::array更兼容??所以我的解决方案从std::array中生成多维数组小号:templatestructmulti_array_helper{usingtype=T;};templateusi

c++ - 从 back_insert_iterator 中提取容器的 value_type 的特征类

std::back_insert_iterator的value_type等于void,但它还有一个protected成员container包含指向底层Container的指针。我正在尝试编写一个traits类来提取容器的value_type,如下所示:#include#include#includetemplatestructoutit_vt:OutputIt{usingself_type=outit_vt;usingvalue_type=typenamestd::remove_pointer_t().container)>::value_type;};intmain(){std::v

c++ - 为什么 std::copy_n 采用模板参数而不是 std::size_t?

这么简单的问题。templateOutputItcopy_n(InputItfirst,Sizecount,OutputItresult);为什么std::copy_n为要复制的元素数量取一个类型,而不是简单地std::size_t?我只是想不出一个理由。templateOutputItcopy_n(InputItfirst,std::size_tcount,OutputItresult); 最佳答案 在这种情况下,推测原始原理大多是徒劳的,但对于这种设计copy_n可以用负计数调用,例如int或ptrdiff_ttype,在这种情