草庐IT

cross-apply

全部标签

c++ - 如何检查类型是否为 mpl::apply-able?

如果我有类型,T,看起来像Foo,我能做到mpl::apply::type得到Foo.但是如果T是一个完整的类型,比如Foo,然后mpl::apply::type不会编译。我想编写一个元函数,如果可能的话将应用一个类型,否则返回该类型。所以像这样:templatestructmaybe_apply:eval_if_c,mpl::identity>{};我可以在???s中放什么,这样它就能达到我想要的效果? 最佳答案 免责声明:我远不是MPL方面的专家,所以我不能保证这是解决这个问题的最佳方法(或者即使它是正确的,它至少看起来是有效的

c++ - 修改后的 std::invoke/std::apply,将可调用对象作为 void* - 可能吗?

在C++17中我们有std::invoke:templatestd::result_of_tinvoke(F&&f,ArgTypes&&...args);(并且在C++11中已经有std::experimental::apply,它是相似的,但有一个元组)。现在,我要实现:templateTinvoke(void*f,ArgTypes&&...args);与std::invoke的不同之处在于f是通过void指针传递的,并且其类型没有模板参数。然而,类型可以被人类读者推断出来,前提是f是一个指向普通独立函数的指针,我可以这样做:templateTmy_invoke(void*f,Arg

c++ - Boost 变体 apply_visitor 编译错误

boost::variant和boost::apply_visitor的简单示例代码:#includestructExprFalse;structExprTrue;structExprMaybe;typedefboost::variantExpression;structExprFalse{};structExprTrue{};structExprMaybe{};structPrinter:publicboost::static_visitor{public:Printer(std::ostream&os):m_os(os){}voidoperator()(ExprFalseconst

c++ - "Why switch statement cannot be applied on strings?"的答案是否仍然正确,即使使用 C++11/14?

我遇到了这个问题:Whyswitchstatementcannotbeappliedonstrings?并想知道答案是否:Thereasonwhyhastodowiththetypesystem.C/C++doesn'treallysupportstringsasatype.Itdoessupporttheideaofaconstantchararraybutitdoesn'treallyfullyunderstandthenotionofastring.仍然适用,即使在C++11/14中使用std:string。是否有多个elseif(...)的替代方案?

c++ - 警告 C4180 : qualifier applied to function type has no meaning; ignored

我已经设置了编译器/Za选项来禁用语言扩展,以便编译器严格使用标准ISOC++。这是我收到以下警告的示例接口(interface)类warningC4180:qualifierappliedtofunctiontypehasnomeaning;ignored这是关于函数返回类型中的const限定符,如果我删除const,警告就会消失,但我不想这样做,我想重新启用lanqage扩展。我的问题是:这个警告合理吗?如果不是,那么我将使用pragma禁用警告,但在此之前我想确保此警告是“误报”因为下面的类是正确的ANSIISOC++不是吗?所以警告应该被禁用?classIBet{public:

c++ - "crosses initialization of variable"仅当初始化结合声明时

我读过thisquestion关于“跳转到案例标签”错误,但我还有一些疑问。我在Ubuntu12.04上使用g++4.7。这段代码报错:intmain(){intfoo=1;switch(foo){case1:inti=0;i++;break;case2:i++;break;}}错误是jump-to-case-label.cpp:Infunction‘intmain()’:jump-to-case-label.cpp:8:8:error:jumptocaselabel[-fpermissive]jump-to-case-label.cpp:5:9:error:crossesinitia

c++ - 使用 std::apply 遍历元组元素

我想实现一种将函数应用于给定元组的每个元素的方法,我想出了一个解决方案,在以下示例中进行了演示。intmain(){std::apply([](auto&&...xs){[](...){}(([](auto&&x){std::cout(xs)),false)...);},std::make_tuple(1,2.f,3.0));}这似乎工作正常,除了元组元素似乎以倒序处理,导致以下输出:321谁能告诉我为什么? 最佳答案 内部空lambda参数的顺序[](...){}评估未指定(即使在paperonevaluationorder之后)

c++ - 为什么 std::apply 会因泛型函数而失败?

取自cppreference,为什么调用std::apply(add_generic,...)编译失败?有办法解决吗?#include#includeintadd(intfirst,intsecond){returnfirst+second;}templateTadd_generic(Tfirst,Tsecond){returnfirst+second;}intmain(){std::cout它fails有错误:[x86-64gcc7(snapshot)]error:nomatchingfunctionforcallto'apply(,std::tuple)'[x86-64gcc7(s

c++ - 错误 : jump to label 'foo' crosses initialization of 'bar'

以下C++示例无法使用gcc或clang进行编译,但仅使用ICC生成警告,而使用MSVC则完全不生成任何警告:intmain(intargc,char*argv[]){if(argcg++:init.cpp:13:error:jumptolabel‘clean_up’init.cpp:4:error:fromhereinit.cpp:7:error:crossesinitializationof‘inti’clang++:init.cpp:4:9:error:cannotjumpfromthisgotostatementtoitslabelgotoclean_up;^init.cpp:

c++ - 具有模板特化的 constexpr 数组成员 : inconsistent behavior cross compilers

考虑以下代码:#includetemplatestructfoo{};templatestructfoo{staticconstexprcharvalue[]="abcde";};templatestructbar{staticconstexprcharvalue[]="abcde";};templatestructbaz{staticconstexprintvalue=12345;};intmain(){charc=foo::value[2];chard=bar::value[2];inte=baz::value;std::cout编译时:clang++-std=c++14./tes