C talk
Download
1 / 29

C++ Talk - PowerPoint PPT Presentation


  • 115 Views
  • Uploaded on

C++ Talk. The short version! :D. You’ll hopefully know the basics, so this talk covers: C++ templates C++11 cool things. Overview. Conceptually similar to Java generics More powerful though. C++ Templates. C++ Template Examples. C++ Template Examples. C++ Template Examples.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'C++ Talk' - kylee


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
C talk

C++ Talk

The short version! :D


Overview

You’ll hopefully know the basics, so this talk covers:

  • C++ templates

  • C++11 cool things

Overview


C templates

C++ Templates





C template thoughts

C++ Template Thoughts



C 11 cool things

  • Static_assert

  • STL threading (with a new memory model!)

  • ALL THE RRID

  • Lambdas

  • Why you shouldn’t use normal arrays

  • Move semantics (the important part)

C++11 Cool THings



Static assert continued
Static_Assert continued



Lambdas capture group

(‘i’ is read-only in this context. So we can’t do ++i)

Lambdas – Capture Group




Threading native handle
Threading – native_handle()


Threading atomic data types

Threading – Atomic Data TYpes


Rrid stuffs

  • Std::shared_ptr<T>

  • Std::unique_ptr<T>

  • Std::weak_ptr<T>

RRID Stuffs


Std shared ptr
Std::shared_ptr


Std unique ptr
Std::unique_ptr


Std weak ptr
Std::weak_ptr


Std vector std array

  • (std::vector | std::array) > raw arrays

    • Checked STL

    • [] guarantees 0 bounds checking with unchecked STL

    • Iterator support

    • Support for .size()/.max_size()

Std::vector/std::array


Std array
std::array


Std vector
Std::vector


Move semantics

Move semantics


What are move semantics

What are move semantics?


Why do we care

  • Example of strings using copy vs move constructors:

    • By doing copy = primary, invoke string copy constructor

      • Allocate new char[]

      • Copy from primary to copy…

    • By doing move = primary, invoke string move constructor

      • Steal char[] pointer from primary

      • “Primary” is no longer useable after this.

Why do we care?


Why do we care1

  • This code used to be bad:

    • It would call string::string(conststring&) once or twice

  • Now it calls string::string(string&&) once or twice

    • Now just a maximum of six assignments

      • As opposed to 2 allocs, 6 assignments, 2 memcpys

Why do we care?


Summary

  • Std::thread provides for easy threading

  • Templates are extremely flexible

    • Also generated on demand

  • Lambdas are great for one-off functions

  • Use std::unique_ptr and std::shared_ptr in place of raw pointers

  • Use std::array/std::vector instead of raw arrays

Summary