草庐IT

Piecewise_construct_wrapper

全部标签

c++ - std::is_constructible<void()>::value 的正确结果是什么?

std::is_constructible::value的结果不一致.我对该标准的解释是它应该是错误的。然而,Clang,同时具有libc++和libstdc++*,给出了true。GCC和MSVC都给出false。哪个结果是正确的?标准语这是标准的N4527[meta.unary.prop]/7:Giventhefollowingfunctiondeclaration:templateadd_rvalue_reference_tcreate()noexcept;thepredicateconditionforatemplatespecializationis_constructibl

c++ - std::reference_wrapper 是否应该包含默认比较器 "<"运算符?

就目前而言,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引起辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visitthehelpcenter为指导。9年前关闭。STL使用“小于”作为默认比较器。对用reference_wrapper包裹的对象的STL比较器调用doesnotcompile,即使基础类定义了“看来,这是因为有noimplicitconversion当LHS.operatorusingafreeversion当比较器工作时。但是,如果reference_wrapper提供了“我在reference_wr

c++ - 如何根据 is_nothrow_move_constructible<T> 声明包装类型 X<T> noexcept 的移动构造函数?

假设我有一个包装类型templatestructX{/*..*/};而且我不能只是X(X&&)=default因为我必须在那里做一些重要的事情。但是,我希望它是noexcept但前提是T(T&&)是noexcept。这可以使用::std::is_nothrow_move_constructible进行测试。我不知道如何根据constexpr有条件地启用构造函数的一个版本或另一个版本。我想可能有一种使用SFINAE的方法,但我不知道如何将其应用于ctors。 最佳答案 noexcept说明符接受任何bool常量表达式,因此您可以直接检

c++ - 为 std::reference_wrapper 赋值

我们如何为std::reference_wrapper包装的项目赋值?inta[]={0,1,2,3,4};std::vector>v(a,a+5);v[0]=1234;//Error,cannotassignvalue!根据错误,删除了直接赋值:error:useofdeletedfunction'std::reference_wrapper::reference_wrapper(_Tp&&)[with_Tp=int]' 最佳答案 使用get()成员函数:v[0].get()=1111;//okHere是std::referenc

c++ - 使用 std::reference_wrapper 作为 std::map 中的键

我在类层次结构中有一堆对象,我想制作一个std::map使用对这些对象的引用作为映射中的键。它看起来像std::reference_wrapper正是为此所需要的,但我似乎无法让它发挥作用。到目前为止我尝试了什么:classObject{//baseclassofmyhierarchy//mostdetailsunimportantpublicvirtualbooloperator,int>table;autoit=table.find(object);table[object]=42;table[object]++但是,我总是从编译器中得到一些模糊的错误:/usr/include/c

c++ - 运行 SonarQube 分析扫描 - SonarSource build-wrapper

我是运行SonarQube扫描的新手,我在Jenkins的日志中收到此错误消息:16:17:3916:17:36.926ERROR-TheonlywaytogetanaccurateanalysisofyourC/C++/Objective-CprojectisbyusingtheSonarSourcebuild-wrapper.Ifforanyreason,theuseofthebuild-wrapperisnotpossibleonyourproject,youcanbypassitwiththehelpofthe"sonar.cfamily.build-wrapper-outpu

c++ - Clang 问题 : implicit type conversion at construction time

概要我正在努力使C++11代码与Clang兼容,并遇到了GCC>=4.6接受代码而Clang>=3.1不接受的情况。Clang认为候选构造函数不可行。详情这里是一个精简的例子来说明这个问题:#includetemplatestructT;templatestructT{typedefTsuper;constexprT(){}templateT(Args&&...){}};templatestructT:T{typedefTsuper;Headhead;T(Headarg):super(),head(std::move(arg)){}};structvoid_type{constexpr

c++ - libc++ is_copy_constructible 对我来说似乎是错误的

is_copy_constructible的libc++实现是这样的:templatestruct_LIBCPP_TYPE_VIS_ONLYis_copy_constructible:publicis_constructible::type>{};is_copy_constructible的C++规范很简单:std::is_copy_constructiblespecification:std::is_constructible::valueistrue.但是,上面的实现不就是实现了T&const而不是constT&吗?将const应用于add_lvalue_reference应该没有

c++ - std::reference_wrapper<T> 在容器中的使用

如果可以的话,我会从我的代码中删除所有原始指针*,因为使用它们可能不是线程安全的,而且设计意图不明确(可选值、所有权等)。然而,有时候不使用指针并不是那么容易。例如,我们倾向于在多态类型的容器中使用指向基类型的指针:classA:noncopyable{...};classB:publicA{...};std::vectorv;v.emplace_back(newB);//temporarycontainerforsomeoperationstd::vectorselected;if(check())selected.emplace_back(v.front());你对上面的代码有什么

c++ - std::piecewise_linear_distribution 在 VS2012 下不工作?

我决定去了解c++11更好,所以我写了这样一段代码:std::mt19937gen(10);std::piecewise_linear_distributiond(Range.begin(),Range.end(),RangeValues.begin());std::maphist;for(intn=0;++n!=iterations;)++hist[std::round(d(gen))];for(autop:hist)std::cout出于某种原因std::random_device似乎在Coliru上不起作用,所以我输入了一个const样本种子。我猜想,它是UB,因此IIRC它在很