C++ (Qt)void DoCopy( const int * src, int * dst, int count ){ const int * end = src + count; while (src != end) { *dst = *src; // *(dst++) = *(src++); ++src; ++dst; }}
C++ (Qt)void DoCopy( const int * src, int * dst, int count ){ for( size_t i = 0; i < count; ++i ) dst[ i ] = src[ i ];}
C++ (Qt)#include <vector>#include <cstdio> struct Point3D { double x, y, z;}; struct Triangle { int v[3];}; typedef std::vector<Point3D> Points;typedef std::vector<Triangle> Triangles;typedef std::vector<int> Indexes; void remove_points(Points &points, Triangles &triangles, const Indexes &remove){ size_t sz = points.size(); // create map for points indexes Indexes map(sz); // mapping to -1 means removed for (size_t i = 0; i < remove.size(); ++i) { map[remove[i]] = -1; } // compute mapping and update points size_t count = 0; for (size_t i = 0; i < sz; ++i) { if (map[i] != -1) { map[i] = count; points[count++] = points[i]; } } points.resize(count); // update triangles count = 0; for (size_t i = 0; i < triangles.size(); ++i) { Triangle &t = triangles[i]; bool removed = false; for (size_t j = 0; j < 3; ++j) { int u = map[t.v[j]]; if (u == -1) { removed = true; break; } t.v[j] = u; } if (!removed) { triangles[count++] = t; } } triangles.resize(count);} void print(const char* str, const Triangles &triangles){ std::printf("%s:", str); for (size_t i = 0; i < triangles.size(); ++i) { const Triangle & t = triangles[i]; std::printf("%s(%d, %d, %d)", (i % 3 ? ", " : "\n "), t.v[0], t.v[1], t.v[2]); } std::printf("\n\n");} int main(){ Points pts = { {0, 0, 0}, {1, 0, 0}, {0, 1, 0}, {0, 0, 1}, {1, 1, 1}, {2, 2, 2} }; Triangles trs = { {{0, 1, 2}}, {{0, 2, 3}}, {{2, 3, 1}}, {{2, 4, 3}}, {{4, 3, 1}}, {{4, 2, 3}}, {{0, 2, 4}}, {{0, 1, 4}}, {{5, 2, 1}}, {{5, 4, 3}}, {{0, 2, 5}}, {{1, 3, 5}}, }; Indexes ids = { 0, 2 }; print("Before", trs); remove_points(pts, trs, ids); print("After", trs);}
C++ (Qt)std::list<int> src;MyCollection dst; for( int i = 0; i < src.size(); ++i ) dst[ i ] = src[ i ];