From 530ccb5e37ea656fb7c605073d9f8bdb7df6e424 Mon Sep 17 00:00:00 2001 From: "Stephen M. McQuay" Date: Fri, 25 May 2012 08:17:47 -0600 Subject: [PATCH] updated for presentation --- ilists.cc | 2 +- init.cc | 10 +++++++++- init_new.cc | 11 ++++++----- lambda.cc | 7 +++++++ loops.cc | 17 ++++------------- notes.rst | 42 +++++++++++++++++++++++++++++++----------- tuple.cc | 18 ++++-------------- 7 files changed, 62 insertions(+), 45 deletions(-) diff --git a/ilists.cc b/ilists.cc index 28ca183..469e9b9 100644 --- a/ilists.cc +++ b/ilists.cc @@ -12,6 +12,6 @@ thang scalar = {3.14, 42}; thang anArray[] = {{1.1, 1}, {2.2, 2}, {3.3, 3}}; int main() { - // vector v = { ??? } ... see init_new + // vector v = { ??? } return 0; } diff --git a/init.cc b/init.cc index 2da9e27..0737e83 100644 --- a/init.cc +++ b/init.cc @@ -1,5 +1,6 @@ #include #include +#include using namespace std; struct Point { @@ -7,7 +8,7 @@ struct Point { Point(int x, int y): x(x), y(y){} }; -// const vector v = ??; +// const vector v = ??; // wat // http://stackoverflow.com/a/4268956 int main() { @@ -17,5 +18,12 @@ int main() { string s2 = "hello"; int y = 42; cout << x << " " << y << " " << endl; + + string names[] = {"stephen", "michael", "bryan", "derek"}; + vector names_v (names, names + 3); + // what is the bug here? + for(unsigned int i = 0; i < names_v.size(); i++) { + cout << names_v[i] << endl; + } return 0; } diff --git a/init_new.cc b/init_new.cc index 52715f1..e5a5f79 100644 --- a/init_new.cc +++ b/init_new.cc @@ -1,6 +1,5 @@ #include #include -#include using namespace std; struct Point { @@ -13,10 +12,12 @@ const vector s = {"a", "b", "c"}; int main() { string s1 {"first"}; int x {42}; - map> singers = { - {"Freddie Mercury", {100, 102, 103}}, - {"Matt Bellamy", {100, 104, 105}}, - }; + + vector names_v = {"stephen", "michael", "bryan", "derek"}; + + // map example + // with nested types + x = 0; return x; } diff --git a/lambda.cc b/lambda.cc index 06c7f6e..55114c3 100644 --- a/lambda.cc +++ b/lambda.cc @@ -13,5 +13,12 @@ int main() { cout << "total: " << total << endl; auto my_lambda_doubling_func = [&](int x) -> int { return x * 2; }; cout << my_lambda_doubling_func(total) << endl; + vector orderme = {46, 78, 2, 75, 33, 1, 65, 48, 45, 73}; + sort(orderme.begin(), orderme.end(), [](int x, int y) -> bool { + return x < y; + }); + for(auto x: orderme) { + cout << x << endl; + } return 0; } diff --git a/loops.cc b/loops.cc index b3124e7..883ddfe 100644 --- a/loops.cc +++ b/loops.cc @@ -14,18 +14,11 @@ const vector mcquays = { int main() { - for(auto name: mcquays) { - cout << name << endl; - } + // original with uint + // original with iterator vector nums = { 1, 2, 3, 4, 5 }; - for(auto & n: nums) { - n--; - } - - for(auto n: nums) { - cout << n << endl; - } + // fix so nums is 0, 1, 2 ... map age_for_mcquay = { {"stephen", 31}, @@ -34,7 +27,5 @@ int main() { {"derek", 21}, }; - for(auto p: age_for_mcquay) { - cout << p.first << " " << p.second << endl; - } + // map example: } diff --git a/notes.rst b/notes.rst index fcff443..12b1eca 100644 --- a/notes.rst +++ b/notes.rst @@ -4,26 +4,33 @@ C++11 .. rubric:: oh dear, it burns +Intro +===== + - Approved 2011-08-12 - for some time called c++0x -- references: primarily the `wikipedia article`_ on c++11 +- references: + - primarily the `wikipedia article`_ on c++11 + - also `Bjarne's FAQ`_ .. _`wikipedia article`: http://en.wikipedia.org/wiki/C%2B%2B11 +.. _`Bjarne's FAQ`: http://www2.research.att.com/~bs/C++0xFAQ.html -constexpr -========= - -- see example with/without -std=c++0x -- see wiki for limitations -- constructors of user-defined types can be declared constexpr - initializer lists ================= -- see example with/without -std=c++0x +- see example with/without -std=c++0x; specifically in this order: + - init.cc + - ilists.cc: c++03 + - init_new.cc - initializer_list<> - - constructed, copied, only by ref + - allows constructors to take initializer lists + +New Loop Syntax +=============== +- example from int, iterator, new syntax +- copy/ref type inference ============== @@ -41,6 +48,7 @@ new string literals tuple fun ========= +- generalization of std::pair - #include - make_tuple - tie @@ -63,7 +71,19 @@ lambdas regular expressions and threading ================================= -- this is where the burning starts ... +- this is where the burning starts to set in ... +- compile with gcc to see how awesome that is +- compile with clang + - instructions on building this found `here`_ + +.. _`here`: http://solarianprogrammer.com/2011/10/16/llvm-clang-libc-linux/ + +constexpr +========= + +- see example with/without -std=c++0x +- see wiki for limitations +- constructors of user-defined types can be declared constexpr rvalue ======= diff --git a/tuple.cc b/tuple.cc index ae9dcf0..f64cf2d 100644 --- a/tuple.cc +++ b/tuple.cc @@ -3,21 +3,11 @@ using namespace std; -auto some_func() -> tuple { - return make_tuple(4, 2); -} + +// tuple-returning func int main() { - auto c = make_tuple(5, 4); - cout << get<0>(c) << endl; - - int a = 0; - int b = 1; - tie(a, b) = make_tuple(b, a); - cout << a << endl; - cout << b << endl; + // make a tuple, get a value from it (silly syntax) + // swap a and b // get a,b from func ... - tie(a, b) = some_func(); - cout << a << endl; - cout << b << endl; }