草庐IT

auto-versioning

全部标签

c++ - 使用 C++11 auto 作为 const 函数对象的返回类型

我有一个const函数对象,暂时它返回void。但可以返回int或double。我正在用c++11风格编写代码,只是想使用auto作为返回类型。尽管代码可以编译,但我不确定它是否100%正确。这是代码。templatestructmy_func{public:my_func(){}my_func(graph_t&_G):G(_G){}templateautooperator()(edge_tedge)->voidconst{//dosomethingwiththeedge.}//operatorprivate:graph_t&G;};//callthefunctor:(passgrap

c++ - 为什么 unique_ptr 对 auto_ptr 有重载?

我遇到编译器错误并注意到一些有趣的事情。出于某种原因,unique_ptr对auto_ptr有重载,但我认为auto_ptr已被弃用:/usr/local/include/c++/4.9.0/bits/unique_ptr.h:228:2:note:templatestd::unique_ptr::unique_ptr(std::auto_ptr&&)unique_ptr(auto_ptr&&__u)noexcept;/usr/local/include/c++/4.9.0/bits/unique_ptr.h:228:2:note:templateargumentdeduction/s

c++ - inline static auto 的 Initializer "sizeof(T)"...是否需要实例化?

如果表达式的类型不相关,但我们用它来初始化静态自动变量,会发生什么?GCC和Clang的行为不同templatestructA{staticinlineautox=sizeof(T{}.f);};Aa;GCC不会引发错误。但是Clang认为这是无效的,因为它实例化了“sizeof”的操作数。GCC似乎跳过了该步骤,因为sizeof(T{}.f)始终具有类型size_t(不依赖于类型),因此它已经知道x没有实例化。如果我们引用x,例如(void)a.x;,两个编译器都会拒绝该程序。它甚至必须解析x的类型吗?如果我没记错的话,C++14以上的语言允许使用“占位符类型”保留事物(如函数)并进

c++ - 为什么 -mmacosx-version-min=10.10 不阻止使用标记为从 10.11 开始的函数?

根据我对可用性宏和-mmacosx-version-min标志如何工作的理解,以下代码在针对OSX10.10时应该无法编译:#include#include#include#if!defined(__MAC_OS_X_VERSION_MIN_REQUIRED)#error#endif#if__MAC_OS_X_VERSION_MIN_REQUIRED101000#error__MAC_OSX_VERSION_MIN_REQUIREDtoohigh#endifintmain(){size_tlen=0;SSLContextRefx{};autostatus=SSLCopyRequeste

c++ - `template <auto>` 和部分类模板特化排序

考虑:#includetemplatestructTag{};templateautotag=Tag{};templatestructSelectorImpl;//1templatestructSelectorImpl...>{};//2template*tag,auto...xs>structSelectorImpl,std::integral_constant...>{};templatestructSelector:SelectorImpl...>{};intmain(){Selector,1,2>{};}gcc和clang都无法编译它,报告SelectorImpl的特化不明确。

c++ - decltype(auto) 函数返回类型不推导 && 类型

如果一个函数返回decltype(auto),它返回一个int&&类型的局部变量,为什么返回类型是int&?如果我将变量转换为它自己的类型,那么返回类型就是我所期望的(int&&)#includenamespace{autoi=5;autoj=5;decltype(auto)foo1(){int&&ret=std::move(i);returnret;}decltype(auto)foo2(){int&&ret=std::move(j);returnstatic_cast(ret);}}intmain(){static_assert(std::is_same_v);static_ass

c++ - C++ eclipse 调试器出现以下错误。 'Launching program name' 遇到...启动命令 : gdb --version 时出错

我一直在解决调试器问题,但现在它变得太烦人了。我正在处理更复杂的程序,如果我不能调试我的程序,我就无处可去。有没有其他人能够在eclipse中解决这个问题?它适用于java,但不适用于我来自minGW的C++插件C++eclipse调试器出现以下错误。“启动程序名称”遇到问题。启动命令时出错:gdb--version 最佳答案 假设您使用的是Windows并安装了MinGW,您只需在MinGWbin文件夹中找到gdb可执行文件。这可以在Eclipse的“调试器”配置中的“主”选项卡上完成:

c++ - 大 vector 的返回值优化与 auto_ptr

如果我使用auto_ptr作为填充大vector的函数的返回值,这会使该函数成为源函数(它将创建一个内部auto_ptr并在返回非constauto_ptr时移交所有权)。但是,我不能将此函数与STL算法一起使用,因为为了访问数据,我需要取消对auto_ptr的引用。我猜一个很好的例子是大小为N的vector场,每个vector有100个分量。如果N很大,则函数按值或按ref返回每个100个分量vector是不一样的。此外,当我尝试这个非常基本的代码时:classt{public:t(){std::coutautoFun(){returnstd::auto_ptr(newt());}a

C++11: `auto` 对 const 和引用类型的操作的标准引用

假设我有一个类型T:typedef...T;然后我有这些功能:Tf11();T&f12();T&&f13();constTf21();constT&f22();constT&&f23();然后像这样称呼他们:autox11=f11();autox12=f12();autox13=f13();autox21=f21();autox22=f22();autox23=f23();从C++11标准的哪些部分/条款可以推导出x11..x23的等效非自动声明? 最佳答案 它在§7.1.6.4autospecifier中。在您的函数返回类型示例中

c++ - 有没有办法为 C++03 实现 auto 关键字

在C++03或更早版本中,是否有实现auto关键字的方法?不是对象类,而是可以像这样使用它[C++11]autox=5;std::cout我很快“搞定”了一个实现,但它很垃圾,因为你可以将它转换为任何类型-太像一个object类,而且非常基础,我知道,但无论如何,这里是:classauto_t{public:templateauto_t(const_Ty&_Value):__data(_Value){}templateoperator_Ty(){return(_Ty)__data;}private:void*__data;};#defineautoauto_t