C++11 introduced several new features for functions and lambdas including:
1. Lambda expressions that allow the definition of anonymous inline functions.
2. The std::function wrapper that allows functions and lambdas to be used interchangeably.
3. std::bind that binds arguments to function parameters for creating function objects.
These features improved support for functional programming patterns in C++.
This presentation was held at the Stockholm Rust Meetup in September 2019.
This is a brief introduction to Rust and highlights some of the problems with C++ that it attempts to solve. It also contain a brief introduction to the ownership model and the borrow checker that Rust uses.
Video and slides synchronized, mp3 and slide download available at URL http://bit.ly/28XnVtb.
Felix Klock describe the core concepts of the Rust language (ownership, borrowing, and lifetimes), as well as the tools beyond the compiler for open source software component distribution (cargo, crates.io). Filmed at qconlondon.com.
Felix Klock is a research engineer at Mozilla, where he works on the Rust compiler, runtime libraries, and language design. He previously worked on the ActionScript Virtual Machine for the Adobe Flash runtime. Klock is one of the developers of the Larceny Scheme language runtime.
This presentation was held at the Stockholm Rust Meetup in September 2019.
This is a brief introduction to Rust and highlights some of the problems with C++ that it attempts to solve. It also contain a brief introduction to the ownership model and the borrow checker that Rust uses.
Video and slides synchronized, mp3 and slide download available at URL http://bit.ly/28XnVtb.
Felix Klock describe the core concepts of the Rust language (ownership, borrowing, and lifetimes), as well as the tools beyond the compiler for open source software component distribution (cargo, crates.io). Filmed at qconlondon.com.
Felix Klock is a research engineer at Mozilla, where he works on the Rust compiler, runtime libraries, and language design. He previously worked on the ActionScript Virtual Machine for the Adobe Flash runtime. Klock is one of the developers of the Larceny Scheme language runtime.
Bien que Docker soit facile d'utilisation, construire une image reste un exercice compliqué.
Optimisation, layers, et sécurité nécessitent de s'abstraire des Dockerfile basiques qu'on peut trouver sur internet.
Dans ce BBL, nous verrons comment bien packager une application Spring Boot dans une image Docker/OCI.
Nous allons parcourir les bonnes pratiques préconisées par Spring, les pièges à éviter, comment bien écrire un Dockerfile pour optimiser la construction et l'image finale pour une exécution dans Kubernetes et nous verrons aussi des moyens alternatifs de construction d'images Spring Boot et l'outillage d'analyse à ajouter à votre toolbox.
An introduction to Rust: the modern programming language to develop safe and ...Claudio Capobianco
Rust is a young programming language developed by Mozilla with the open source community support. According to a survey of StackOverflow, in 2016 was the most loved among developers language! The goal of Rust is to combine control and performances, that is, operate at low level with high-level constructs. The actual applications vary from operating system to web development. Rust natively includes tools for Agile development, such as dependency management, testing and much more. The gap with other popular languages is filling up quickly thanks to the community, very active and fantastic :)
In this introductory presentation we will discuss the characteristics that make Rust unique, including the concepts of Ownership, Borrowing, and Lifetimes.
These slide has be presented for a talk in BIC Lazio Casilina, that has been also the first meetup of Rust Rome!
The new standard for C++ language has been signed in 2011. This new (extended) language, called C++11, has a number of new semantics (in terms of language constructs) and a number of new standard library support. The major language extensions are discussed in this presentation. The library will be taken up in a later presentation.
Often called as the Swiss Army Knife of Embedded Linux, BusyBox combines tiny versions of many common UNIX utilities into a single small executable. It provides replacements for most of the utilities you usually find in GNU fileutils, shellutils, etc. It is written with size-optimization
and limited resources in mind. Here is a presentation that details about BusyBox.
Build a full-functioned virtual machine from scratch, when Brainfuck is used. Basic concepts about interpreter, optimizations techniques, language specialization, and platform specific tweaks.
Bien que Docker soit facile d'utilisation, construire une image reste un exercice compliqué.
Optimisation, layers, et sécurité nécessitent de s'abstraire des Dockerfile basiques qu'on peut trouver sur internet.
Dans ce BBL, nous verrons comment bien packager une application Spring Boot dans une image Docker/OCI.
Nous allons parcourir les bonnes pratiques préconisées par Spring, les pièges à éviter, comment bien écrire un Dockerfile pour optimiser la construction et l'image finale pour une exécution dans Kubernetes et nous verrons aussi des moyens alternatifs de construction d'images Spring Boot et l'outillage d'analyse à ajouter à votre toolbox.
An introduction to Rust: the modern programming language to develop safe and ...Claudio Capobianco
Rust is a young programming language developed by Mozilla with the open source community support. According to a survey of StackOverflow, in 2016 was the most loved among developers language! The goal of Rust is to combine control and performances, that is, operate at low level with high-level constructs. The actual applications vary from operating system to web development. Rust natively includes tools for Agile development, such as dependency management, testing and much more. The gap with other popular languages is filling up quickly thanks to the community, very active and fantastic :)
In this introductory presentation we will discuss the characteristics that make Rust unique, including the concepts of Ownership, Borrowing, and Lifetimes.
These slide has be presented for a talk in BIC Lazio Casilina, that has been also the first meetup of Rust Rome!
The new standard for C++ language has been signed in 2011. This new (extended) language, called C++11, has a number of new semantics (in terms of language constructs) and a number of new standard library support. The major language extensions are discussed in this presentation. The library will be taken up in a later presentation.
Often called as the Swiss Army Knife of Embedded Linux, BusyBox combines tiny versions of many common UNIX utilities into a single small executable. It provides replacements for most of the utilities you usually find in GNU fileutils, shellutils, etc. It is written with size-optimization
and limited resources in mind. Here is a presentation that details about BusyBox.
Build a full-functioned virtual machine from scratch, when Brainfuck is used. Basic concepts about interpreter, optimizations techniques, language specialization, and platform specific tweaks.
Basic c++ 11/14 for python programmersJen Yee Hong
A short list of some common python programming patterns and their C++ equivalents. This can help programmers learn C++ in a more efficient way if he or she already knows Python.
Part of this material is used for internal training of Appier Inc, one of the leading artificial intelligence company in Asia.
Thank Appier Inc. for allowing me to share this.
Our new blog post featuring some common python programming patterns and their C++ equivalents is now up!
Leave us a comment below and let us know what you'd like to see covered in our future posts!
█ Read More
Technical Insights: Introduction to GraphQL|goo.gl/d7PyXH
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Jeffrey Haguewood
Sidekick Solutions uses Bonterra Impact Management (fka Social Solutions Apricot) and automation solutions to integrate data for business workflows.
We believe integration and automation are essential to user experience and the promise of efficient work through technology. Automation is the critical ingredient to realizing that full vision. We develop integration products and services for Bonterra Case Management software to support the deployment of automations for a variety of use cases.
This video focuses on the notifications, alerts, and approval requests using Slack for Bonterra Impact Management. The solutions covered in this webinar can also be deployed for Microsoft Teams.
Interested in deploying notification automations for Bonterra Impact Management? Contact us at sales@sidekicksolutionsllc.com to discuss next steps.
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Ramesh Iyer
In today's fast-changing business world, Companies that adapt and embrace new ideas often need help to keep up with the competition. However, fostering a culture of innovation takes much work. It takes vision, leadership and willingness to take risks in the right proportion. Sachin Dev Duggal, co-founder of Builder.ai, has perfected the art of this balance, creating a company culture where creativity and growth are nurtured at each stage.
State of ICS and IoT Cyber Threat Landscape Report 2024 previewPrayukth K V
The IoT and OT threat landscape report has been prepared by the Threat Research Team at Sectrio using data from Sectrio, cyber threat intelligence farming facilities spread across over 85 cities around the world. In addition, Sectrio also runs AI-based advanced threat and payload engagement facilities that serve as sinks to attract and engage sophisticated threat actors, and newer malware including new variants and latent threats that are at an earlier stage of development.
The latest edition of the OT/ICS and IoT security Threat Landscape Report 2024 also covers:
State of global ICS asset and network exposure
Sectoral targets and attacks as well as the cost of ransom
Global APT activity, AI usage, actor and tactic profiles, and implications
Rise in volumes of AI-powered cyberattacks
Major cyber events in 2024
Malware and malicious payload trends
Cyberattack types and targets
Vulnerability exploit attempts on CVEs
Attacks on counties – USA
Expansion of bot farms – how, where, and why
In-depth analysis of the cyber threat landscape across North America, South America, Europe, APAC, and the Middle East
Why are attacks on smart factories rising?
Cyber risk predictions
Axis of attacks – Europe
Systemic attacks in the Middle East
Download the full report from here:
https://sectrio.com/resources/ot-threat-landscape-reports/sectrio-releases-ot-ics-and-iot-security-threat-landscape-report-2024/
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...DanBrown980551
Do you want to learn how to model and simulate an electrical network from scratch in under an hour?
Then welcome to this PowSyBl workshop, hosted by Rte, the French Transmission System Operator (TSO)!
During the webinar, you will discover the PowSyBl ecosystem as well as handle and study an electrical network through an interactive Python notebook.
PowSyBl is an open source project hosted by LF Energy, which offers a comprehensive set of features for electrical grid modelling and simulation. Among other advanced features, PowSyBl provides:
- A fully editable and extendable library for grid component modelling;
- Visualization tools to display your network;
- Grid simulation tools, such as power flows, security analyses (with or without remedial actions) and sensitivity analyses;
The framework is mostly written in Java, with a Python binding so that Python developers can access PowSyBl functionalities as well.
What you will learn during the webinar:
- For beginners: discover PowSyBl's functionalities through a quick general presentation and the notebook, without needing any expert coding skills;
- For advanced developers: master the skills to efficiently apply PowSyBl functionalities to your real-world scenarios.
UiPath Test Automation using UiPath Test Suite series, part 3DianaGray10
Welcome to UiPath Test Automation using UiPath Test Suite series part 3. In this session, we will cover desktop automation along with UI automation.
Topics covered:
UI automation Introduction,
UI automation Sample
Desktop automation flow
Pradeep Chinnala, Senior Consultant Automation Developer @WonderBotz and UiPath MVP
Deepak Rai, Automation Practice Lead, Boundaryless Group and UiPath MVP
Securing your Kubernetes cluster_ a step-by-step guide to success !KatiaHIMEUR1
Today, after several years of existence, an extremely active community and an ultra-dynamic ecosystem, Kubernetes has established itself as the de facto standard in container orchestration. Thanks to a wide range of managed services, it has never been so easy to set up a ready-to-use Kubernetes cluster.
However, this ease of use means that the subject of security in Kubernetes is often left for later, or even neglected. This exposes companies to significant risks.
In this talk, I'll show you step-by-step how to secure your Kubernetes cluster for greater peace of mind and reliability.
DevOps and Testing slides at DASA ConnectKari Kakkonen
My and Rik Marselis slides at 30.5.2024 DASA Connect conference. We discuss about what is testing, then what is agile testing and finally what is Testing in DevOps. Finally we had lovely workshop with the participants trying to find out different ways to think about quality and testing in different parts of the DevOps infinity loop.
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...UiPathCommunity
💥 Speed, accuracy, and scaling – discover the superpowers of GenAI in action with UiPath Document Understanding and Communications Mining™:
See how to accelerate model training and optimize model performance with active learning
Learn about the latest enhancements to out-of-the-box document processing – with little to no training required
Get an exclusive demo of the new family of UiPath LLMs – GenAI models specialized for processing different types of documents and messages
This is a hands-on session specifically designed for automation developers and AI enthusiasts seeking to enhance their knowledge in leveraging the latest intelligent document processing capabilities offered by UiPath.
Speakers:
👨🏫 Andras Palfi, Senior Product Manager, UiPath
👩🏫 Lenka Dulovicova, Product Program Manager, UiPath
Connector Corner: Automate dynamic content and events by pushing a buttonDianaGray10
Here is something new! In our next Connector Corner webinar, we will demonstrate how you can use a single workflow to:
Create a campaign using Mailchimp with merge tags/fields
Send an interactive Slack channel message (using buttons)
Have the message received by managers and peers along with a test email for review
But there’s more:
In a second workflow supporting the same use case, you’ll see:
Your campaign sent to target colleagues for approval
If the “Approve” button is clicked, a Jira/Zendesk ticket is created for the marketing design team
But—if the “Reject” button is pushed, colleagues will be alerted via Slack message
Join us to learn more about this new, human-in-the-loop capability, brought to you by Integration Service connectors.
And...
Speakers:
Akshay Agnihotri, Product Manager
Charlie Greenberg, Host
Key Trends Shaping the Future of Infrastructure.pdfCheryl Hung
Keynote at DIGIT West Expo, Glasgow on 29 May 2024.
Cheryl Hung, ochery.com
Sr Director, Infrastructure Ecosystem, Arm.
The key trends across hardware, cloud and open-source; exploring how these areas are likely to mature and develop over the short and long-term, and then considering how organisations can position themselves to adapt and thrive.
Neuro-symbolic is not enough, we need neuro-*semantic*Frank van Harmelen
Neuro-symbolic (NeSy) AI is on the rise. However, simply machine learning on just any symbolic structure is not sufficient to really harvest the gains of NeSy. These will only be gained when the symbolic structures have an actual semantics. I give an operational definition of semantics as “predictable inference”.
All of this illustrated with link prediction over knowledge graphs, but the argument is general.
Transcript: Selling digital books in 2024: Insights from industry leaders - T...BookNet Canada
The publishing industry has been selling digital audiobooks and ebooks for over a decade and has found its groove. What’s changed? What has stayed the same? Where do we go from here? Join a group of leading sales peers from across the industry for a conversation about the lessons learned since the popularization of digital books, best practices, digital book supply chain management, and more.
Link to video recording: https://bnctechforum.ca/sessions/selling-digital-books-in-2024-insights-from-industry-leaders/
Presented by BookNet Canada on May 28, 2024, with support from the Department of Canadian Heritage.
6. raw string literals
C++03 C++11
string test="C:ABCDfile1.txt"; string test=R"(C:ABCDfile1.txt)";
cout << test << endl; cout << test << endl;
C:ABCDfile1.txt C:ABCDfile1.txt
string test; string test;
test = "First Line.nSecond line.nThird Line.n"; test = R"(First Line.nSecond line.nThird Line.n)";
cout << test << endl; cout << test << endl;
First Line. First Line.nSecond line.nThird Line.n
Second line.
Third Line.
string test =
R"(First Line.
Second line.
Third Line.)";
cout << test << endl;
First Line.
Second line.
Third Line.
7. in-class member initializers
C++03 C++11
class A class A
{ {
public: public:
A(): a(4), b(2), A() {}
h("text1"), s("text2") {} A(int in_a) : a(in_a) {}
A(int in_a) : a(in_a), b(2), A(C c) {}
h("text1"), s("text2") {} private:
A(C c) : a(4), b(2), int a = 4;
h("text1"), s("text2") {} int b = 2;
private: string h = "text1";
int a; string s = "text2";
int b; };
string h;
string s;
};
8. delegating constructors
C++03 C++11
class A class A
{ {
int a; int a;
public:
void validate(int x)
A(int x)
{ {
if (0<x && x<=42) a=x; else throw bad_A(x); if (0<x && x<=42) a=x; else throw bad_A(x);
} }
public: A() : A(42){ }
A(int x) { validate(x); } A(string s) : A(stoi(s)){ }
A() { validate(42); } };
A(string s)
{
int x = stoi(s);
validate(x);
}
};
9. override
C++03 C++11
struct Base struct Base
{ {
virtual void some_func(float); virtual void some_func(float);
}; };
struct Derived : Base struct Derived : Base
{ {
virtual void some_func(int); void some_func(int) override;
//warning //error
}; };
10. final
C++11 Java
struct Base1 final {}; final class Base1 {}
struct Derived1 : Base1{ class Derived1 extends Base1 {
//error //error
}; }
struct Base2{ class Base2 {
virtual void f() final; public final void f(){};
}; }
struct Derived2 : Base2 { class Derived2 extends Base2 {
void f(); //error public void f(){}; //error
}; }
11. static_assert
C++11
template<class T>
void f(T v){
static_assert(sizeof(v) == 4, “v must have size of 4 bytes");
//do something with v
}
void g(){
int64_t v; // 8 bytes
f(v);
}
vs2010/2012 output:
1>d:main.cpp(5): error C2338: v must have size of 4 bytes
13. auto
C++03 C++11
map<string,string>::iterator it = m.begin(); auto it = m.begin();
double const param = config["param"]; auto const param = config["param"];
singleton& s = singleton::instance(); auto& s = singleton::instance();
Prefer using auto in the following cases:
auto p = new T();
Here is T in the expression. No need to repeat it again.
auto p = make_shared<T>(arg1);
The same as above.
auto my_lambda = [](){};
If you need to store lambda you may use auto or std::function
auto it = m.begin();
Instead of: map<string,list<int>::iterator>::const_iterator it = m.cbegin();
http://programmers.stackexchange.com/questions/180216/does-auto-make-c-code-harder-to-
understand
14. decltype
C++11 C++11
int main(){ int main(){
int i = 4; int i = 4;
const int j = 6; const int j = 6;
const int& k = i; const int& k = i;
int a[5]; int a[5];
int *p; int *p;
//decltype is an operator for querying the type of an expression.
//similarly to the sizeof operator, the operand of decltype is unevaluated.
int var1; decltype(i) var1;
int var2; decltype(1) var2;
int var3; decltype(2+3) var3;
int& var4 = i; decltype(i=1) var4 = i; //there is no assignment i to 1
// // i == 4 as before
const int var5 = 1; decltype(j) var5 = 1;
const int& var6 = j; decltype(k) var6 = j;
int var7[5]; decltype(a) var7;
int& var8 = i; decltype(a[3]) var8 = i;
int& var9 = i; decltype(*p) var9 = i;
return 0; return 0;
} }
15. suffix return type syntax
C++11
template<class T, class U>
??? add(T x, U y)
//return type???
{
return x+y;
}
16. suffix return type syntax
C++11
template<class T, class U> template<class T, class U>
??? add(T x, U y) decltype(x+y) add(T x, U y)
//return type??? //scope problem
{ {
return x+y; return x+y;
} }
17. suffix return type syntax
C++11
template<class T, class U> template<class T, class U>
??? add(T x, U y) decltype(x+y) add(T x, U y)
//return type??? //scope problem
{ {
return x+y; return x+y;
} }
template<class T, class U>
decltype(*(T*)(0)+*(U*)(0)) add(T x, U y)
// ugly!
{
return x+y;
}
18. suffix return type syntax
C++11
template<class T, class U> template<class T, class U>
??? add(T x, U y) decltype(x+y) add(T x, U y)
//return type??? //scope problem
{ {
return x+y; return x+y;
} }
template<class T, class U> template<class T, class U>
decltype(*(T*)(0)+*(U*)(0)) add(T x, U y) auto add(T x, U y) -> decltype(x+y)
// ugly! {
{ return x+y;
return x+y; }
}
33. std::initializer_list
C++11
vector<int> v = { 1, 2, 3, 4, 5 }; //How to make this works?
vector<int> v = { 1, 2, 3, 4, 5 }; template<class T>
//vector(initializer_list<T> args) is called class vector{
vector(initializer_list<T> args)
{ /*rude, naive implementation to show how ctor
with initiailizer_list works*/
for(auto it = begin(args); it != end(args); ++it)
push_back(*it);
}
//…
};
//what is initializer_list<T> ? initializer_list<T> is a lightweight proxy object that
provides access to an array of objects of type T.
A std::initializer_list object is automatically
constructed when:
vector<int> v{1,2,3,4,5};//list-initialization
v = {1,2,3,4,5};//assignment expression
f({1,2,3,4,5});//function call
for (int x : {1, 2, 3})//ranged for loop
cout << x << endl;
34. Uniform Initialization
C++11
//but wait!!! How then does this work?? The answer is:
struct Vector3{ now you can use {} instead of ()
float x,y,z; But what about following case:
Vector3(float _x, float _y, float _z) struct T {
: x(_x), y(_y), z(_z){} T(int,int);
//I don’t see ctor with std::initializer_list! T(initializer_list<int>);
};
};
T foo {10,20}; // calls initializer_list ctor
Vector3 normalize(const Vector3& v){ T bar (10,20); // calls first constructor
float inv_len = 1.f/ length(v);
return {v.x*inv_len, v.y*inv_len, v.z*inv_len}; Initializer-list constructors take precedence over other
} constructors when the initializer-list constructor syntax is
used!
Vector3 x = normalize({2,5,9}); So, be careful! Consider following example:
Vector3 y{4,2,1};
vector<int> v(5); // v contains five elements {0,0,0,0,0}
vector<int> v{5}; // v contains one element {5}
35. Uniform Initialization
C++11
Uniform initialization solves many problems:
Narrowing
int x = 6.3; //warning!
int y {6.3}; //error: narrowing
int z = {6.3}; //error: narrowing
vector<int> v = { 1, 4.3, 4, 0.6 }; //error: double to int narrowing
“The most vexing parse” problem
struct B{ struct B{
B(){} B(){}
}; };
struct A{ struct A{
A(B){} A(B){}
void f(){} void f(){}
}; };
int main(){ int main(){
A a(B()); //this is function declaration! A a{B()}; //calls B ctor, then A ctor. Everything is ok.
a.f(); //compile error! a.f(); //calls A::f
return 0; return 0;
} }
36. Uniform Initialization and
std::initializer_list
// Don’t mix std::initializer_list with auto
int n;
auto w(n); // int
auto x = n; // int
auto y {n}; // std::initializer_list<int>
auto z = {n}; // std::initializer_list<int>
37. using
C++03
typedef int int32_t; // on windows
typedef void (*Fn)(double);
template <int U, int V> class Type;
typedef Type<42,36> ConcreteType;
template<int V> template<int V>
typedef Type<42,V> MyType; struct meta_type{
//error: not legal C++ code typedef Type<42, V> type;
};
MyType<36> object; typedef meta_type<36>::type MyType;
MyType object;
38. using
C++03 C++11
typedef int int32_t; // on windows using int32_t = int; // on windows
typedef void (*Fn)(double); using Fn = void (*)(double);
template <int U, int V> class Type; template <int U, int V> class Type;
typedef Type<42,36> ConcreteType; using ConcreteType = Type<42,36>;
template<int V> template <int V>
struct meta_type{ using MyType = Type<42, V>;
typedef Type<42, V> type;
};
typedef meta_type<36>::type MyType;
MyType object; MyType<36> object;
41. explicit conversion operators
C++03 C++11
struct A { struct A {
A(int) {} A(int) {}
}; };
struct B { struct B {
int m; int m;
B(int x) : m(x) {} B(int x) : m(x) {}
operator A() { return A(m); } explicit operator A() { return A(m); }
}; };
void f(A){} void f(A){}
int main(){ int main(){
B b(1); B b(1);
A a = b; //silent implicit cast! A a = b; //error: implicit cast!
f(b); //silent implicit cast! f(b); //error: implicit cast!
return 0; return 0;
} }
42. explicit conversion operators
C++03 C++11
struct A { struct A {
A(int) {} A(int) {}
}; };
struct B { struct B {
int m; int m;
B(int x) : m(x) {} B(int x) : m(x) {}
operator A() { return A(m); } explicit operator A() { return A(m); }
}; };
void f(A){} void f(A){}
int main(){ int main(){
B b(1); B b(1);
A a = b; //silent implicit cast! A a = static_cast<A>(b);
f(b); //silent implicit cast! f(static_cast<A>(b));
return 0; return 0;
} }
43. control of defaults: default and delete
C++11
class A
{
A& operator=(A) = delete; // disallow copying
A(const A&) = delete;
};
struct B
{
B(float); // can initialize with a float
B(long) = delete; // but not with long
};
struct C
{
virtual ~C() = default;
};
44. enum class - scoped and strongly
typed enums
C++03 C++11
enum Alert { green, yellow, red }; enum class Alert { green, yellow, red };
//enum Color{ red, blue }; enum class Color : int{ red, blue };
//error C2365: 'red' : redefinition
Alert a = 7; // error (as ever in C++)
Alert a = 7; // error (as ever in C++) Color c = 7; // error: no int->Color conversion
int a2 = red; // ok: Alert->int conversion int a2 = red; // error
int a3 = Alert::red; // error int a3 = Alert::red; //error
int a4 = blue; // error: blue not in scope
int a5 = Color::blue; //error: not Color->int
conversion
Color a6 = Color::blue; //ok
45. user-defined literals
C++03 C++11
123 // int 1.2_i // imaginary
1.2 // double 123.4567891234_df // decimal floating point (IBM)
1.2F // float 101010111000101_b // binary
'a' // char 123_s // seconds
1ULL // unsigned long long 123.56_km // not miles! (units)
Speed v = 100_km/1_h;
int operator "" _km(int val){
return val;
}
Practical usage:
http://www.codeproject.com/Articles/447922/Applic
ation-of-Cplusplus11-User-Defined-Literals-t
46. Move Semantics
C++03
typedef vector<float> Matrix;
//requires already created C
void Mul(const Matrix& A, const Matrix& B, Matrix& C);
//need to manage lifetime manually using new/delete
void Mul(const Matrix& A, const Matrix& B, Matrix* C);
//please, don’t forget to call delete
Matrix* operator*(const Matrix& A, const Matrix& B);
//no need to manage lifetime manually, but adds some
//performance and abstraction penalty
shared_ptr<Matrix> operator* (const Matrix& A, const
Matrix& B);
47. Move Semantics
C++03 C++11
typedef vector<float> Matrix; typedef vector<float> Matrix;
//requires already created C
void Mul(const Matrix& A, const Matrix& B, Matrix& C);
//need to manage lifetime manually using new/delete
void Mul(const Matrix& A, const Matrix& B, Matrix* C);
//Cool syntax, no abstraction or performance
//please, don’t forget to call delete //penalty! Thanks to move semantics!
Matrix* operator*(const Matrix& A, const Matrix& B); Matrix operator*(const Matrix& A, const Matrix& B);
//no need to manage lifetime manually, but adds some
//performance and abstraction penalty
shared_ptr<Matrix> operator* (const Matrix& A, const
Matrix& B);
Matrix A(10000);
Matrix B(10000);
Matrix C = A * B;
54. Variadic templates
C++03 C++11
void f(); template <class ...T>
template<class T> void f(T... args);
void f(T arg1);
template<class T, class U>
void f(T arg1, U arg2);
template<class T, class U, class Y>
void f(T arg1, U arg2, Y arg3);
template<class T, class U, class Y, class Z>
void f(T arg1, U arg2, Y arg3, Z arg4);
f(“test”,42,’s’,12.f); f(“test”,42,’s’,12.f);
//… till some max N.
56. Tuple definition using
variadic templates
C++11
template<class... Elements> “LISP-style” definition:
class tuple; A tuple is either:
template<> - An empty tuple, or
class tuple<> {};
template<class Head, class... Tail> - A pair (head, tail) where head is
class tuple<Head, Tail...> : private tuple<Tail...> the first element of the tuple and
{ tail is a tuple containing the rest(…)
Head head; of the elements.
//
};
57. Variadic templates
C++11 Haskell
template<int... Elements> struct count; count [] = 0
count (T:Args) = 1 + count Args
template<> struct count<>
{
static const int value = 0; //call
}; count [0,1,2,3,4]
template<int T, int... Args>
struct count<T, Args...>
{
static const int value = 1 +
count<Args...>::value;
};
//call
int x = count<0,1,2,3,4>::value;
58. Variadic templates(sizeof... operator)
C++11
template<int... Elements> struct count; template<int... Elements>
struct count
template<> struct count<> {
{ static const int value = sizeof...(Elements);
static const int value = 0; };
};
/*
template<int T, int... Args> sizeof...() – return the number elements in
struct count<T, Args...> a parameter pack
{ */
static const int value = 1 +
count<Args...>::value; //call
}; int x = count<0,1,2,3,4>::value;
//call
int x = count<0,1,2,3,4>::value;
59. std::string
Interprets a signed integer value in the string:
int stoi( const std::string& str, size_t *pos = 0, int base = 10 );
long stol( const std::string& str, size_t *pos = 0, int base = 10 );
long long stoll( const std::string& str, size_t *pos = 0, int base = 10 );
Interprets an unsigned integer value in the string:
unsigned long stoul( const std::string& str, size_t *pos = 0, int base = 10 );
unsigned long long stoull( const std::string& str, size_t *pos = 0, int base = 10 );
Interprets a floating point value in a string:
float stof( const std::string& str, size_t *pos = 0 );
double stod( const std::string& str, size_t *pos = 0 );
long double stold( const std::string& str, size_t *pos = 0 );
Converts a (un)signed/decimal integer to a string/wstring:
to_string
to_wstring
67. std::mutex
C++11 Output(is defined within run)
#include <iostream>
#include <thread>
1: 0
#include <mutex> 1: 1
using namespace std; 1: 2
mutex m;
1: 3
1: 4
void run(size_t n){
m.lock(); 2: 0
for (size_t i = 0; i < 5; ++i){ 2: 1
cout << n << ": " << i << endl;
} 2: 2
m.unlock();
2: 3
} 2: 4
int main(){ 3: 0
thread t1(run, 1);
thread t2(run, 2);
3: 1
thread t3(run, 3); 3: 2
t1.join(); 3: 3
t2.join(); 3: 4
t3.join();
return 0;
}
68. std::lock_guard+std::mutex
C++11
#include <iostream> #include <iostream>
#include <thread> #include <thread>
#include <mutex> #include <mutex>
using namespace std; using namespace std;
mutex m; mutex m;
void run(size_t n){ void run(size_t n){
m.lock(); lock_guard<mutex> lm(m); //ctor – m.lock(), dtor – m.unlock()
for (size_t i = 0; i < 5; ++i){ for (size_t i = 0; i < 5; ++i){
cout << n << ": " << i << endl; cout << n << ": " << i << endl;
} }
}
m.unlock();
} int main(){
thread t1(run, 1);
int main(){ thread t2(run, 2);
thread t1(run, 1); thread t3(run, 3);
thread t2(run, 2);
thread t3(run, 3); t1.join();
t2.join();
t1.join(); t3.join();
t2.join();
t3.join(); return 0;
}
return 0;
}
69. std::async
C++11
#include <iostream>
#include <future>
using namespace std;
int Fib(int n){
return n<=2 ? 1 : Fib(n-1)+Fib(n-2);
}
int calc1(){ return Fib(30); }
int calc2(){ return Fib(40); }
int main()
{
// start calc1() asynchronously
future<int> result1 = async(calc1);
// call calc2() synchronously
int result2 = calc2();
// wait for calc1() and add its result to result2
int result = result1.get() + result2;
cout << "calc1()+calc2(): " << result << endl;
return 0;
}
70. Deprecated idioms
C++11
Now that we have C++11, we can use new features instead of following idioms:
nullptr
Move_Constructor
Safe_bool
Shrink-to-fit
Type_Safe_Enum
Requiring_or_Prohibiting_Heap-based_Objects
Type_Generator
Final_Class
address_of
http://stackoverflow.com/questions/9299101/what-c-idioms-are-deprecated-in-c11
71. C++11 compiler support
gcc icc msvc(with NOV CTP) Ibm xlc clang
38/39 27/39 24/39 17/39 37/39
Not implemented: Full STL Full STL Not Full STL
threads, regex support support(without init. implemented: support
list) threads, regex