From a3ac1124315bcf918902db76106294fc5396c216 Mon Sep 17 00:00:00 2001 From: Anthony Calandra Date: Fri, 24 Mar 2017 23:44:54 -0400 Subject: [PATCH] Converting constructors. --- README.md | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/README.md b/README.md index d7f833b..5263d16 100644 --- a/README.md +++ b/README.md @@ -61,6 +61,7 @@ C++11 includes the following new language features: - [deleted functions](#deleted-functions) - [range-based for loops](#range-based-for-loops) - [special member functions for move semantics](#special-member-functions-for-move-semantics) +- [converting constructors](#converting-constructors) C++11 includes the following new library features: - [std::move](#stdmove) @@ -944,6 +945,36 @@ a2 = std::move(a3); // move-assignment using std::move a1 = f(A{}); // move-assignment from rvalue temporary ``` +### Converting constructors +Converting constructors will convert values of braced list syntax into constructor arguments. +```c++ +struct A { + A(int) {} + A(int, int) {} + A(int, int, int) {} +}; + +A a{0, 0}; // calls A::A(int, int) +A b(0, 0); // calls A::A(int, int) +A c = {0, 0}; // calls A::A(int, int) +A d{0, 0, 0}; // calls A::A(int, int, int) +``` + +Note that if a constructor accepts a `std::initializer_list`, it will be called instead: +```c++ +struct A { + A(int) {} + A(int, int) {} + A(int, int, int) {} + A(std::initializer_list) {} +}; + +A a{0, 0}; // calls A::A(std::initializer_list) +A b(0, 0); // calls A::A(int, int) +A c = {0, 0}; // calls A::A(std::initializer_list) +A d{0, 0, 0}; // calls A::A(std::initializer_list) +``` + ## C++11 Library Features ### std::move