Slide 2
Slide 2 text
$ sudo apt-get install libgmp-dev libmpfr-dev libmpc-dev g++
$ tar xjf gcc-4.8.0.tar.bz2
$ cd gcc-4.8.0
$ mkdir build
$ cd build
$ ../configure --prefix=/usr/local/gcc --disable-shared --disable-multilib \
--enable-threads --enable-__cxa_atexit --enable-languages=c,c++ \
--disable-nls --enable-libstdcxx-time=rt
$ make -j 4 BOOT_CFLAGS=-O2 bootstrap
$ make install
$ make clean
PATH に を入れて、 に以下を追加。
/usr/local/gcc/bin /etc/manpath.config
MANPATH_MAP /usr/local/gcc/bin /usr/local/gcc/share/man
Better types
int32_t とか C++11 でも使えるようになった。
http://en.cppreference.com/w/cpp/types/integer
その他、型安全な enum や nullptr や
Better types in C++11
tuple/tie も便利
http://en.cppreference.com/w/cpp/utility/tuple
move
named return value optimization 勝手にやる。move constructor があれば。
関数呼び出し等では名前がついているときは しないといけない。
std::move()
自分で move constructor を定義するときは、例外を投げないようにするべき。絶対。
Move constructors
To make strong exception guarantee possible, user-defined move constructors should not throw
exceptions. In fact, standard containers typically rely on std::move_if_noexcept to choose between
move and copy when container elements need to be relocated.
Rvalue References and Exception Safety
std::unique_ptr や 等 move をサポートしているオブジェクトの所有権をどう渡すかはこの記事が良くまとめている。
std::thread
If you mean for a function to claim ownership of a unique_ptr, take it by value.
If you mean for a function to simply use the unique_ptr for the duration of that function's execution, take
it by const&. Alternatively, pass a & or const& to the actual type pointed to, rather than using a
unique_ptr.
If a function may or may not claim ownership (depending on internal code paths), then take it by &&. But I
strongly advise against doing this whenever possible.
How do I pass a unique_ptr argument to a constructor or a function?
短く言うと、引数も返り値も値渡しで書けばいい。