- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我正在尝试消费 Windows::Gaming::Input::RawGameController通过C++/WinRT图书馆。
调用 RawGameController::GetCurrentReading()
获取当前 Controller 状态:
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>
但它太丑了。
最佳答案
这是设计使然。 winrt::array_view
是一个适配器,它告诉底层 API 绑定(bind)数组或存储具有适当的二进制布局以有效地接收数据(通常通过 memcpy
)而无需某种转换。 std::vector<bool>
不提供该保证,因此不能使用。你可能想尝试其他的东西,比如 std::array
或其他一些连续的容器。
关于c++ - 无法将 std::vector<bool> 传递给 winrt::array_view,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57059598/
我刚刚看过 Herb Sutter 的“默认情况下编写良好的 C++14...”(https://www.youtube.com/watch?v=hEx5DNLWGgA)的第一部分,我有一个(可能是愚
我在 Windows 8 上将 C++ AMP 与 Visual Studio 2012 结合使用。我有一个案例,其中我有 2D array_view、experimentData 和 1D arra
假设我有一些类层次结构,其中有几个 virtual返回容器引用的函数: #include #include #include #include #include class Interfac
我已经开始尝试使用 C++ AMP。我创建了一个简单的测试应用程序只是为了看看它可以做什么,但是结果让我很惊讶。考虑以下代码: #include #include "Timer.h" using n
如果我有一个 concurrency::array_view 在 concurrency::parallel_for_each 循环中运行,我的理解是我可以在 CPU 上继续其他任务,同时循环正在执行
我想要一个与维度无关的模板(对 3d 和 4d 都有用),大部分操作将在第一维被剥离的子矩阵上执行。 这就是我想要的 template class MMapMatrixTemplate{ publi
我正在尝试使用一个数组,例如 int myarray[2][3]初始化 array_view目的。我试过了 array_view a(2,3, myarray);但是,这不起作用。我也希望能够用 ve
void Addx(float *z, float *x, float *y, size_t m, size_t n) { vector vx(m*n); vector vy(m*n); vector
在最近的几次 session 演讲中,我听到 Bjarne Stroustrup 和其他人提到了 C++ 的新编码指南以及一些支持它们的类型。 具体来说,我记得 the example of span
我的问题与 Boost.MultiArray 类有关。我了解如何将 multi_array 对象转换为 array_view 对象,如下代码所示: int my_row = 5;
我正在尝试消费 Windows::Gaming::Input::RawGameController通过C++/WinRT图书馆。 调用 RawGameController::GetCurrentRea
我写了一个小的测试函数,它的行为与我想要的不一样。 基本上,它应该读取一个数组并写回它的内容(稍后,当它起作用时,它应该做更多,但现在即使这样也会失败)。 调试 GPU 代码时,我看到前几次迭代(以某
假设我有一个成员变量std::vector在一个类中,我想使用 gsl::array_view 的组合从成员函数返回它作为不可变 View 和 gsl::cstring_view .不幸的是,以下内容
我是一名优秀的程序员,十分优秀!