大佬教程收集整理的这篇文章主要介绍了c – 获取c数组中的开始的返回类型,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
using type = decltype(std::begin(std::declval<T>()));@H_673_3@并且当T = std :: vector< int> ;.但是我不明白为什么以下不行:
using type = decltype(std::begin(std::declval<int[3]>()));@H_673_3@我得到错误:
example.cpp:83:60: error: no matching function for call to ‘begin(int [3])’ using type = decltype(std::begin(std::declval<int[3]>()));@H_673_3@如何获得std ::的返回类型以通用方式开始?
template< class T,std::size_t N > constexpr T* begin( T (&array)[n] );@H_673_3@而std :: declval< int [3]>()给你一个int(&&)[3],这不匹配那个重载.它也不符合正常的容器重载,因为那些是具有c.begin()的SFINAE编辑.所以你没有匹配的功能.
您需要的是将数组的一个左值引用传递给begin(),以使迭代器退出.因此,当您使用别名时,您需要手动提供一个左值引用:
template <class T> using type = decltype(std::begin(std::declval<T>())); using arr = type<int(&)[3]>; // int*@H_673_3@或者让别名本身为您提供lvalue参考:
template <class T> using type = decltype(std::begin(std::declval<T&>())); using arr = type<int[3]>; // int*@H_673_3@前者对我来说似乎更为正确,但是ymMV.
以上是大佬教程为你收集整理的c – 获取c数组中的开始的返回类型全部内容,希望文章能够帮你解决c – 获取c数组中的开始的返回类型所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。