小编eis*_*baw的帖子

C++:const引用,在类型说明符之后

参数之间有什么区别:

int foo1(const Fred &arg) {
...
}
Run Code Online (Sandbox Code Playgroud)

int foo2(Fred const &arg) {
...
}
Run Code Online (Sandbox Code Playgroud)

?我没有看到parashift FAQ中涉及的这个案例.

c++ const reference

132
推荐指数
5
解决办法
7万
查看次数

std ::对象的向量和const-correctness

考虑以下:

class A {
public:
    const int c; // must not be modified!

    A(int _c)
    :   c(_c)
    {
        // Nothing here
    }

    A(const A& copy)
    : c(copy.c)
    {
        // Nothing here
    }    
};



int main(int argc, char *argv[])
{
    A foo(1337);

    vector<A> vec;
    vec.push_back(foo); // <-- compile error!

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

显然,复制构造函数是不够的.我错过了什么?

编辑:Ofc.我无法在operator =()方法中更改this-> c,因此我没有看到如何使用operator =()(尽管std :: vector需要).

c++ vector const-correctness

15
推荐指数
3
解决办法
4454
查看次数

std :: for_each over std :: set,C++ 11

迭代向量工作:

std::vector<int> collection = {2, 3, 4, 5435345, 2};
std::for_each(collection.begin(), collection.end(), [](int& i){cout << i << endl;});
Run Code Online (Sandbox Code Playgroud)

但不是一组(编译错误):

std::set<int> collection = {2, 3, 4, 5435345, 2};
std::for_each(collection.begin(), collection.end(), [](int& i){cout << i << endl;});
Run Code Online (Sandbox Code Playgroud)

为什么我不能遍历一个std::setstd::for_each

奖金问题:另外,我想改变int&lambda的论证auto&,为什么不能自动推断?

c++ foreach stl set c++11

7
推荐指数
1
解决办法
6779
查看次数

最小切割顶点/节点 - 而不是边缘

我们都知道并喜欢最小切割算法,但它们都切入图中的边缘.是否存在切断节点的变体?

language-agnostic algorithm graph-theory graph

5
推荐指数
1
解决办法
2144
查看次数

GPU加速硬件模拟?

我正在调查GPGPU是否可用于加速硬件仿真.我的理由是这样的:由于硬件本质上非常平行,为什么要模拟高度顺序的CPU?

GPU非常适合这种情况,如果不是因为它们的限制性编程风格:你有一个内核运行,等等.

我对GPGPU编程没什么经验,但是可以在OpenCL/CUDA中使用事件或队列吗?

编辑:通过硬件模拟,我不是指仿真,而是比特精确的行为仿真(如在VHDL行为仿真中).

simulation cuda opencl hardware-acceleration

5
推荐指数
1
解决办法
1798
查看次数

任何带C输出的C编译器?

我们都知道C编译器会吐出汇编.

然而,我正在研究我的工具只接受ANSI C的一个窄子集.那里有任何C-to-C转换器可以内联函数或扁平化结构,但写出C代码?

任何其他可以简化C代码的工具,让我听听它们.

c code-translation program-transformation

3
推荐指数
1
解决办法
550
查看次数