Download - What's new in Microsoft Visual C++ 2015 Preview December 17 th 201 4 Marc Grégoire [email protected]
![Page 1: What's new in Microsoft Visual C++ 2015 Preview December 17 th 201 4 Marc Grégoire marc.gregoire@nuonsoft.com](https://reader036.vdocuments.mx/reader036/viewer/2022062421/56649c755503460f94928fe6/html5/thumbnails/1.jpg)
What's new in MicrosoftVisual C++ 2015 Preview
December 17th 2014
Marc Gré[email protected] http://www.nuonsoft.com/ http://www.nuonsoft.com/blog/
![Page 2: What's new in Microsoft Visual C++ 2015 Preview December 17 th 201 4 Marc Grégoire marc.gregoire@nuonsoft.com](https://reader036.vdocuments.mx/reader036/viewer/2022062421/56649c755503460f94928fe6/html5/thumbnails/2.jpg)
Agenda
C++11, C++14, C++17 Productivity Improvements Improved Performance C++ Cross-Platform Mobile Dev
![Page 3: What's new in Microsoft Visual C++ 2015 Preview December 17 th 201 4 Marc Grégoire marc.gregoire@nuonsoft.com](https://reader036.vdocuments.mx/reader036/viewer/2022062421/56649c755503460f94928fe6/html5/thumbnails/3.jpg)
C++11, C++14, C++17Increased standard compliancy
![Page 4: What's new in Microsoft Visual C++ 2015 Preview December 17 th 201 4 Marc Grégoire marc.gregoire@nuonsoft.com](https://reader036.vdocuments.mx/reader036/viewer/2022062421/56649c755503460f94928fe6/html5/thumbnails/4.jpg)
C++11 Core Language Features New or updated C++11 core language features
ref-qualifiers Partial support for constexpr Inheriting constructors char16_t and char32_t Unicode string literals User-defined literals Full defaulted and deleted functions support (partial in VC++2013) Extended sizeof() noexcept Inline namespaces Full Rvalue references compliant (partial VC++2013) Full alignment support (partial in VC++2013) Unrestricted unions
![Page 5: What's new in Microsoft Visual C++ 2015 Preview December 17 th 201 4 Marc Grégoire marc.gregoire@nuonsoft.com](https://reader036.vdocuments.mx/reader036/viewer/2022062421/56649c755503460f94928fe6/html5/thumbnails/5.jpg)
ref-qualifiers
rvalue references are well-known for function parameters, example: void foo(Bar&& bar);
How to apply rvalue reference to *this?class Foo {
void f1() const; // *this is const
void f2() &; // *this is an lvalue
void f3() &&; // *this is an rvalue
};
![Page 6: What's new in Microsoft Visual C++ 2015 Preview December 17 th 201 4 Marc Grégoire marc.gregoire@nuonsoft.com](https://reader036.vdocuments.mx/reader036/viewer/2022062421/56649c755503460f94928fe6/html5/thumbnails/6.jpg)
ref-qualifiers – Contrived Example
class BigObject {};class BigObjectFactory {public: BigObject Get() { return m_bigObject; } private: BigObject m_bigObject;};
BigObjectFactory aFactory; BigObject obj = aFactory.Get();
![Page 7: What's new in Microsoft Visual C++ 2015 Preview December 17 th 201 4 Marc Grégoire marc.gregoire@nuonsoft.com](https://reader036.vdocuments.mx/reader036/viewer/2022062421/56649c755503460f94928fe6/html5/thumbnails/7.jpg)
ref-qualifiers – Contrived Example
But what with this:BigObject obj = BigObjectFactory().Get();
The factory is a temporary object, but BigObject is still copied because *this is not an rvalue-reference
Solution: Make BigObject moveable Overload Get() for an rvalue-reference *this
![Page 8: What's new in Microsoft Visual C++ 2015 Preview December 17 th 201 4 Marc Grégoire marc.gregoire@nuonsoft.com](https://reader036.vdocuments.mx/reader036/viewer/2022062421/56649c755503460f94928fe6/html5/thumbnails/8.jpg)
ref-qualifiers – Contrived Example
class BigObject {};class BigObjectFactory {public: BigObject Get() const & { // *this is an lvalue return m_bigObject; // Deep copy } BigObject Get() && { // *this is an rvalue return std::move(m_bigObject); // move }private: BigObject m_bigObject;};
BigObjectFactory myFactory;
BigObject o1 = myFactory.Get(); // Deep copy
BigObject o2 = BigObjectFactory().Get();// Move
![Page 9: What's new in Microsoft Visual C++ 2015 Preview December 17 th 201 4 Marc Grégoire marc.gregoire@nuonsoft.com](https://reader036.vdocuments.mx/reader036/viewer/2022062421/56649c755503460f94928fe6/html5/thumbnails/9.jpg)
constexpr
Constant expressions Simple example
static constexpr size_t FACTOR = 2;constexpr size_t CalculateArraySize(size_t base){ return base * FACTOR;}...double arr[CalculateArraySize(123)];
![Page 10: What's new in Microsoft Visual C++ 2015 Preview December 17 th 201 4 Marc Grégoire marc.gregoire@nuonsoft.com](https://reader036.vdocuments.mx/reader036/viewer/2022062421/56649c755503460f94928fe6/html5/thumbnails/10.jpg)
Inheriting constructors
class Base{public: Base(int data) : m_data(data) {}private: int m_data;};class Derived : Base{public: Derived(const std::string& msg) : Base(1), m_msg(msg) {}private: std::string m_msg;};...Base b1(123); // OKDerived d1("Message"); // OKDerived d2(456); // NOT OK
![Page 11: What's new in Microsoft Visual C++ 2015 Preview December 17 th 201 4 Marc Grégoire marc.gregoire@nuonsoft.com](https://reader036.vdocuments.mx/reader036/viewer/2022062421/56649c755503460f94928fe6/html5/thumbnails/11.jpg)
Inheriting Constructorsclass Base{public: Base(int data) : m_data(data) {}private: int m_data;};class Derived : Base{public: using Base::Base; Derived(const std::string& msg) : Base(1), m_msg(msg) {}private: std::string m_msg;};...Derived d2(456); // OK
![Page 12: What's new in Microsoft Visual C++ 2015 Preview December 17 th 201 4 Marc Grégoire marc.gregoire@nuonsoft.com](https://reader036.vdocuments.mx/reader036/viewer/2022062421/56649c755503460f94928fe6/html5/thumbnails/12.jpg)
char16_t and char32_t
Existing character types: char: only 8 bits wchar_t: compiler-dependent size, not specified
by C++ standard! hard to use for platform independent code
New character types: char16_t and char32_t
![Page 13: What's new in Microsoft Visual C++ 2015 Preview December 17 th 201 4 Marc Grégoire marc.gregoire@nuonsoft.com](https://reader036.vdocuments.mx/reader036/viewer/2022062421/56649c755503460f94928fe6/html5/thumbnails/13.jpg)
char16_t and char32_t
In total 4 character types: char: stores 8 bits; can be used to store ASCII,
or as building block for UTF-8 encoded Unicode characters
char16_t: stores at least 16 bits; building block for UTF-16 encoded Unicode characters
char32_t: stores at least 32 bits; building block for UTF-32 encoded Unicode characters
wchar_t: stores a wide character of a compiler dependent size and encoding
![Page 14: What's new in Microsoft Visual C++ 2015 Preview December 17 th 201 4 Marc Grégoire marc.gregoire@nuonsoft.com](https://reader036.vdocuments.mx/reader036/viewer/2022062421/56649c755503460f94928fe6/html5/thumbnails/14.jpg)
char16_t and char32_t
A compiler can define the following new preprocessor defines: __STDC_UTF_32__: If defined then char32_t
represents a UTF-32 encoding, otherwise it has a compiler dependent encoding.
__STDC_UTF_16__: If defined then char16_t represents a UTF-16 encoding, otherwise it has a compiler dependent encoding.
Both not defined in VC++2015 Preview
![Page 15: What's new in Microsoft Visual C++ 2015 Preview December 17 th 201 4 Marc Grégoire marc.gregoire@nuonsoft.com](https://reader036.vdocuments.mx/reader036/viewer/2022062421/56649c755503460f94928fe6/html5/thumbnails/15.jpg)
char16_t and char32_t
New std::basic_string specializations: typedef basic_string<char> string; typedef basic_string<wchar_t> wstring; typedef basic_string<char16_t> u16string;
typedef basic_string<char32_t> u32string;
![Page 16: What's new in Microsoft Visual C++ 2015 Preview December 17 th 201 4 Marc Grégoire marc.gregoire@nuonsoft.com](https://reader036.vdocuments.mx/reader036/viewer/2022062421/56649c755503460f94928fe6/html5/thumbnails/16.jpg)
char16_t and char32_t
Unfortunately, support for char16_t and char32_t stops here
No I/O stream classes support these new types
No version of cout/cin/… for these types
![Page 17: What's new in Microsoft Visual C++ 2015 Preview December 17 th 201 4 Marc Grégoire marc.gregoire@nuonsoft.com](https://reader036.vdocuments.mx/reader036/viewer/2022062421/56649c755503460f94928fe6/html5/thumbnails/17.jpg)
Unicode String Literals
New string literals: L: A wchar_t string literal with a compiler-
dependent encoding u8: A char string literal with UTF-8 encoding u: A char16_t string literal, which can be UTF-16
if __STDC_UTF_16__ is defined by the compiler U: A char32_t string literal, which can be UTF-32
if __STDC_UTF_32__ is defined by the compiler
![Page 18: What's new in Microsoft Visual C++ 2015 Preview December 17 th 201 4 Marc Grégoire marc.gregoire@nuonsoft.com](https://reader036.vdocuments.mx/reader036/viewer/2022062421/56649c755503460f94928fe6/html5/thumbnails/18.jpg)
Unicode String Literals
All can be combined with the R prefix for raw string literals:const char* s1 = u8R"(Raw UTF-8 encoded string literal)";
const wchar_t* s2 = LR"(Raw wide string literal)";
const char16_t* s3 = uR"(Raw char16_t string literal)";
const char32_t* s4 = UR"(Raw char32_t string literal)";
![Page 19: What's new in Microsoft Visual C++ 2015 Preview December 17 th 201 4 Marc Grégoire marc.gregoire@nuonsoft.com](https://reader036.vdocuments.mx/reader036/viewer/2022062421/56649c755503460f94928fe6/html5/thumbnails/19.jpg)
User-Defined Literals
C++ has standard literals such as: 'a': character "character array": zero-terminated array of
characters, C-style string 3.14f: float floating point value 0xabc: hexadecimal value
![Page 20: What's new in Microsoft Visual C++ 2015 Preview December 17 th 201 4 Marc Grégoire marc.gregoire@nuonsoft.com](https://reader036.vdocuments.mx/reader036/viewer/2022062421/56649c755503460f94928fe6/html5/thumbnails/20.jpg)
User-Defined Literals
Start with _ Implemented in a literal operator:
Raw mode: op receives sequence of characters Cooked mode: op receives an interpreted type Example: literal 0x23
Raw mode op receives ‘0’, ‘x’, ‘2’, ‘3’ Cooked mode op receives the integer 35
![Page 21: What's new in Microsoft Visual C++ 2015 Preview December 17 th 201 4 Marc Grégoire marc.gregoire@nuonsoft.com](https://reader036.vdocuments.mx/reader036/viewer/2022062421/56649c755503460f94928fe6/html5/thumbnails/21.jpg)
User-Defined Literals – Cooked Mode
Has 1 parameter to process numeric values Type can be unsigned long long, long double,
char, wchar_t, char16_t or char32_t or 2 parameters to process strings
a character array the length of the character array example: (const char* str, size_t len)
![Page 22: What's new in Microsoft Visual C++ 2015 Preview December 17 th 201 4 Marc Grégoire marc.gregoire@nuonsoft.com](https://reader036.vdocuments.mx/reader036/viewer/2022062421/56649c755503460f94928fe6/html5/thumbnails/22.jpg)
User-Defined Literals – Cooked Mode
Example: cooked mode complex number literal
std::complex<double> operator"" _i(long double d){ return std::complex<double>(0, d);}
std::complex<double> c1 = 9.634_i;auto c2 = 1.23_i; // type is std::complex<double>
![Page 23: What's new in Microsoft Visual C++ 2015 Preview December 17 th 201 4 Marc Grégoire marc.gregoire@nuonsoft.com](https://reader036.vdocuments.mx/reader036/viewer/2022062421/56649c755503460f94928fe6/html5/thumbnails/23.jpg)
User-Defined Literals – Cooked Mode
Example: cooked mode std::string literal
std::string operator"" _s(const char* str, size_t len){ return std::string(str, len);}
std::string str1 = "Hello World"_s;auto str2 = "Hello World"_s; // type is std::stringauto str3 = "Hello World"; // type is const char*
![Page 24: What's new in Microsoft Visual C++ 2015 Preview December 17 th 201 4 Marc Grégoire marc.gregoire@nuonsoft.com](https://reader036.vdocuments.mx/reader036/viewer/2022062421/56649c755503460f94928fe6/html5/thumbnails/24.jpg)
User-Defined Literals – Raw Mode
Example: raw mode complex number literal
std::complex<double> operator"" _i(const char* p){ // Implementation omitted; it requires parsing the C-style // string and converting it to a complex number.}
![Page 25: What's new in Microsoft Visual C++ 2015 Preview December 17 th 201 4 Marc Grégoire marc.gregoire@nuonsoft.com](https://reader036.vdocuments.mx/reader036/viewer/2022062421/56649c755503460f94928fe6/html5/thumbnails/25.jpg)
Full Defaulted and Deleted Functions Support
=default Ask the compiler to forcefully generate the default
implementation Example:
class C{public: C(int i) {} C() = default;};
![Page 26: What's new in Microsoft Visual C++ 2015 Preview December 17 th 201 4 Marc Grégoire marc.gregoire@nuonsoft.com](https://reader036.vdocuments.mx/reader036/viewer/2022062421/56649c755503460f94928fe6/html5/thumbnails/26.jpg)
Full Defaulted and Deleted Functions Support
=delete Forcefully delete an implementation
Error message states intent, better error message than making it private without implementation
Example:class C{public: C() = delete; C(const C& src) = delete; C& operator=(const C& src) = delete;};C c;//error C2280:'C::C(void)': attempting to reference a deleted function
![Page 27: What's new in Microsoft Visual C++ 2015 Preview December 17 th 201 4 Marc Grégoire marc.gregoire@nuonsoft.com](https://reader036.vdocuments.mx/reader036/viewer/2022062421/56649c755503460f94928fe6/html5/thumbnails/27.jpg)
Full Defaulted and Deleted Functions Support
=delete can be used to disallow calling a function with a certain type
Example:void foo(int i) { }...foo(123);foo(1.23); // Compiles, but with warning
Disallow calling foo() with doubles by deleting a double overload of foo():void foo(int i) { }void foo(double d) = delete;...foo(123);foo(1.23); // error C2280: 'void foo(double)' : // attempting to reference a deleted function
![Page 28: What's new in Microsoft Visual C++ 2015 Preview December 17 th 201 4 Marc Grégoire marc.gregoire@nuonsoft.com](https://reader036.vdocuments.mx/reader036/viewer/2022062421/56649c755503460f94928fe6/html5/thumbnails/28.jpg)
Extended sizeof()
sizeof() on class members without an instance
Example:
class Bar {};
class Foo {public: Bar m_bar;};
sizeof(Foo::m_bar);
![Page 29: What's new in Microsoft Visual C++ 2015 Preview December 17 th 201 4 Marc Grégoire marc.gregoire@nuonsoft.com](https://reader036.vdocuments.mx/reader036/viewer/2022062421/56649c755503460f94928fe6/html5/thumbnails/29.jpg)
noexcept
Double meaning: noexcept to mark a function as non-throwing
void func1(); // Can throw anythingvoid func2() noexcept(expr); // A constant expression returning a Boolean
// true means func2 cannot throw // false means func2 can throw
void func3() noexcept; // = noexcept(true)
If a noexcept-marked function does throw at runtime, terminate() is called
Note that old exception specifications are deprecated since C++11
![Page 30: What's new in Microsoft Visual C++ 2015 Preview December 17 th 201 4 Marc Grégoire marc.gregoire@nuonsoft.com](https://reader036.vdocuments.mx/reader036/viewer/2022062421/56649c755503460f94928fe6/html5/thumbnails/30.jpg)
noexcept noexcept as an operator: noexcept(expr) Example:
bool b1 = noexcept(2 + 3); // b1 = truebool b2 = noexcept(throw 1); // b2 = false
void func1() { }bool b3 = noexcept(func1());
void func2() noexcept { }bool b4 = noexcept(func2()); // b4 = true
Used by the standard library to decide between moving or copying
Thus, mark your move ctor and move assignment operator noexcept
// b3 = false
![Page 31: What's new in Microsoft Visual C++ 2015 Preview December 17 th 201 4 Marc Grégoire marc.gregoire@nuonsoft.com](https://reader036.vdocuments.mx/reader036/viewer/2022062421/56649c755503460f94928fe6/html5/thumbnails/31.jpg)
Inline Namespace
Intended for libraries to support versioning Example:
// file V98.h:namespace V98 { void f(int); // does something}
// file V99.h:inline namespace V99 { void f(int); // does something better than the V98 version void f(double); // new feature}
// file MyLibrary.h:namespace MyLibrary { #include "V99.h" #include "V98.h"}
#include "MyLibrary.h"using namespace MyLibrary;
V98::f(1); // old versionV99::f(1); // new versionf(1); // default version
![Page 32: What's new in Microsoft Visual C++ 2015 Preview December 17 th 201 4 Marc Grégoire marc.gregoire@nuonsoft.com](https://reader036.vdocuments.mx/reader036/viewer/2022062421/56649c755503460f94928fe6/html5/thumbnails/32.jpg)
C++11 Core Language Concurrency Features
New or updated C++11 core language concurrency features quick_exit() and at_quick_exit() Full support for thread-local storage (partial in
VC++2013) Magic statics
![Page 33: What's new in Microsoft Visual C++ 2015 Preview December 17 th 201 4 Marc Grégoire marc.gregoire@nuonsoft.com](https://reader036.vdocuments.mx/reader036/viewer/2022062421/56649c755503460f94928fe6/html5/thumbnails/33.jpg)
quick_exit() and at_quick_exit()
quick_exit() terminates application as follows: Calls all functions registered with at_quick_exit() Terminates application
Except at_quick_exit() handlers, no other cleanup is done
No destructors are called
![Page 34: What's new in Microsoft Visual C++ 2015 Preview December 17 th 201 4 Marc Grégoire marc.gregoire@nuonsoft.com](https://reader036.vdocuments.mx/reader036/viewer/2022062421/56649c755503460f94928fe6/html5/thumbnails/34.jpg)
Thread-Local Storage
Keyword: thread_local Each thread gets its own instance Example:
thread_local unsigned int data = 1;
![Page 35: What's new in Microsoft Visual C++ 2015 Preview December 17 th 201 4 Marc Grégoire marc.gregoire@nuonsoft.com](https://reader036.vdocuments.mx/reader036/viewer/2022062421/56649c755503460f94928fe6/html5/thumbnails/35.jpg)
Magic Statics
Thread-safe “Magic” statics Static local variables are initialized in a
thread-safe way No manual synchronization needed for
initialization Using statics from multiple threads still
requires manual synchronization
![Page 36: What's new in Microsoft Visual C++ 2015 Preview December 17 th 201 4 Marc Grégoire marc.gregoire@nuonsoft.com](https://reader036.vdocuments.mx/reader036/viewer/2022062421/56649c755503460f94928fe6/html5/thumbnails/36.jpg)
Magic Statics
Example: simple thread-safe singleton:
static Singleton& GetInstance(){ static Singleton theInstance; return theInstance;}
![Page 37: What's new in Microsoft Visual C++ 2015 Preview December 17 th 201 4 Marc Grégoire marc.gregoire@nuonsoft.com](https://reader036.vdocuments.mx/reader036/viewer/2022062421/56649c755503460f94928fe6/html5/thumbnails/37.jpg)
C++11 Core Language C99 Features
New or updated C++11 core language C99 features __func__
![Page 38: What's new in Microsoft Visual C++ 2015 Preview December 17 th 201 4 Marc Grégoire marc.gregoire@nuonsoft.com](https://reader036.vdocuments.mx/reader036/viewer/2022062421/56649c755503460f94928fe6/html5/thumbnails/38.jpg)
__func__
Standard way to get the name of a function
int _tmain(int argc, _TCHAR* argv[]){ cout << __func__ << endl; return 0;}
Output:
wmain
![Page 39: What's new in Microsoft Visual C++ 2015 Preview December 17 th 201 4 Marc Grégoire marc.gregoire@nuonsoft.com](https://reader036.vdocuments.mx/reader036/viewer/2022062421/56649c755503460f94928fe6/html5/thumbnails/39.jpg)
C++14 Core Language Features
New or updated C++14 core language features Binary literals auto and decltype(auto) return types Lambda capture expressions Generic lambdas Digit separators (will be in RTM) Sized deallocation (partial support)
![Page 40: What's new in Microsoft Visual C++ 2015 Preview December 17 th 201 4 Marc Grégoire marc.gregoire@nuonsoft.com](https://reader036.vdocuments.mx/reader036/viewer/2022062421/56649c755503460f94928fe6/html5/thumbnails/40.jpg)
Binary Literals
int value = 0b1111011; // = 123
![Page 41: What's new in Microsoft Visual C++ 2015 Preview December 17 th 201 4 Marc Grégoire marc.gregoire@nuonsoft.com](https://reader036.vdocuments.mx/reader036/viewer/2022062421/56649c755503460f94928fe6/html5/thumbnails/41.jpg)
auto and decltype(auto) Return Types
Both auto and decltype(auto) can be used to let the compiler deduce the return type
auto strips ref-qualifiers (lvalue and rvalue references) and strips cv-qualifiers (const and volatile)
Decltype(auto) does not strip those
![Page 42: What's new in Microsoft Visual C++ 2015 Preview December 17 th 201 4 Marc Grégoire marc.gregoire@nuonsoft.com](https://reader036.vdocuments.mx/reader036/viewer/2022062421/56649c755503460f94928fe6/html5/thumbnails/42.jpg)
auto and decltype(auto) Return Types
Example: return type will be intauto Foo(int i){ return i + 1;}
Example: return type will be doubletemplate<typename T>auto Bar(const T& t){ return t * 2;}...auto result = Bar<double>(1.2);
![Page 43: What's new in Microsoft Visual C++ 2015 Preview December 17 th 201 4 Marc Grégoire marc.gregoire@nuonsoft.com](https://reader036.vdocuments.mx/reader036/viewer/2022062421/56649c755503460f94928fe6/html5/thumbnails/43.jpg)
auto and decltype(auto) Return Types
Multiple return statements are allowed but all need to be of exactly the same type
Following won’t compile returns int and unsigned int
auto Foo(int i){ if (i > 1) return 1; else return 2u;}
![Page 44: What's new in Microsoft Visual C++ 2015 Preview December 17 th 201 4 Marc Grégoire marc.gregoire@nuonsoft.com](https://reader036.vdocuments.mx/reader036/viewer/2022062421/56649c755503460f94928fe6/html5/thumbnails/44.jpg)
auto and decltype(auto) Return Types
Recursion allowed but there must be a non-recursive return before the recursive call
Correct:auto Foo(int i){ if (i == 0) return 0; else return i + Foo(i - 1);}
Wrong:auto Foo(int i){ if (i > 0) return i + Foo(i - 1); else return 0;}
![Page 45: What's new in Microsoft Visual C++ 2015 Preview December 17 th 201 4 Marc Grégoire marc.gregoire@nuonsoft.com](https://reader036.vdocuments.mx/reader036/viewer/2022062421/56649c755503460f94928fe6/html5/thumbnails/45.jpg)
decltype(auto)
Quick reminder:static const string message = "Test";
const string& Foo(){ return message;}
...
auto f1 = Foo();decltype(Foo()) f2 = Foo();decltype(auto) f3 = Foo();
Type: string Type: const string& Type: const string&
![Page 46: What's new in Microsoft Visual C++ 2015 Preview December 17 th 201 4 Marc Grégoire marc.gregoire@nuonsoft.com](https://reader036.vdocuments.mx/reader036/viewer/2022062421/56649c755503460f94928fe6/html5/thumbnails/46.jpg)
auto and decltype(auto) Return Types
decltype(auto) as return type Example:
auto Foo1(const string& str){ return str;}
Return Type: string Return Type: const string&
decltype(auto) Foo2(const string& str){ return str;}
decltype(auto) a = Foo1("abc");decltype(auto) b = Foo2("abc");
![Page 47: What's new in Microsoft Visual C++ 2015 Preview December 17 th 201 4 Marc Grégoire marc.gregoire@nuonsoft.com](https://reader036.vdocuments.mx/reader036/viewer/2022062421/56649c755503460f94928fe6/html5/thumbnails/47.jpg)
Lambda Capture Expressions
Capture expressions to initialize lambda variables
Example:float pi = 3.1415;auto myLambda = [myCapture = "Pi: ", pi]{ std::cout << myCapture << pi; };
Lambda has 2 variables: myCapture: a string (not from the enclosing scope)
with value “Pi: “ pi: captured from the enclosing scope
![Page 48: What's new in Microsoft Visual C++ 2015 Preview December 17 th 201 4 Marc Grégoire marc.gregoire@nuonsoft.com](https://reader036.vdocuments.mx/reader036/viewer/2022062421/56649c755503460f94928fe6/html5/thumbnails/48.jpg)
Lambda Capture Expressions
Allow moving variables into the lambda Example:
auto myPtr = std::make_unique<double>(3.1415);auto myLambda = [p = std::move(myPtr)]{ std::cout << *p; };
Lambda has 1 variable: p: a unique_ptr captured and moved from the
enclosing scope (could even be called myPtr)
![Page 49: What's new in Microsoft Visual C++ 2015 Preview December 17 th 201 4 Marc Grégoire marc.gregoire@nuonsoft.com](https://reader036.vdocuments.mx/reader036/viewer/2022062421/56649c755503460f94928fe6/html5/thumbnails/49.jpg)
Generic Lambdas
Lambda parameters can be declared as auto auto doubler = [](const auto& value){ return value * 2; };
...
vector<int> v1{ 1, 2, 3 };transform(begin(v1), end(v1), begin(v1), doubler);
...
vector<double> v2{ 1.1, 2.2, 3.3 };transform(begin(v2), end(v2), begin(v2), doubler);
![Page 50: What's new in Microsoft Visual C++ 2015 Preview December 17 th 201 4 Marc Grégoire marc.gregoire@nuonsoft.com](https://reader036.vdocuments.mx/reader036/viewer/2022062421/56649c755503460f94928fe6/html5/thumbnails/50.jpg)
Digit Separators (will be in RTM)
Single quote character Example:
int number1 = 23'456'789; // The number 23456789
float number2 = 0.123'456f; // The number 0.123456
![Page 51: What's new in Microsoft Visual C++ 2015 Preview December 17 th 201 4 Marc Grégoire marc.gregoire@nuonsoft.com](https://reader036.vdocuments.mx/reader036/viewer/2022062421/56649c755503460f94928fe6/html5/thumbnails/51.jpg)
C++14 Library Features New or updated C++14 library features
Standard user-defined literals Null forward iterators quoted() Heterogeneous associative lookup Compile-time integer sequences exchange() Dual-range equal(), is_permutation(), mismatch() get<T>() tuple_element_t
![Page 52: What's new in Microsoft Visual C++ 2015 Preview December 17 th 201 4 Marc Grégoire marc.gregoire@nuonsoft.com](https://reader036.vdocuments.mx/reader036/viewer/2022062421/56649c755503460f94928fe6/html5/thumbnails/52.jpg)
Standard User-Defined literals “s” for creating std::strings
auto myString = "Hello World"s; “h”, “min”, “s”, “ms”, “us”, “ns”, for creating
std::chrono::duration time intervals auto myDuration = 42min;
“i”, “il”, “if” for creating complex numbers complex<double>, complex<long double>, and complex<float> respectively auto myComplexNumber = 1.3i;
![Page 53: What's new in Microsoft Visual C++ 2015 Preview December 17 th 201 4 Marc Grégoire marc.gregoire@nuonsoft.com](https://reader036.vdocuments.mx/reader036/viewer/2022062421/56649c755503460f94928fe6/html5/thumbnails/53.jpg)
C++17 Core Language Features
New or updated C++17 core language features Removing trigraphs Resumable functions (proposal for C++17)
![Page 54: What's new in Microsoft Visual C++ 2015 Preview December 17 th 201 4 Marc Grégoire marc.gregoire@nuonsoft.com](https://reader036.vdocuments.mx/reader036/viewer/2022062421/56649c755503460f94928fe6/html5/thumbnails/54.jpg)
Removing Trigraphs
Trigraph = sequence of 3 characters
TrigraphPunctuation Character
??= #
??( [
??/ \
??) ]
??' ^
??< {
??! |
??> }
??- ~
![Page 55: What's new in Microsoft Visual C++ 2015 Preview December 17 th 201 4 Marc Grégoire marc.gregoire@nuonsoft.com](https://reader036.vdocuments.mx/reader036/viewer/2022062421/56649c755503460f94928fe6/html5/thumbnails/55.jpg)
Resumable Functions (proposal for C++17)
Based on concept of coroutines Coroutine is a generalized routine supporting:
Invoke Return Suspend Resume
![Page 56: What's new in Microsoft Visual C++ 2015 Preview December 17 th 201 4 Marc Grégoire marc.gregoire@nuonsoft.com](https://reader036.vdocuments.mx/reader036/viewer/2022062421/56649c755503460f94928fe6/html5/thumbnails/56.jpg)
Resumable Functions (proposal for C++17)
Visual C++ 2015 Preview resumable functions restrictions 64-bit targets only Manually add /await compiler switch Manually disable /RTC1 (run-time error checks) Manually disable /sdl (additional security
checks) Currently in <experimental\resumable>
![Page 57: What's new in Microsoft Visual C++ 2015 Preview December 17 th 201 4 Marc Grégoire marc.gregoire@nuonsoft.com](https://reader036.vdocuments.mx/reader036/viewer/2022062421/56649c755503460f94928fe6/html5/thumbnails/57.jpg)
Resumable Functions – Async Operations
future<int> calculate_the_answer() // This could be some long running computation or I/O{ return async([] { this_thread::sleep_for(3s); return 42; });}
future<void> coro() // A resumable function{ cout << "coro() starting to wait for the answer..." << endl; auto result = __await calculate_the_answer(); cout << "got answer " << result << endl;}
int main(){ auto fut = coro(); cout << "main() is writing something" << endl; fut.get(); // Before exiting, let's wait on our asynchronous coro() call to finish. return 0;}
coro() starting to wait for the answer...
main() is writing something
got answer 42
23
6/5
14
5/6
![Page 58: What's new in Microsoft Visual C++ 2015 Preview December 17 th 201 4 Marc Grégoire marc.gregoire@nuonsoft.com](https://reader036.vdocuments.mx/reader036/viewer/2022062421/56649c755503460f94928fe6/html5/thumbnails/58.jpg)
Resumable Functions – Generator Pattern
#include <experimental\resumable>#include <experimental\generator>
using namespace std;using namespace std::experimental;
generator<int> fib(){ int a = 0; int b = 1; for (;;) { __yield_value a; auto next = a + b; a = b; b = next; }}
int main(){ for (auto v : fib()) { if (v > 50) { break; } cout << v << endl; }}
0
1
1
2
3
5
8
13
21
34
![Page 59: What's new in Microsoft Visual C++ 2015 Preview December 17 th 201 4 Marc Grégoire marc.gregoire@nuonsoft.com](https://reader036.vdocuments.mx/reader036/viewer/2022062421/56649c755503460f94928fe6/html5/thumbnails/59.jpg)
TS Library Features
New or updated Technical Specification library features File system “V3”
![Page 60: What's new in Microsoft Visual C++ 2015 Preview December 17 th 201 4 Marc Grégoire marc.gregoire@nuonsoft.com](https://reader036.vdocuments.mx/reader036/viewer/2022062421/56649c755503460f94928fe6/html5/thumbnails/60.jpg)
Productivity ImprovementsEnhanced productivity & build-time
improvements
![Page 61: What's new in Microsoft Visual C++ 2015 Preview December 17 th 201 4 Marc Grégoire marc.gregoire@nuonsoft.com](https://reader036.vdocuments.mx/reader036/viewer/2022062421/56649c755503460f94928fe6/html5/thumbnails/61.jpg)
Productivity & Build-Time Improvements
Improved IntelliSense database buildup Incremental linking with LTCG enabled Incremental linking for static libraries
Changes to static libraries referenced by other code modules now link incrementally
New fast PDB generation techniques: /Debug:FastLink Substantially decreases link times
Object file size reduction Multithreading in the linker New Visual Studio Graphics Analyzer (VSGA)
![Page 62: What's new in Microsoft Visual C++ 2015 Preview December 17 th 201 4 Marc Grégoire marc.gregoire@nuonsoft.com](https://reader036.vdocuments.mx/reader036/viewer/2022062421/56649c755503460f94928fe6/html5/thumbnails/62.jpg)
Productivity Improvements
Simplified QuickInfo for template deduction
VC++2013
VC++2015
![Page 63: What's new in Microsoft Visual C++ 2015 Preview December 17 th 201 4 Marc Grégoire marc.gregoire@nuonsoft.com](https://reader036.vdocuments.mx/reader036/viewer/2022062421/56649c755503460f94928fe6/html5/thumbnails/63.jpg)
New Refactorings
Rename symbol Implement pure virtuals Create declaration or definition Move function definition Convert to raw string literal Extract function (available from Visual Studio
Gallery)
![Page 64: What's new in Microsoft Visual C++ 2015 Preview December 17 th 201 4 Marc Grégoire marc.gregoire@nuonsoft.com](https://reader036.vdocuments.mx/reader036/viewer/2022062421/56649c755503460f94928fe6/html5/thumbnails/64.jpg)
Demo
New Refactorings
![Page 65: What's new in Microsoft Visual C++ 2015 Preview December 17 th 201 4 Marc Grégoire marc.gregoire@nuonsoft.com](https://reader036.vdocuments.mx/reader036/viewer/2022062421/56649c755503460f94928fe6/html5/thumbnails/65.jpg)
Improved Performance
![Page 66: What's new in Microsoft Visual C++ 2015 Preview December 17 th 201 4 Marc Grégoire marc.gregoire@nuonsoft.com](https://reader036.vdocuments.mx/reader036/viewer/2022062421/56649c755503460f94928fe6/html5/thumbnails/66.jpg)
Improved Performance Improvements to automatic vectorization
Vectorization of control flow (if-then-else) Vectorization with /O1 (minimize size) enabled Vectorizing more range-based for loops
Improvements to scalar optimizations Better code gen of bit-test operations Control flow merging and optimizations (loop-if switching) Better code gen for std::min and std:max
ARM32 code generation improvements
![Page 67: What's new in Microsoft Visual C++ 2015 Preview December 17 th 201 4 Marc Grégoire marc.gregoire@nuonsoft.com](https://reader036.vdocuments.mx/reader036/viewer/2022062421/56649c755503460f94928fe6/html5/thumbnails/67.jpg)
C++ Cross-Platform Mobile Dev
![Page 68: What's new in Microsoft Visual C++ 2015 Preview December 17 th 201 4 Marc Grégoire marc.gregoire@nuonsoft.com](https://reader036.vdocuments.mx/reader036/viewer/2022062421/56649c755503460f94928fe6/html5/thumbnails/68.jpg)
C++ Cross-Platform Mobile Dev
VC++ 2015 Preview has 2 compilers: VC++ compiler to target Windows platforms Clang to target Android (iOS coming in the near
future) Android support:
Build C++ dynamic shared libs and static libs Libs are consumed with Java, Xamarin , …
Build Native-Activity apps, pure C++
![Page 69: What's new in Microsoft Visual C++ 2015 Preview December 17 th 201 4 Marc Grégoire marc.gregoire@nuonsoft.com](https://reader036.vdocuments.mx/reader036/viewer/2022062421/56649c755503460f94928fe6/html5/thumbnails/69.jpg)
Demo
Android Native-Activity App
![Page 70: What's new in Microsoft Visual C++ 2015 Preview December 17 th 201 4 Marc Grégoire marc.gregoire@nuonsoft.com](https://reader036.vdocuments.mx/reader036/viewer/2022062421/56649c755503460f94928fe6/html5/thumbnails/70.jpg)
Questions
?