[Assorted-commits] SF.net SVN: assorted:[1495] sandbox/trunk/src/cc
Brought to you by:
yangzhang
From: <yan...@us...> - 2009-11-03 17:16:27
|
Revision: 1495 http://assorted.svn.sourceforge.net/assorted/?rev=1495&view=rev Author: yangzhang Date: 2009-11-03 17:16:07 +0000 (Tue, 03 Nov 2009) Log Message: ----------- added gcc 4.4 c++0x demos Added Paths: ----------- sandbox/trunk/src/cc/inference.cc sandbox/trunk/src/cc/init_lists.cc Added: sandbox/trunk/src/cc/inference.cc =================================================================== --- sandbox/trunk/src/cc/inference.cc (rev 0) +++ sandbox/trunk/src/cc/inference.cc 2009-11-03 17:16:07 UTC (rev 1495) @@ -0,0 +1,21 @@ +#include <iostream> +#include <map> +#include <vector> +using namespace std; + +int main() { + auto x = 2; + cout << x << endl; + + auto xs = vector<int>({0,1,2,3}); + cout << xs[2] << endl; + + const auto ys = xs; + // No need for: + // for (vector<int>::const_iterator y = xs.begin(); y != xs.end(); ++y) { + for (auto y = ys.begin(); y != ys.end(); ++y) { + cout << *y << endl; + } + + return 0; +} Added: sandbox/trunk/src/cc/init_lists.cc =================================================================== --- sandbox/trunk/src/cc/init_lists.cc (rev 0) +++ sandbox/trunk/src/cc/init_lists.cc 2009-11-03 17:16:07 UTC (rev 1495) @@ -0,0 +1,41 @@ +#include <iostream> +#include <map> +#include <vector> +using namespace std; + +void f(const vector<int> &xs) { cout << xs[2] << endl; } + +struct point { + point(int x, int y) : x(x), y(y) {} + int x, y; +}; + +struct point2 { + point2(initializer_list<int> xs) { + for (const int *p = xs.begin(); p != xs.end(); ++p) { + ys.push_back(*p); + } + } + vector<int> ys; +}; + +int main() { + vector<int> xs = {0, 1, 2, 3}; + cout << xs[2] << endl; + cout << (vector<int>({0, 1, 2, 3}))[2] << endl; + f({0, 1, 2, 3}); + + point p = {2, 3}; + + point2 q = {0, 1, 2, 3}; + cout << q.ys[2] << endl; + + // causes a segfault in gcc 4.4.1 + map<int, pair<int, int>> m = {{0, {0, 0}}, + {1, {1, 1}}, + {2, {2, 2}}, + {3, {3, 3}}}; + cout << m[2].first << endl; + + return 0; +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |