草庐IT

non-unique

全部标签

c++ - 为什么叫 "non-type"模板参数?

在C++模板术语中,我们有非类型模板参数、类型模板参数和模板模板参数(然后是带参数的相同列表)。为什么叫非类型?它不是一个值吗?不应该是“值模板参数”吗?如果我将它们视为值模板参数,我会错过什么吗?注意:出于好奇,我查看了D语言的文档,他们称之为value。 最佳答案 “值”在C++中有一个非常具体的非直观定义,不一定适用于非类型模板参数:3.9Types[basic.types]4TheobjectrepresentationofanobjectoftypeTisthesequenceofNunsignedcharobjectst

c++ - std::make_unique 导致大幅减速?

我最近开始使用C++14而不是C++11对我的C++代码库进行现代化改造。在用C++14中的std::make_unique替换一次出现的std::unique_ptr.reset(new...)后,我意识到我的测试套件(由大约30个C++测试程序组成)运行速度慢了大约50%。旧的C++11代码(快速):classFoo{public:Foo(size_tsize){array.reset(newchar[size]);}private:std::unique_ptrarray;};新的C++14代码(慢):classFoo{public:Foo(size_tsize){array=s

c++ - std::unique_ptr<T[]> API 禁止派生到基指针的转换

在ModernEffectiveC++中,“Iterm19:使用std::shared_ptr进行共享所有权资源管理。”,第133-134页,它说:std::shared_ptrsupportsderived-to-basepointerconversionsthatmakesenseforsingleobjects,butthatopenholesinthetypesystemwhenappliedtoarrays.(Forthisreason,thestd::unique_ptrAPIprohibitssuchconversions.)“类型系统中的漏洞”是什么意思?为什么std:

c++ - 为什么不能推导出unique_ptr的模板参数?

当你有C++17中可用的类模板参数推导时,为什么你不能推导std::unique_ptr的模板参数?例如,这给了我一个错误:std::unique_ptrsmp(newD);上面写着“类模板的参数列表丢失”。模板参数(至少是指针类型)不应该是可推导的吗?Seethis:anydeclarationthatspecifiesinitializationofavariableandvariabletemplate 最佳答案 让我们看看newint和newint[10].两者都返回int*.无法判断您是否应该拥有unique_ptr或un

c++ - std::unique_ptr constexpr 构造函数

如图here,std::unique_ptr有两个用于空指针的constexpr构造函数:constexprunique_ptr();constexprunique_ptr(nullptr_t);我对这两个构造函数有两个问题:为什么我们需要两个?我们不能只声明一个:constexprunique_ptr(nullptr_t=nullptr);constexpr真的有用吗?我尝试在我的代码中这样做,但它没有编译(g++6.1.0,-std=c++14):constexprstd::unique_ptrp;//error:thetype'conststd::unique_ptr'ofcon

c++ - 使用带有 unique_ptr 的 union

当我尝试std::move或std::make_unique时,尝试在union中使用unique_ptr会给我一个段错误。#include#includeunionmyUnion{struct{std::unique_ptrupFloat;}structUpFloat;struct{std::unique_ptrupInt;}structUpInt;myUnion(){}~myUnion(){}};structmyStruct{intx;myUnionnum;};intmain(){myStructaStruct,bStruct;aStruct.x=1;bStruct.x=2;aut

c++ - Doxygen 警告 : no uniquely matching class member found for

我将Doxygen用于C++项目。在构建html文档时,出现以下错误:C:/Amir/Programming/EclipseC++/CacheOptimization/src/CacheLruNaiveAlgorithm.cpp:19:warning:nouniquelymatchingclassmemberfoundforvoidCacheOpt::CacheLruNaiveAlgorithm::init(TierList&tierList,TierMap*tierMap)此警告的来源可能是什么?一般是什么原因造成的?编辑:我的DoxyfileDOXYFILE_ENCODING=UT

c++ - 带有 std::make_unique 的 push_back 或 emplace_back

基于these中的答案questionshere,我知道使用c++14的std::make_unique肯定比直接emplace_back(newX)更可取。也就是说,是不是更喜欢打电话my_vector.push_back(std::make_unique("constructor","args"));或my_vector.emplace_back(std::make_unique("constructor","args"));也就是说,在添加由std::make_uniquestd::unique_ptr时,我应该使用push_back还是emplace_back/?====编辑=

c++ - 将 unique_ptrs 从一个 vector move 到另一个 vector

我想将存储在它们的未排序vector中的unique_ptrmove到另一个vector,该vector将包含指针的排序vector。确定moveunique_ptr不会自动删除第一个vector中的元素吗?我该怎么做?我想做的例子:std::vector>unsorted,sorted;//fillthe"unsorted"vectorwhile(unsorted.size()>0){constautoit=find_next_element_to_add_to_sorted(unsorted);sorted.push_back(std::move(*it));}我希望意图很明确。更

c++ - 为什么构造不完整类型的 std::unique_ptr 编译?

代码:#includestructData;std::unique_ptrmake_me();intmain(){std::unique_ptrm=make_me();return0;}当然失败了:Infileincludedfrom:1:Infileincludedfrom/opt/compiler-explorer/gcc-7.1.0/lib/gcc/x86_64-linux-gnu/7.1.0/../../../../include/c++/7.1.0/memory:80:/opt/compiler-explorer/gcc-7.1.0/include/c++/7.1.0/bit