请考虑以下代码:
template<typename T> void foo(T&& some_struct)
{
bar(std::forward</* what to put here? */>(some_struct.member));
}
Run Code Online (Sandbox Code Playgroud)
在转发整个结构的情况下,我会这样做std::forward<T>(some_struct).但是如何在转发会员时获得正确的类型?
我有一个想法是使用decltype(some_struct.member),但似乎总是产生该成员的基本类型(如结构定义中所定义).
在我的项目中,我将使用过的点类型更改Eigen::Vector2f为Eigen::Vector2d并遇到了对齐问题.
这是代码的简化版本:
#include <vector>
#include <Eigen/Eigen>
int main()
{
std::vector<Eigen::Vector2d> points = { {0,0}, {0,1} };
}
Run Code Online (Sandbox Code Playgroud)
我收到以下运行时错误:
eigen3/Eigen/src/Core/DenseStorage.h:78: Eigen::internal::plain_array<double, 2, 0, 16>::plain_array() [T = double, Size = 2, MatrixOrArrayOptions = 0, Alignment = 16]: Assertion `(reinterpret_cast<size_t>(array) & 0xf) == 0 && "this assertion is explained here: " "http://eigen.tuxfamily.org/dox-devel/group__TopicUnalignedArrayAssert.html" " **** READ THIS WEB PAGE !!! ****"' failed.
Run Code Online (Sandbox Code Playgroud)
正如断言消息所示,我读到了固定大小的可矢量化特征对象所需的对齐.还有关于STL容器的小节.似乎我有两个选择:
Eigen::aligned_allocatorEIGEN_DEFINE_STL_VECTOR_SPECIALIZATION宏.两次尝试都不编译(使用GCC 4.8.3和Clang 3.5进行测试),因为编译器无法正确转换初始化列表.
这里改变了代码:
#include <vector> …Run Code Online (Sandbox Code Playgroud) When I look at the documentation of glMultiDrawElementsIndirect (or in the Wiki) it says that a single call to glMultiDrawElementsIndirect is equivalent to repeatedly calling glDrawElementsIndirect (just with different parameters).
Does that mean that gl_InstanceID will reset for each of these "internal" calls? And if so, how am I able to tell all these calls apart in my vertex shader?
背景:我试图一次绘制所有不同的网格。但是我需要一些方法来知道我在顶点着色器中处理的顶点属于哪个网格。
我写了一个小using语句,可以轻松访问可变参数模板参数包的类型.
template<size_t index, typename args...>
using get = std::tuple_element<index, std::tuple<args...>>::type;
Run Code Online (Sandbox Code Playgroud)
但是用clang(3.5.0)或gcc(4.9.0)编译它会失败.这是clang的错误输出:
error: expected ',' or '>' in template-parameter-list template<size_t index, typename args...>
^
Run Code Online (Sandbox Code Playgroud)
该using语句是否与可变参数模板不可组合?或者我做错了什么?