From 815175e35ebe96d03b7a41f59ca4adaee2040488 Mon Sep 17 00:00:00 2001 From: "Stephen M. McQuay" Date: Sat, 5 May 2012 13:45:49 -0600 Subject: [PATCH] finished product --- Makefile | 2 +- constexpr.cc | 2 +- init.cc | 1 + init_new.cc | 6 +++--- tuple.cc | 11 ++++++++--- 5 files changed, 14 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 739887b..30dbc17 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ CXX=g++ # CPPFLAGS=-Wall -g # CPPFLAGS=-Wall -g -std=c++0x -# CPPFLAGS=-Wall -g -std=c++0x -pthread +CPPFLAGS=-Wall -g -std=c++0x -pthread all: @echo "build things individually (make loops, etc.)" diff --git a/constexpr.cc b/constexpr.cc index 37a32a5..7cd9451 100644 --- a/constexpr.cc +++ b/constexpr.cc @@ -1,7 +1,7 @@ #include using namespace std; -int some_constant_func() { +constexpr int some_constant_func() { return 41; } diff --git a/init.cc b/init.cc index cb0d3c3..f4e4d13 100644 --- a/init.cc +++ b/init.cc @@ -11,6 +11,7 @@ struct Point { int main() { string s1("first"); + string s3 = string("again"); int x = int(42); string s2 = "hello"; int y = 42; diff --git a/init_new.cc b/init_new.cc index 4072134..9261829 100644 --- a/init_new.cc +++ b/init_new.cc @@ -13,9 +13,9 @@ const vector s = {"a", "b", "c"}; int main() { string s1 {"first"}; int x {42}; - map singers = { - {"Freddie Mercury", 100}, - {"Matt Bellamy", 100}, + map> singers = { + {"Freddie Mercury", {100, 102, 103}}, + {"Matt Bellamy", {100, 104, 105}}, }; return 0; } diff --git a/tuple.cc b/tuple.cc index 1254a5d..ae9dcf0 100644 --- a/tuple.cc +++ b/tuple.cc @@ -3,16 +3,21 @@ using namespace std; -// make a function that returns multiple values +auto some_func() -> tuple { + return make_tuple(4, 2); +} int main() { - tuple c = make_tuple(5, 4); + 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; - // swap a, b // get a,b from func ... + tie(a, b) = some_func(); + cout << a << endl; + cout << b << endl; }