草庐IT

is_unique

全部标签

c++ - std::unique_ptr::release() 与 std::move()

我有一个表示运行时上下文并构建树的类,树根保存在unique_ptr中。构建树完成后,我想提取树。这是它的样子(不可运行,这不是调试问题):classContext{private:std::unique_ptrroot{newNode{}};public://imagineaconstructor,attributesandmethodstobuildatreestd::unique_ptrextractTree(){returnstd::move(this->root);}};所以我使用std::move()从Context实例中提取根节点。但是,除了使用std::move()之外

c++ - "-ftrapv"和 "-fwrapv": Which is better for efficiency?

来自GNU的网站:-ftrapvThisoptiongeneratestrapsforsignedoverflowonaddition,subtraction,multiplicationoperations.-fwrapvThisoptioninstructsthecompilertoassumethatsignedarithmeticoverflowofaddition,subtractionandmultiplicationwrapsaroundusingtwos-complementrepresentation.Thisflagenablessomeoptimizationsa

c++ - 为什么 std::is_array 对 std::array 返回 false?

自std::array和std::is_array都是在C++11中引入的,编译失败似乎很奇怪:#include#includestatic_assert(std::is_array>::value);有没有一种简单的方法来检查某物是否是一个数组,包括T[N]的两种可能性?和std::array? 最佳答案 std::is_array仅对看起来像T[]的类型定义为真或T[N].std::array不包括在内。您不能修改或专门化std::is_array成为true_type对于std::array在标准之下;这会使您的程序格式错误,

C++ 错误 : Type Name is Not Allowed

我正在尝试学习指针参数中的新类(class),我想让函数senior和everyoneElse接受指针x,但是当我尝试使用指针pAge调用函数时,它显示错误:类型名称是不允许的。怎么了?#includeintsenior(int*x);inteveryoneElse(int*x);usingnamespacestd;intmain(){intage(0);int*pAge(&age);cout>age;if(age>59)senior(int*pAge);elseeveryoneElse(int*pAge);return0;}intsenior(int*x){return*x;}int

c++ - std::is_signed<T> 和 std::numeric_limits<T>::is_signed 之间的区别?

两者都是std::is_signed和std::numeric_limits::is_signed应该给出关于T的签名的答案.为什么现在有两个符号指示符(即自C++11起)? 最佳答案 我敢猜测唯一的区别是如果std::numeric_limits专门用于用户定义的类型。这样的用户定义类型当然可以为is_signed提供自己的值。.但要求std::is_signed::value在这种类型上将始终返回false除非std::is_signed已独立特化。似乎std::is_signed的条件代表是is_arithmetic::val

c++ - 由空指针常量 : which behaviour is correct? 初始化

intmain(){constintx=0;int*y=x;//line3int*z=x+x;//line4}引用标准(C++11§4.10/1)Anullpointerconstantisanintegralconstantexpression(5.19)prvalueofintegertypethatevaluatestozerooraprvalueoftypestd::nullptr_t.Anullpointerconstantcanbeconvertedtoapointertype;...有四种可能:第4行没问题,但第3行不行。这是因为x和x+x都是计算结果为0的常量表达式,但

C# Dll 导入失败 : "The application has failed to start because its side-by-side configuration is incorrect"

我有一个c#.net4应用程序,使用vs2010。我正在尝试导入一个c++dll(基于vs2005)。[DllImport("Card.dll")]我得到了失败:UnabletoloadDLL'Card.dll':Theapplicationhasfailedtostartbecauseitsside-by-sideconfigurationisincorrect.Pleaseseetheapplicationeventlogorusethecommand-linesxstrace.exetoolformoredetail.(ExceptionfromHRESULT:0x800736B

c++ - 是否可以在 Xcode 5.1 中使用 std::make_unique?

由于Xcode5.1包含clang3.4,因此应该可以使用std::make_unique。好像是在memory.h中定义的。但是,它需要有_LIBCPP_STD_VER>11但由于__cplusplus宏的值,它仍然设置为11(仍然是201103L).有办法改变吗? 最佳答案 如clangwebsite中所述,您需要启用-std=c++1y。Xcode在其“C++语言版本”选项中不包含此选项作为选项,因此您需要手动输入它。为此,您需要在项目定义打开时进入“编辑器”菜单,然后按“显示定义”。您现在应该能够手动将“C++语言方言”选项

c++ - "Use of undefined type"带有 unique_ptr 以转发声明的类和默认移动构造函数/赋值

在下面的代码中,是避免编译错误并在A.cpp中手动包含B.h实现移动构造函数/赋值的唯一方法吗?//A.h#includeclassB;//implementationsomewhereinB.h/B.cppclassA{public:A()=default;~A()=default;A(constA&)=delete;A&operator=(constA&)=delete;A(A&&)=default;A&operator=(A&&)=default;private:std::unique_ptrm_b;};VisualStudio2015给出“错误C2027:使用未定义类型”,因为

c++ - 使用折叠表达式检查可变参数模板参数是否唯一

给定一个可变模板参数包,我想使用inlineconstexprbool和foldexpressions来检查给它的所有类型是否都是唯一的.我尝试这样的事情:templateinlinestaticconstexprboolis_unique=(...&&(!is_one_of));其中is_one_of是一个类似的bool值,可以正常工作。但是无论我在is_one_of中输入什么,这一行都不会编译。这甚至可以使用折叠表达式来完成,还是我需要为此目的使用常规结构? 最佳答案 您的方法实际上不起作用,因为is_one_of需要使用类型T