cpp11/notes.rst

109 lines
2.4 KiB
ReStructuredText
Raw Normal View History

2012-05-05 08:36:42 -07:00
=====
C++11
=====
.. rubric:: oh dear, it burns
2012-05-25 07:17:47 -07:00
Intro
=====
2012-05-05 08:36:42 -07:00
- Approved 2011-08-12
- for some time called c++0x
2012-05-25 07:17:47 -07:00
- references:
- primarily the `wikipedia article`_ on c++11
- also `Bjarne's FAQ`_
2012-05-05 08:36:42 -07:00
.. _`wikipedia article`: http://en.wikipedia.org/wiki/C%2B%2B11
2012-05-25 07:17:47 -07:00
.. _`Bjarne's FAQ`: http://www2.research.att.com/~bs/C++0xFAQ.html
2012-05-05 08:36:42 -07:00
initializer lists
=================
2012-05-25 07:17:47 -07:00
- see example with/without -std=c++0x; specifically in this order:
- init.cc
- ilists.cc: c++03
- init_new.cc
2012-05-05 08:36:42 -07:00
- initializer_list<>
2012-05-25 07:17:47 -07:00
- allows constructors to take initializer lists
New Loop Syntax
===============
- example from int, iterator, new syntax
- copy/ref
2012-05-05 08:36:42 -07:00
type inference
==============
- auto keyword
- decltype
new string literals
===================
- u8"I'm a UTF-8 string."
- u"This is a UTF-16 string."
- U"This is a UTF-32 string."
2012-05-25 07:57:20 -07:00
- R"\w+" instead of "\\w+"
- doesn't seem to work with my compilers
2012-05-05 08:36:42 -07:00
tuple fun
=========
2012-05-25 07:17:47 -07:00
- generalization of std::pair
2012-05-05 08:36:42 -07:00
- #include <tuple>
- make_tuple
- tie
lambdas
=======
- see `c++11 anonymous funcs`_
- [capture](arguments) -> return-type {body}
- capture:
- [] capture nothing
- [x, &y] x by value, y by reference
- [&] any external variable captured by ref
- [=] any external variable captured by val
- [&, x] x by val, everything else by ref
- [=, &x] x by ref, everything else by val
.. _`c++11 anonymous funcs`: http://en.wikipedia.org/wiki/Anonymous_function#C.2B.2B
regular expressions and threading
=================================
2012-05-25 07:17:47 -07:00
- this is where the burning starts to set in ...
2012-05-25 07:57:20 -07:00
- threading works ... mostly
2012-05-25 09:06:00 -07:00
- `great quote`_
2012-05-25 07:57:20 -07:00
- compiles and runs with both compilers
- run stress
- regex examples
- compile with gcc to see how awesome that is
- compile with clang
- instructions on building this found `here`_
2012-05-25 07:17:47 -07:00
.. _`here`: http://solarianprogrammer.com/2011/10/16/llvm-clang-libc-linux/
2012-05-25 09:06:00 -07:00
.. _`great quote`: https://twitter.com/nedbat/status/194452404794691584
2012-05-25 07:17:47 -07:00
constexpr
=========
- see example with/without -std=c++0x
- see wiki for limitations
- constructors of user-defined types can be declared constexpr
2012-05-05 08:36:42 -07:00
rvalue
=======
- pass-by-value is deep-copy (usually)
- c++11 adds notion of "move constructor"
- takes the rvalue ref's stuff and nullifies the rvalue
- 'safe and invisible' (because it's null, memory is not del'd when it goes
out of scope)
- rvalue is automatic when using stuff with "move constructor"
- std::move<T>()
Smart Pointers
==============