无法将 std::vector<bool> 传递给 winrt::array_view

DJm00n

我试图通过C++/WinRT使用Windows::Gaming::Input::RawGameController

调用RawGameController::GetCurrentReading()以获取当前控制器状态:

std::vector<bool> buttonsArray(rawController.ButtonCount(), false);
std::vector<GameControllerSwitchPosition> switchesArray(rawController.SwitchCount(), GameControllerSwitchPosition::Center);
std::vector<double> axisArray(rawController.AxisCount(), 0.0);
uint64_t timestamp = rawController.GetCurrentReading(buttonsArray, switchesArray, axisArray);

并有编译错误:

1>------ Build started: Project: cppwinrtgamepad, Configuration: Debug x64 ------
1>cppwinrtgamepad.cpp
1>c:\somepath\x64\debug\generated files\winrt\base.h(3458): error C2039: 'data': is not a member of 'std::vector<T,std::allocator<_Ty>>'
1>        with
1>        [
1>            T=bool,
1>            _Ty=bool
1>        ]
1>c:\somepath\x64\debug\generated files\winrt\base.h(3663): note: see declaration of 'std::vector<T,std::allocator<_Ty>>'
1>        with
1>        [
1>            T=bool,
1>            _Ty=bool
1>        ]
1>c:\somepath\cppwinrtgamepad.cpp(121): note: see reference to function template instantiation 'winrt::array_view<T>::array_view<T>(std::vector<T,std::allocator<_Ty>> &) noexcept' being compiled
1>        with
1>        [
1>            T=bool,
1>            _Ty=bool
1>        ]
1>c:\somepath\cppwinrtgamepad.cpp(121): note: see reference to function template instantiation 'winrt::array_view<T>::array_view<T>(std::vector<T,std::allocator<_Ty>> &) noexcept' being compiled
1>        with
1>        [
1>            T=bool,
1>            _Ty=bool
1>        ]
1>c:\somepath\cppwinrtgamepad.cpp(90): note: see reference to class template instantiation 'winrt::impl::fast_iterator<winrt::Windows::Foundation::Collections::IVectorView<winrt::Windows::Gaming::Input::Gamepad>>' being compiled
1>c:\somepath\x64\debug\generated files\winrt\base.h(7801): note: see reference to class template instantiation 'winrt::com_ptr<winrt::impl::IContextCallback>' being compiled
1>c:\somepath\x64\debug\generated files\winrt\base.h(7573): note: see reference to class template instantiation 'winrt::com_ptr<winrt::impl::IServerSecurity>' being compiled
1>c:\somepath\x64\debug\generated files\winrt\base.h(7532): note: see reference to class template instantiation 'std::chrono::time_point<winrt::clock,winrt::Windows::Foundation::TimeSpan>' being compiled
1>c:\somepath\x64\debug\generated files\winrt\base.h(5264): note: see reference to class template instantiation 'winrt::com_ptr<winrt::impl::IMarshal>' being compiled
1>c:\somepath\x64\debug\generated files\winrt\base.h(2503): note: see reference to class template instantiation 'winrt::com_ptr<To>' being compiled
1>        with
1>        [
1>            To=winrt::impl::ILanguageExceptionErrorInfo2
1>        ]
1>c:\somepath\x64\debug\generated files\winrt\base.h(4120): note: see reference to function template instantiation 'winrt::com_ptr<To> winrt::com_ptr<winrt::impl::IRestrictedErrorInfo>::try_as<winrt::impl::ILanguageExceptionErrorInfo2>(void) noexcept const' being compiled
1>        with
1>        [
1>            To=winrt::impl::ILanguageExceptionErrorInfo2
1>        ]
1>c:\somepath\x64\debug\generated files\winrt\base.h(4202): note: see reference to class template instantiation 'winrt::com_ptr<winrt::impl::IRestrictedErrorInfo>' being compiled
1>c:\program files (x86)\microsoft visual studio\2017\professional\vc\tools\msvc\14.16.27023\include\string_view(39): note: see reference to class template instantiation 'std::basic_string_view<wchar_t,std::char_traits<wchar_t>>' being compiled
1>c:\somepath\x64\debug\generated files\winrt\base.h(3458): error C2664: 'winrt::array_view<T>::array_view(winrt::array_view<T> &&)': cannot convert argument 1 from 'winrt::array_view<T>::size_type' to 'std::initializer_list<bool>'
1>        with
1>        [
1>            T=bool
1>        ]
1>c:\somepath\x64\debug\generated files\winrt\base.h(3459): note: No constructor could take the source type, or constructor overload resolution was ambiguous
1>Done building project "cppwinrtgamepad.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

GetCurrentReading()定义winrt/Windows.Gaming.Input.h如下:

template <typename D> uint64_t consume_Windows_Gaming_Input_IRawGameController<D>::GetCurrentReading(array_view<bool> buttonArray, array_view<Windows::Gaming::Input::GameControllerSwitchPosition> switchArray, array_view<double> axisArray) const

相应的winrt::array_view构造函数定义winrt/base.h如下:

template <typename C>
array_view(std::vector<C>& value) noexcept :
    array_view(value.data(), static_cast<size_type>(value.size()))
{}

考虑到std::vector<bool>根本不限制data()方法,这看起来像是一个遗忘的错误或者有其他推荐的调用方式RawGameController::GetCurrentReading()

PS:作为一种解决方法,我可以使用std::array<bool, SOME_BIG_BUTTTON_COUNT>但它太丑了。

DJm00n

丑陋的解决方法而不是使用vector<bool>

int32_t buttons = rawController.ButtonCount();
int32_t switches = rawController.SwitchCount();
int32_t axis = rawController.AxisCount();

std::unique_ptr<bool[]> buttonsArray = std::make_unique<bool[]>(buttons);
std::vector<GameControllerSwitchPosition> switchesArray(switches);
std::vector<double> axisArray(axis);

uint64_t timestamp = rawController.GetCurrentReading(winrt::array_view<bool>(buttonsArray.get(), buttonsArray.get() + buttons), switchesArray, axisArray);

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

将std :: vector传递给数组引用

来自分类Dev

如何将r值std :: vector传递给函数?

来自分类Dev

将本机C ++传递给WinRT

来自分类Dev

无法将参数传递给std :: thread?

来自分类Dev

为什么我特别应该将std :: span而不是std :: vector&传递给函数?

来自分类Dev

如何将Vector / Array传递给符号函数?

来自分类Dev

将二进制文件读入std :: vector <bool>

来自分类Dev

将2d std :: array传递给函数cpp

来自分类常见问题

将未知大小的std :: array传递给函数

来自分类Dev

将std :: vector作为参数传递给函数时为EXC_BAD_ACCESS

来自分类Dev

将std :: vector传递给C ++中的函数时的内存分配

来自分类Dev

使用std :: vector时如何将索引信息传递给元素构造函数?

来自分类Dev

将类的复制构造函数双重调用传递给std :: vector :: emplace_back

来自分类Dev

为什么不能使用模板模板参数将std :: vector <MyType>传递给此函数?

来自分类Dev

std :: vector <bool>优化实现

来自分类Dev

快速std :: vector <bool>重置

来自分类Dev

无法删除std :: vector和std :: array?

来自分类Dev

无法删除std :: vector和std :: array?

来自分类Dev

C ++-将char引用转换为bool Referenece(std :: vector <bool>)

来自分类Dev

无法将std :: cout传递给ostream&构造函数

来自分类Dev

将char向量的vector传递给char **

来自分类Dev

如何在满足constnt表达式的同时将整数传递给指针,传递给std :: array <double,integer>?

来自分类Dev

将std :: vector v传递给需要在相应实例的整个生命周期内访问v的类的ctor

来自分类Dev

如何为std :: vector <std :: vector <bool >>编写哈希函数

来自分类Dev

将-std = c ++ 11传递给CMakeLists?

来自分类Dev

将CSocket传递给std :: thread

来自分类Dev

将lamda传递给std :: find

来自分类Dev

将-std = c ++ 11传递给CMakeLists?

来自分类Dev

将模板args传递给std :: thread

Related 相关文章

  1. 1

    将std :: vector传递给数组引用

  2. 2

    如何将r值std :: vector传递给函数?

  3. 3

    将本机C ++传递给WinRT

  4. 4

    无法将参数传递给std :: thread?

  5. 5

    为什么我特别应该将std :: span而不是std :: vector&传递给函数?

  6. 6

    如何将Vector / Array传递给符号函数?

  7. 7

    将二进制文件读入std :: vector <bool>

  8. 8

    将2d std :: array传递给函数cpp

  9. 9

    将未知大小的std :: array传递给函数

  10. 10

    将std :: vector作为参数传递给函数时为EXC_BAD_ACCESS

  11. 11

    将std :: vector传递给C ++中的函数时的内存分配

  12. 12

    使用std :: vector时如何将索引信息传递给元素构造函数?

  13. 13

    将类的复制构造函数双重调用传递给std :: vector :: emplace_back

  14. 14

    为什么不能使用模板模板参数将std :: vector <MyType>传递给此函数?

  15. 15

    std :: vector <bool>优化实现

  16. 16

    快速std :: vector <bool>重置

  17. 17

    无法删除std :: vector和std :: array?

  18. 18

    无法删除std :: vector和std :: array?

  19. 19

    C ++-将char引用转换为bool Referenece(std :: vector <bool>)

  20. 20

    无法将std :: cout传递给ostream&构造函数

  21. 21

    将char向量的vector传递给char **

  22. 22

    如何在满足constnt表达式的同时将整数传递给指针,传递给std :: array <double,integer>?

  23. 23

    将std :: vector v传递给需要在相应实例的整个生命周期内访问v的类的ctor

  24. 24

    如何为std :: vector <std :: vector <bool >>编写哈希函数

  25. 25

    将-std = c ++ 11传递给CMakeLists?

  26. 26

    将CSocket传递给std :: thread

  27. 27

    将lamda传递给std :: find

  28. 28

    将-std = c ++ 11传递给CMakeLists?

  29. 29

    将模板args传递给std :: thread

热门标签

归档