代码如下:
#include <memory>
#include <thread>
class A
{
void foo(int&& arg) const {}
void boo() const
{
int value(0);
std::thread t(&A::foo, this, std::move(value));
t.join();
}
};
int main()
{
A a;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
MS Visual Studio 2012(工具集v110)给出下一个错误:
错误C2664:'_ Rx std :: _ Pmf_wrap <_Pmf_t,_Rx,_Farg0,_V0_t,_V1_t,_V2_t,_V3_t,_V4_t,_V5_t,> :: operator()(const _Wrapper&,_ V0_t)const':无法从'转换参数2' int'到'int &&'
那是什么?我们不能通过线程使用移动语义吗?
我最近一直在使用 Apple 的 Metal API 进行一些实验,现在我来到了主题问题 -如何在一个 Metal API 场景中使用不同的片段着色器?是否可以?
背景:整个几何基元由一个简单的顶点片段链渲染,其中颜色在内部定义/计算(假设我们有一个立方体,它的所有面都是用所描述的方法渲染的)。接下来,需要使用纹理额外渲染图元的一部分(仅向其中一个面添加一些图片)。
我们是否需要使用不同的片段着色器来实现这一点?我想可以在第一步使用一些默认纹理,这将提供一些解决方案。
你会推荐什么?
//============== 编辑部分更进一步==========//
正如 Warren 建议的那样,我尝试将MTLRenderPipelineState的两个不同对象与两对不同的渲染函数一起使用。使用以下代码我没有得到想要的结果。每个状态都按照单独完成时的预期进行渲染,但一起渲染只能得到第一个渲染的状态。
创作:
id <MTLFunction> fragmentProgram = [_defaultLibrary newFunctionWithName:@"color_fragment"];
// Load the vertex program into the library
id <MTLFunction> vertexProgram = [_defaultLibrary newFunctionWithName:@"lighting_vertex"];
// Create a vertex descriptor from the MTKMesh
MTLVertexDescriptor *vertexDescriptor = MTKMetalVertexDescriptorFromModelIO(_boxMesh.vertexDescriptor);
vertexDescriptor.layouts[0].stepRate = 1;
vertexDescriptor.layouts[0].stepFunction = MTLVertexStepFunctionPerVertex;
// Create a reusable pipeline state
MTLRenderPipelineDescriptor *pipelineStateDescriptor = [[MTLRenderPipelineDescriptor alloc] init];
pipelineStateDescriptor.label = @"MyPipeline"; …Run Code Online (Sandbox Code Playgroud) 我有这个代码:
void f2(int& lvalue)
{
std::cout <<"lvalue\n";
}
void f2(int&& rvalue)
{
std::cout << "rvalue\n";
}
template<typename T>
void f(T&& param)
{
f2(param);
}
Run Code Online (Sandbox Code Playgroud)
如果我打电话给f,我希望得到"左值" :
int v = 10;
f(v);
Run Code Online (Sandbox Code Playgroud)
并且如果我用以下方式调用f,则期望"rvalue" :
f(10);
Run Code Online (Sandbox Code Playgroud)
但是,我总是得到左值的情况.拜托,任何人都可以解释我错在哪里.
以下示例似乎非常简单明了:
void ftest(size_t& arg)
{
std::cout << arg << '\n';
}
int main()
{
size_t max = 5;
for (auto i = 0; i < max; ++i)
ftest(i);
}
Run Code Online (Sandbox Code Playgroud)
但它不会编译(至少使用VS2013)因为i被推断为int而不是size_t.问题是 - 如果不能依赖条件字段,那么for循环中auto的意义何在?如果编译分析整个语句并给出预期结果而不是我们现在拥有的结果,那会是太难和耗时吗?
我正在玩Apple Metal API以及所谓的simd库.标题中有这样的代码:
typedef __attribute__((__ext_vector_type__(3))) float vector_float3;
Run Code Online (Sandbox Code Playgroud)
我很好奇它实际上做了什么以及为什么编译器不允许在函数的参数中或以下一种方式引用vector_float3:
vector_float3 v;
vector_float3& ref = v;
Run Code Online (Sandbox Code Playgroud) 以下代码通过左键单击在画布上添加点,通过右键单击用绘制的点绘制多段线,并在光标移动时在线上绘制滑动点。唯一的问题是,由于标题原因,执行在“滑动”后很快就停止了。我怎样才能克服这个问题并随心所欲地滑动?
import matplotlib.pyplot as plt
class DumbyRemove:
def __init__(self):
pass
def remove(self):
pass
the_points = list()
drawn_points = list()
moving_point = DumbyRemove()
def draw_polyline():
global the_points, drawn_points
if len(the_points) < 2:
return
start_point = the_points[0]
for end_point in the_points[1:]:
xs = (start_point[0], end_point[0])
ys = (start_point[1], end_point[1])
start_point = end_point
line = plt.Line2D(xs, ys, marker='.', color=(0.7, 0.3, 0.3))
plt.gcf().gca().add_artist(line)
drawn_points = drawn_points + the_points
the_points = list()
plt.show()
def button_press_callback(event):
global the_points
if event.button == 1:
the_points.append((event.xdata, event.ydata))
p = …Run Code Online (Sandbox Code Playgroud) 我有这个代码:
def find_smallest_circle_sqtime(list):
inv_number_of_elements = 1.0 / len(list);
smallest_circle = MyCircle(inv_number_of_elements * sum(p.get_x() for p in list),
inv_number_of_elements * sum(p.get_y() for p in list), .1);
smallest_circle.radius = max(smallest_circle.centre.sub(p).norm() for p in list);
return smallest_circle
Run Code Online (Sandbox Code Playgroud)
我在哪里得到list相对于最远点的半径smallest_circle.centre.但实际上我需要弄清楚这一点.我怎样才能以最pythonic的方式做到这一点?