updated for presentation

This commit is contained in:
Stephen M. McQuay 2012-05-25 08:17:47 -06:00
parent b47b5c6f35
commit 530ccb5e37
7 changed files with 62 additions and 45 deletions

View File

@ -12,6 +12,6 @@ thang scalar = {3.14, 42};
thang anArray[] = {{1.1, 1}, {2.2, 2}, {3.3, 3}};
int main() {
// vector<thang> v = { ??? } ... see init_new
// vector<thang> v = { ??? }
return 0;
}

10
init.cc
View File

@ -1,5 +1,6 @@
#include <string>
#include <iostream>
#include <vector>
using namespace std;
struct Point {
@ -7,7 +8,7 @@ struct Point {
Point(int x, int y): x(x), y(y){}
};
// const vector<string> v = ??;
// const vector<string> 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<string> 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;
}

View File

@ -1,6 +1,5 @@
#include <string>
#include <vector>
#include <map>
using namespace std;
struct Point {
@ -13,10 +12,12 @@ const vector<string> s = {"a", "b", "c"};
int main() {
string s1 {"first"};
int x {42};
map<string, vector<int>> singers = {
{"Freddie Mercury", {100, 102, 103}},
{"Matt Bellamy", {100, 104, 105}},
};
vector<string> names_v = {"stephen", "michael", "bryan", "derek"};
// map example
// with nested types
x = 0;
return x;
}

View File

@ -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<int> 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;
}

View File

@ -14,18 +14,11 @@ const vector<string> mcquays = {
int main() {
for(auto name: mcquays) {
cout << name << endl;
}
// original with uint
// original with iterator
vector<int> 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<string, int> 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:
}

View File

@ -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 <tuple>
- 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
=======

View File

@ -3,21 +3,11 @@
using namespace std;
auto some_func() -> tuple<int, int> {
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 <i> syntax)
// swap a and b
// get a,b from func ...
tie(a, b) = some_func();
cout << a << endl;
cout << b << endl;
}