草庐IT

decltype

全部标签

c++ - CRTP 失败 w/decltype

templatestructA{autofunc()->decltype(T::func()){returnT::func();}};classB:publicA{voidfunc(){}};对我来说似乎很简单。但是MSVC无法编译。visualstudio2010\projects\temp\temp\main.cpp(4):errorC2039:'func':isnotamemberof'B'visualstudio2010\projects\temp\temp\main.cpp(8):seedeclarationof'B'visualstudio2010\projects\tem

c++ - constexpr decltype

我最近在这里(DetectinginstancemethodconstexprwithSFINAE)问了一个问题,我试图在编译时做一些constexpr检测。最终,我发现可以利用noexcept来做到这一点:任何常量表达式也是noexcept。所以我组装了以下机器:templateconstexprintmaybe_noexcept(T&&t){return0;}...constexprboolb=noexcept(maybe_noexcept(int{}));这行得通并且b正如您所期望的那样为真,因为对int进行零初始化是一个常量表达式。它也应该正确地产生零(如果我将int更改为其他

c++ - 如何在 C++11 中使用 decltype 引用当前类?

当我声明一个类静态方法时,是否可以使用decltype(或任何其他类似的样式)来引用当前类?例如,classAAA{staticAAAconstmake();};我正在尝试制作这样的东西。classAAA{staticdecltype(*this)constmake();//Notworkingbecausethere'sno`this`.};*this用来描述我想做什么。我想知道一些可以解析为AAA的decltype()表达式。如果可能,我该怎么做? 最佳答案 在C++1y中你可以这样做:classAAA{public:stati

c++ - 英特尔 C++ 编译器编译递归 decltype 返回的速度非常慢

我正在为由任意数量的char参数化的表达式编写模板标签。给定参数列表,工厂函数返回不同类型的表达式,具体取决于是否有两个相同类型的参数或它们是否唯一。一个具体的例子:假设A是一个“可标记”对象,其operator()重载产生?Expression.让a,b,...被声明为标签LabelName,LabelName,....然后A(a,b,c,d)会产生UniqueExpression,而A(a,c,b,c)会产生RepeatedExpression相反。为此,我必须定义?Expressionauto的工厂函数和decltype.此外,decltype必须级联到另一个decltype直到

c++ - 应用于三元时 decltype 的返回类型(?:) expression

当我查看可能实现std::common_type的代码片段时templatestructcommon_type;templatestructcommon_type{typedefdecay_ttype;};templatestructcommon_type{typedefdecay_t():declval())>type;};templatestructcommon_type{typedefcommon_type_t,V...>type;};如何为两个模板参数获取通用类型的部分让我感到困惑。这是三元运算符与decltype的用法。据我所知,是否返回第二个或第三个操作数是由第一个操作数的

c++ - 不完整类型的调用运算符的 decltype 的特殊行为

我一直在努力解决编译问题,并且能够将问题缩小到一个小代码段。为了做好准备,我正在尝试执行CRTP,其中基方法调用派生类中的另一个方法。复杂的是,我想使用尾随返回类型来直接获取转发到派生类方法的类型。这总是无法编译除非我转发给派生类中的调用运算符。编译:#includestructIncomplete;templatestructBase{templateautoentry(Args&&...args)->decltype(std::declval()(std::declval()...));};voidexample(){Basederived;}虽然这不是:(注意唯一区别的注释)#i

c++ - 比较 std::tuple_element 和 decltype(std::get) 时,std::is_same 返回 false

我找不到类似的问题...我认为有两种“简单”的方法可以在编译时获取元组的第I^th个元素的类型(如果我错了请纠正我):usingTI1=typenamestd::tuple_element::type;usingTI2=decltype(std::get(Tuple{}));事实上,如果我们通过typeid(...).name()打印每一个的类型,它们返回相同的值。但是...std::is_same当我比较这些时返回false:liveexample这是预期的吗?为什么?usingTuple=std::tuple;constexprsize_tI=0;static_assert(std

c++ - 模板值参数上的 decltype 是否应该触发 SFINAE 上下文?

在试验一些模板约束结构时,我在Clang3.7中遇到了一个令人惊讶的行为:structconstraint_success{};structconstraint_failure{};templatestructrequire_t{};templatestructrequire_t{staticconstexprconstraint_success*result=nullptr;};templatestructrequire_t{staticconstexprconstraint_failure*result=nullptr;};templateconstexprautorequire=

c++ - decltype 说明符的用途

这个问题在这里已经有了答案:EnlighteningUsageofC++11decltype(3个答案)关闭8年前。我正在阅读有关限定名称查找的条款。那里引用了一句话:Ifa::scoperesolutionoperatorinanested-name-specifierisnotprecededbyadecltype-specifier,lookupofthenameprecedingthat::considersonlynamespaces,types,andtemplateswhosespecializationsaretypes.在标准decltype-specifier中的定

c++ - 类方法类型的 decltype

我想将类成员函数的返回值存储在另一个类中。这似乎可行:classFoo{public:Foo(int){}//nondefaultconstructorthathidesdefaultconstructorunspecified_return_typeget_value();};classBar{//storesavaluereturnedbyFoo::get_valuedecltype(Foo().get_value())value;};然而,有一个对类Foo的默认构造函数的引用,在某些情况下可能未定义。有没有办法在不显式引用任何构造函数的情况下做到这一点?