Or: The Ampersand Recovery && Reinvestment Act of 2010 Stephan T. Lavavej Visual C++ Libraries Developer 1Version 1.1 - April 28, 2009.

Slides:



Advertisements
Similar presentations
Lecture Computer Science I - Martin Hardwick The Programming Process rUse an editor to create a program file (source file). l contains the text of.
Advertisements

Lecture Computer Science I - Martin Hardwick Strings #include using namespace std; int main () { string word; cout
Introduction to C++ An object-oriented language Unit - 01.
Boost Writing better code faster with Boost. Boost Introduction Collection of C++ libraries Boost includes 52 libraries, 1.31 will have at least.
C++ Introduction.
Yaser Zhian Dead Mage IGDI, Workshop 10, May 30 th -31 st, 2013.
Brown Bag #3 Return of the C++. Topics  Common C++ “Gotchas”  Polymorphism  Best Practices  Useful Titbits.
Computer Science 1620 Math Library. Remember this program? suppose that I invest $25000 into a mutual fund that returns 8% per year. Write a program to.
Brown Bag #2 Advanced C++. Topics  Templates  Standard Template Library (STL)  Pointers and Smart Pointers  Exceptions  Lambda Expressions  Tips.
How to Program C++/CX Room metro Tokyo #3 2014/1/18 Sat Sao Haruka.
Pass by Value. COMP104 Pass by Value / Slide 2 Passing Parameters by Value * A function returns a single result (assuming the function is not a void function)
Chapter 12 Separate Compilation and Namespaces. Abstract Data Type (ADT) ADT: A data type consisting of data and their behavior. The abstraction is that.
Overview  Miscellaneous Utility Functions  Return Type Deduction  Generic Lambdas  Generalised Lambda Captures  C++14 Literals  constexpr Functions.
Factorial Preparatory Exercise #include using namespace std; double fact(double); int fact(int); int main(void) { const int n=20; ofstream my_file("results.txt");
Chapter 16 Exception Handling. What is Exception Handling? A method of handling errors that informs the user of the problem and prevents the program from.
Vectors, lists and queues

Writing Modern C++ Marc Grégoire Software Architect April 3 rd 2012.
Chapter 6 Advanced Function Features Pass by Value Pass by Reference Const parameters Overloaded functions.
What's new in Microsoft Visual C Preview
Derived data types Dealing with data –Where the information is stored –What value is kept there –What kind of information is stored Address operator Pointers.
Riyadh Philanthropic Society For Science Prince Sultan College For Woman Dept. of Computer & Information Sciences CS 102 Computer Programming II (Lab:
File and I/O system calls int open(const char* path, int flags, mode_t modes) int creat(const char *path, mode_t mode) ssize_t read(int fd, void *buf,
第三次小考. #include using namespace std; int aaa(int *ib,int a1,int a2) { int u,v; int m=(a1+a2)/2; if(a1==a2)return ib[a1]; u=aaa(ib,a1,m); cout
EC-241 Object-Oriented Programming
Chapter 8 Scope, Lifetime and More on Functions. Definitions Scope –The region of program code where it is legal to reference (use) an identifier Three.
C++ Templates. What is a template? Templates are type-generic versions of functions and/or classes Template functions and template classes can be used.
.NET 3.5 – Mysteries. NetFx Evolution NetFx 1.0 C# 1.0, VB 7.0, VS.NET NetFx 1.1 C# 1.1, VB 7.1, VS 2003 NetFx 2.0 C# 2.0, VB 8.0, VS 2005 NetFx 3.0 C#
Tinaliah, S. Kom.. * * * * * * * * * * * * * * * * * #include using namespace std; void main () { for (int i = 1; i
Triana Elizabeth, S.Kom. #include using namespace std; void main () { for (int i = 1; i
Esempio Polimorfismo1 // Definition of abstract base class Shape #ifndef SHAPE_H #define SHAPE_H class Shape { public: virtual double area() const { return.
Methods of variable creation Global variable –declared very early stage –available at all times from anywhere –created at the start of the program, and.
 2006 Pearson Education, Inc. All rights reserved Other Topics.
Computing with C# and the.NET Framework Chapter 1 An Introduction to Computing with C# ©2003, 2011 Art Gittleman.
Functions Pass by Reference Alina Solovyova-Vincent Department of Computer Science & Engineering University of Nevada, Reno Fall 2005.
Functional Programming Think Differently!! Functional languages are expressive, accomplishing tasks using short, succinct and readable code. Functional.
Multiple Files. Monolithic vs Modular  one file before  system includes  main driver function  prototypes  function.
Java Objects and Classes. Overview n Creating objects that belong to the classes in the standard Java library n Creating your own classes.
C++ History C++ was designed at AT&T Bell Labs by Bjarne Stroustrup in the early 80's Based on the ‘C’ programming language C++ language standardised in.
Evaluating Python as an Introductory Programming Language A. Thomas and H.L. Liang UNISA.
1 Original Source : and Problem and Problem Solving.ppt.
C++ Programming Lecture 11 Functions – Part III By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department.
C++ 0x 달려 BOA 요 ~ 아. 꿈. 사 비밀 모임 발표 : 김연기. 발표자 는 뉴규 ? 김연기 아. 꿈. 사 오후반 스터디 그룹 장소 예약 담당 (Pattern Oriented Software Architecture 2) ~ Microsoft Visual.
OOP using C Abstract data types How to accomplish the task??? Requirements Details Input, output, process Specify each task in terms of input.
1 More Operator Overloading Chapter Objectives You will be able to: Define and use an overloaded operator to output objects of your own classes.
Programming II Array of objects. this Using the this Pointer this Objects use the this pointer implicitly or explicitly. – this is – this is used implicitly.
Module 1: Array ITEI222 - Advance Programming Language.
Generic Programming and Library Design Brian Bartman
Current Assignments Project 3 has been posted, due next Tuesday. Write a contact manager. Homework 6 will be posted this afternoon and will be due Friday.
Software Engineering Algorithms, Compilers, & Lifecycle.
C++ Features Function Overloading Default Functions arguments Thinking about objects – relationship to classes Types of member functions Constructor and.
Concepts of programming languages Chapter 5 Names, Bindings, and Scopes Lec. 9 Lecturer: Dr. Emad Nabil 1-1.
C++ Lesson 1.
Eine By: Avinash Reddy 09/29/2016.
Chapter 13 Introduction to C++ Language
C# and the .NET Framework
C++ History C++ was designed at AT&T Bell Labs by Bjarne Stroustrup in the early 80's Based on the ‘C’ programming language C++ language standardised in.
Global & Local Identifiers
#include "std_lib_facilities
Reserved Words.
Data Types.
Static Data Member and Functions
C++ Functions, Classes, and Templates
C Declarations: auto, decltype,using =,nullptr 2. Smart pointers 3. Class changes 4. Range-based for loop 5. The rvalue reference 6. Move semantics.
Name: Rubaisha Rajpoot
Programming -2 برمجة -2 المحاضرة-7 Lecture-7.
Using C++ in your Windows Phone Applications Talk will be repeated tomorrow morning at 8:30 in 33/McKinley Peter Torr, Program Manager.
Virtual Base Classes By:Nouf Aljaffan Edited by : Nouf Almunyif.
CSE 303 Lecture 25 Loose Ends and Random Topics
Introduction to Algorithms and Programming COMP151
Presentation transcript:

Or: The Ampersand Recovery && Reinvestment Act of 2010 Stephan T. Lavavej Visual C++ Libraries Developer 1Version April 28, 2009

 Lambdas  Including mutable lambdas  auto  Including multi-declarator auto  static_assert  Rvalue references  NOT including *this  decltype  Including trailing return types Version April 28, 20092

 Function objects are very powerful  Encapsulating both behavior and state  Function objects are obnoxious to define  Entire classes are inconveniently verbose  Worse, they're inconveniently nonlocal  Libraries are insufficiently helpful  Syntactic contortions  Horrible compiler errors  Performance problems  We need a core language feature for unnamed function objects Version April 28, 20093

 Lambda expressions implicitly define and construct unnamed function objects  Define an unnamed class  Construct an unnamed object  Lambda expression: for_each(v.begin(), v.end(), [](int n) { cout << n << " "; });  Equivalent handwritten function object: struct LambdaFunctor { void operator()(int n) const { void operator()(int n) const { cout << n << " "; cout << n << " "; }}; for_each(v.begin(), v.end(), LambdaFunctor()); Version April 28, 20094

 Lambdas can contain arbitrary amounts of code: for_each(v.begin(), v.end(), [](int n) { cout << n; cout << n; if (n % 2 == 0) { if (n % 2 == 0) { cout << " even "; cout << " even "; } else { } else { cout << " odd "; cout << " odd "; } }); Version April 28, 20095

 Lambdas return void by default  Lambdas of the form { return expression; } get automatic return types  Example: transform(v.begin(), v.end(), front_inserter(d), [](int n) { return n * n * n; }); [](int n) { return n * n * n; });  Another example: sort(v.begin(), v.end(), [](const string& l, const string& r) { [](const string& l, const string& r) { return l.size() < r.size(); return l.size() < r.size(); }); Version April 28, 20096

 Explicit return types go on the right: transform(v.begin(), v.end(), front_inserter(d), [](int n) -> double { [](int n) -> double { if (n % 2 == 0) { if (n % 2 == 0) { return n * n * n; return n * n * n; } else { } else { return n / 2.0; return n / 2.0; } }); });  If you forget, the compiler will complain: error C3499: a lambda that has been specified to have a void return type cannot return a value Version April 28, 20097

 The empty lambda-introducer [] says "I am a stateless lambda", i.e. "I capture nothing"  Within the lambda-introducer, you can specify a capture-list: v.erase(remove_if(v.begin(), v.end(), [x, y](int n) { return x < n && n < y; } [x, y](int n) { return x < n && n < y; } ), v.end()); ), v.end());  If you forget, the compiler will complain: error C3493: 'x' cannot be implicitly captured as no default capture mode has been specified  Lexical scope and conceptual scope are different Version April 28, 20098

 Lambda expression: v.erase(remove_if(v.begin(), v.end(), [x, y](int n) { return x < n && n < y; }), v.end()); [x, y](int n) { return x < n && n < y; }), v.end());  Equivalent handwritten function object: class LambdaFunctor { public: LambdaFunctor(int a, int b) : m_a(a), m_b(b) { } LambdaFunctor(int a, int b) : m_a(a), m_b(b) { } bool operator()(int n) const { bool operator()(int n) const { return m_a < n && n < m_b; } return m_a < n && n < m_b; }private: int m_a; int m_a; int m_b; int m_b;}; v.erase(remove_if(v.begin(), v.end(), LambdaFunctor(x, y)), v.end()); LambdaFunctor(x, y)), v.end()); Version April 28, 20099

 Good news  The function object can outlive the local variables that were captured to create it  Potentially bad news  Some objects are expensive to copy  The captured copies can't be modified within the lambda  Because the function call operator is const by default  Solution: mutable lambdas, see next slide, but even so...  Updates to the captured copies won't be reflected in the local variables  Updates to the local variables won't be reflected in the captured copies Version April 28,

int x = 1; int y = 1; for_each(v.begin(), v.end(), [x, y](int& r) mutable { [x, y](int& r) mutable { const int old = r; const int old = r; r *= x * y; r *= x * y; x = y; x = y; y = old; y = old; }); Version April 28,

int x = 1; int y = 1; for_each(v.begin(), v.end(), [&x, &y](int& r) { [&x, &y](int& r) { const int old = r; const int old = r; r *= x * y; r *= x * y; x = y; x = y; y = old; y = old; }); Version April 28,

#pragma warning(push) // assignment operator #pragma warning(disable: 4512) // could not be generated class LambdaFunctor { public: LambdaFunctor(int& a, int& b) : m_a(a), m_b(b) { } LambdaFunctor(int& a, int& b) : m_a(a), m_b(b) { } void operator()(int& r) const { void operator()(int& r) const { const int old = r; const int old = r; r *= m_a * m_b; r *= m_a * m_b; m_a = m_b; m_a = m_b; m_b = old; m_b = old; }private: int& m_a; int& m_a; int& m_b; int& m_b;}; #pragma warning(pop) int x = 1; int y = 1; for_each(v.begin(), v.end(), LambdaFunctor(x, y)); Version April 28,

 These lambdas are equivalent: [x, y](int n) { return x < n && n < y; } [=](int n) { return x < n && n < y; }  So are these: [&x, &y](int& r) { const int old = r; r *= x * y; x = y; y = old; } const int old = r; r *= x * y; x = y; y = old; } [&](int& r) { const int old = r; r *= x * y; x = y; y = old; } const int old = r; r *= x * y; x = y; y = old; } Version April 28,

int sum = 0; int product = 1; int x = 1; int y = 1; for_each(v.begin(), v.end(), [=, &sum, &product](int& r) mutable { [=, &sum, &product](int& r) mutable { sum += r; sum += r; if (r != 0) { product *= r; } if (r != 0) { product *= r; } const int old = r; const int old = r; r *= x * y; r *= x * y; x = y; x = y; y = old; y = old; }); }); // Equivalent: [&, x, y] // Equivalent: [&sum, &product, x, y] Version April 28,

 Lambdas produce ordinary function objects (with unspecified types) and can be stored in boost/tr1/std::function void meow(const vector & v, const function & f) { for_each(v.begin(), v.end(), f); for_each(v.begin(), v.end(), f); cout << endl; cout << endl;} meow(v, [](int n) { cout << n << " "; }); meow(v, [](int n) { cout << n * n << " "; }); function g = [](int n) { cout << n * n * n << " "; }; cout << n * n * n << " "; }; meow(v, g); Version April 28,

 What's wrong with mem_fn(&string::size) ?  It's nonconformant to take the address of any Standard Library non-virtual member function  C /2 permits additional overloads, making the address-of operator ambiguous  static_cast can't disambiguate: C /2 also permits additional arguments with default values, which change the signature  Lambdas for the win!  [](const string& s) { return s.size(); } Version April 28,

map m; const regex r("(\\w+) (\\w+)"); for (string s; getline(cin, s); ) { smatch results; smatch results; if (regex_match(s, results, r)) { if (regex_match(s, results, r)) { m[results[1]] = results[2]; m[results[1]] = results[2]; }} for (auto i = m.begin(); i != m.end(); ++i) { cout second first second first << endl;} // Instead of map ::iterator Version April 28,

 auto is powered by the template argument deduction rules  const auto * p = foo and const auto& r = bar work  auto...  Reduces verbosity, allowing important code to stand out  Avoids type mismatches and the resulting truncation, etc. errors  Increases genericity, by allowing templates to be written that care less about the types of intermediate expressions  Deals with undocumented or unspeakable types, like lambdas Version April 28,

 auto can be used to name lambdas, allowing them to be reused  Doesn't defeat the point of lambdas; they're still local template template void keep_if(vector & v, Predicate pred) { auto notpred = [&](const T& t) { return !pred(t); }; auto notpred = [&](const T& t) { return !pred(t); }; v.erase(remove_if(v.begin(), v.end(), notpred), v.end()); v.erase(remove_if(v.begin(), v.end(), notpred), v.end());} auto prime = [](const int n) -> bool { if (n < 2) { return false; } if (n < 2) { return false; } for (int i = 2; i <= n / i; ++i) { for (int i = 2; i <= n / i; ++i) { if (n % i == 0) { return false; } if (n % i == 0) { return false; } } return true; return true;}; keep_if(a, prime); keep_if(b, prime); Version April 28,

C:\Temp>type static.cpp #include #include using namespace std; template struct Kitty { static_assert(is_integral ::value, static_assert(is_integral ::value, "Kitty requires T to be an integral type."); "Kitty requires T to be an integral type.");}; int main() { Kitty peppermint; Kitty peppermint; Kitty jazz; Kitty jazz;} Version April 28,

C:\Temp>cl /EHsc /nologo /W4 static.cpp static.cpp static.cpp(6) : error C2338: Kitty requires T to be an integral type. static.cpp(12) : see reference to class template instantiation 'Kitty ' being compiled static.cpp(12) : see reference to class template instantiation 'Kitty ' being compiled with with [ T=double T=double ] Version April 28,

 Rvalue references enable two different things  Move semantics: for performance  Perfect forwarding: for genericity  The move semantics and perfect forwarding patterns are easy to follow  But they're powered by new initialization, overload resolution, template argument deduction, and "reference collapsing" rules  It's C++'s usual deal: complex rules let you write beautifully simple and powerful code  Take an hour to read this: ue-references-c-0x-features-in-vc10-part-2.aspx ue-references-c-0x-features-in-vc10-part-2.aspx ue-references-c-0x-features-in-vc10-part-2.aspx Version April 28,

class remote_integer { public: //... copy ctor, copy assign, etc. omitted... remote_integer(remote_integer&& other) { remote_integer(remote_integer&& other) { m_p = other.m_p; m_p = other.m_p; other.m_p = NULL; other.m_p = NULL; } remote_integer& operator=(remote_integer&& other) { remote_integer& operator=(remote_integer&& other) { if (this != &other) { if (this != &other) { delete m_p; delete m_p; m_p = other.m_p; m_p = other.m_p; other.m_p = NULL; other.m_p = NULL; } return *this; return *this; }private: int * m_p; int * m_p;}; Version April 28,

#include #include class remote_point { public: // implicitly defined copy ctor and copy assign are okay remote_point(remote_point&& other) remote_point(remote_point&& other) : m_x(std::move(other.m_x)), : m_x(std::move(other.m_x)), m_y(std::move(other.m_y)) { } m_y(std::move(other.m_y)) { } remote_point& operator=(remote_point&& other) { remote_point& operator=(remote_point&& other) { m_x = std::move(other.m_x); m_x = std::move(other.m_x); m_y = std::move(other.m_y); m_y = std::move(other.m_y); return *this; return *this; }private: remote_integer m_x; remote_integer m_x; remote_integer m_y; remote_integer m_y;}; Version April 28,

#include #include void inner(int&, int&) { cout << "inner(int&, int&)" << endl; cout << "inner(int&, int&)" << endl;} void inner(int&, const int&) { cout << "inner(int&, const int&)" << endl; cout << "inner(int&, const int&)" << endl;} void inner(const int&, int&) { cout << "inner(const int&, int&)" << endl; cout << "inner(const int&, int&)" << endl;} void inner(const int&, const int&) { cout << "inner(const int&, const int&)" << endl; cout << "inner(const int&, const int&)" << endl;} template void outer(T1&& t1, T2&& t2) { inner(std::forward (t1), std::forward (t2)); inner(std::forward (t1), std::forward (t2));} Version April 28,

struct Plus { template template auto operator()(T&& t, U&& u) const auto operator()(T&& t, U&& u) const -> decltype(forward (t) + forward (u)) { -> decltype(forward (t) + forward (u)) { return forward (t) + forward (u); return forward (t) + forward (u); }}; vector i, j, k; transform(i.begin(), i.end(), j.begin(), back_inserter(k), Plus()); back_inserter(k), Plus()); vector s, t, u; transform(s.begin(), s.end(), t.begin(), back_inserter(u), Plus()); back_inserter(u), Plus()); Version April 28,

 Rvalue references  Supply-side: vector, etc. gains move ctors and move assign ops  Demand-side: vector reallocation, etc. exploits move semantics  Perfect forwarding: make_shared (), etc.  Goodbye auto_ptr : Hello unique_ptr  New member functions: cbegin(), cend(), crbegin(), crend()  New algorithms: copy_if(), is_sorted(), etc.  Singly linked lists: forward_list  Code conversions:  Code conversions:  Exception propagation: exception_ptr    Non-Standard Dinkum Allocators Library  Non-Standard Dinkum Allocators Library  Tons of updates  And more! Version April 28,

 VS 2008 SP1 (VC9 SP1):  shared_ptr sp(new T(args));  shared_ptr sp(new T(args), del, alloc);  VS 2010 (VC10):  auto sp = make_shared (args);  auto sp = allocate_shared (alloc, args);  Convenient!  Mentions the type T once instead of twice  Robust!  Avoids the Classic Unnamed shared_ptr Leak  Efficient!  Performs one dynamic memory allocation instead of two Version April 28,

vector v; for (auto i = v.begin(); i != v.end(); ++i) { // i is vector ::iterator // i is vector ::iterator} for (auto i = v.cbegin(); i != v.cend(); ++i) { // i is vector ::const_iterator // i is vector ::const_iterator} Version April 28,

 Supersedes auto_ptr, which is now deprecated  Noncopyable but movable unique_ptr c(new Cat); unique_ptr c(new Cat); unique_ptr d; unique_ptr d; d.reset(new Dog); d.reset(new Dog); unique_ptr m_src(new Monster); unique_ptr m_src(new Monster); unique_ptr m_dest(move(m_src)); unique_ptr m_dest(move(m_src));  Works just fine in containers vector > v; vector > v; v.push_back(move(c)); v.push_back(move(c)); v.push_back(move(d)); v.push_back(move(d)); v.push_back(move(m_dest)); v.push_back(move(m_dest)); for (auto i = v.cbegin(); i != v.cend(); ++i) { for (auto i = v.cbegin(); i != v.cend(); ++i) { (*i)->make_noise(); (*i)->make_noise(); } Version April 28,

   bool all_of/any_of/none_of(InIt, InIt, Pred)  InIt find_if_not(InIt, InIt, Pred)  OutIt copy_n(InIt, Size, OutIt)  OutIt copy_if(InIt, InIt, OutIt, Pred)  bool is_partitioned(InIt, InIt, Pred)  pair partition_copy(InIt, InIt, Out1, Out2, Pred)  FwdIt partition_point(FwdIt, FwdIt, Pred)  bool is_sorted(FwdIt, FwdIt, Comp?)  FwdIt is_sorted_until(FwdIt, FwdIt, Comp?)  bool is_heap(RanIt, RanIt, Comp?)  RanIt is_heap_until(RanIt, RanIt, Comp?)  pair minmax_element(FwdIt, FwdIt, Comp?)    void iota(FwdIt, FwdIt, T)    InIt next(InIt, Distance)  BidIt prev(BidIt, Distance) Version April 28,

 Non-Standard, but important  VS (VC8-9):  _SECURE_SCL == 0, 1  _HAS_ITERATOR_DEBUGGING == 0, 1  VS 2010 Beta 1 (VC10 Beta 1):  _ITERATOR_DEBUG_LEVEL == 0, 1, 2  Later:  _ITERATOR_DEBUG_LEVEL will default to 0 in release  #pragma detect_mismatch will detect mismatch at link time, preventing ODR violations from causing incomprehensible crashes  Will NOT perform general ODR validation Version April 28,

 C++ Standardization Committee C++ Standardization Committee C++ Standardization Committee  N2857: March 2009 C++0x Working Draft N2857: March 2009 C++0x Working Draft N2857: March 2009 C++0x Working Draft  N2869: March 2009 C++0x Core Language Features N2869: March 2009 C++0x Core Language Features N2869: March 2009 C++0x Core Language Features  N2870: March 2009 C++0x Standard Library Features N2870: March 2009 C++0x Standard Library Features N2870: March 2009 C++0x Standard Library Features  Dinkumware Dinkumware  Dinkum Allocators Library Dinkum Allocators Library Dinkum Allocators Library  Dinkum Conversions Library Dinkum Conversions Library Dinkum Conversions Library  VCBlog VCBlog  C++0x Features in VC10  Part 1: Lambdas, auto, and static_assert Part 1: Lambdas, auto, and static_assert Part 1: Lambdas, auto, and static_assert  Part 2: Rvalue References Part 2: Rvalue References Part 2: Rvalue References  Part 3: decltype Part 3: decltype Part 3: decltype  34Version April 28, 2009

35

 Empty parentheses can be elided from lambdas taking no arguments: vector v; int i = 0; generate_n(back_inserter(v), 10, [&] { return i++; });  As opposed to [&]() { return i++; }  Note that due to how lambdas work syntactically, empty parentheses cannot be omitted when you have mutable or -> ReturnType Version April 28,

 Local variables can be captured  But data members aren't local variables  You can explicitly capture this with [this]  And then use m_foo or this->m_foo as usual  Or, you can implicitly capture this with [=]  Triggered by using m_foo or this->m_foo  this can also be implicitly captured with [&]  But this is always captured by value  [&this] is forbidden Version April 28,

C:\Temp>type meow.cpp #include #include using namespace std; Version April 28,

class Animal { public: Animal() { } Animal() { } virtual ~Animal() { } virtual ~Animal() { } void make_noise() const { void make_noise() const { cout << "This " << name() cout << "This " << name() << " says " << sound() << "." << endl; << " says " << sound() << "." << endl; }private: Animal(const Animal&); Animal(const Animal&); Animal& operator=(const Animal&); Animal& operator=(const Animal&); virtual string name() const = 0; virtual string name() const = 0; virtual string sound() const = 0; virtual string sound() const = 0;}; Version April 28,

class Cat : public Animal { private: virtual string name() const { return "kitty"; } virtual string name() const { return "kitty"; } virtual string sound() const { return "meow"; } virtual string sound() const { return "meow"; }}; class Dog : public Animal { private: virtual string name() const { return "puppy"; } virtual string name() const { return "puppy"; } virtual string sound() const { return "bow-wow"; } virtual string sound() const { return "bow-wow"; }}; class Monster : public Animal { private: virtual string name() const { return "floating eye"; } virtual string name() const { return "floating eye"; } virtual string sound() const { return "*paralyzing gaze*"; } virtual string sound() const { return "*paralyzing gaze*"; }}; Version April 28,

int main() { unique_ptr c(new Cat); unique_ptr c(new Cat); unique_ptr d; unique_ptr d; d.reset(new Dog); d.reset(new Dog); unique_ptr m_src(new Monster); unique_ptr m_src(new Monster); unique_ptr m_dest(move(m_src)); unique_ptr m_dest(move(m_src)); vector > v; vector > v; v.push_back(move(c)); v.push_back(move(c)); v.push_back(move(d)); v.push_back(move(d)); v.push_back(move(m_dest)); v.push_back(move(m_dest)); for (auto i = v.cbegin(); i != v.cend(); ++i) { for (auto i = v.cbegin(); i != v.cend(); ++i) { (*i)->make_noise(); (*i)->make_noise(); }} Version April 28,

C:\Temp>cl /EHsc /nologo /W4 meow.cpp meow.cppC:\Temp>meow This kitty says meow. This puppy says bow-wow. This floating eye says *paralyzing gaze*. Version April 28,