SlideShare a Scribd company logo
1 of 47
Download to read offline
Migration of C++ Libraries to C++14
The Goal and the Journey
numscaleUnlocked software performance
Joel Falcou
NumScale SAS
Meeting C++ 2015
1 of 30
The Times, They’are-a-changing
Isn’t it 2015 already ?
Code base migration to C++ 11/14 is a clear concern now
Time to support in compilers
Time to adopt the new standard
Worried ?
Isn’t the new C++ even creepier ?
Is <feature X> really worth it ?
Will my coworkers get it ?
2 of 30
Sustainable C++
3 of 30
Sustainable C++
What is Sustainability for C++ ?
Code intent must be obvious
Code must be clear for you and “future you”
Code must be clear for your coworkers
Are C++ 11 and 14 sustainable ?
We claim that yes
Complex and simple tasks are easier
This talk is what we learnt
3 of 30
Fear and Loathing in C++
State of the union
What were we working on ?
Boost.Dispatch : tag dispatching abstraction
Boost.SIMD : portable standard SIMD API
NT2 : Matlab done right in C++
BSP++ : parallel application deployment
Limitations of C++ 03
5 of 30
State of the union
What were we working on ?
Boost.Dispatch : tag dispatching abstraction
Boost.SIMD : portable standard SIMD API
NT2 : Matlab done right in C++
BSP++ : parallel application deployment
Limitations of C++ 03
Compile time
5 of 30
State of the union
What were we working on ?
Boost.Dispatch : tag dispatching abstraction
Boost.SIMD : portable standard SIMD API
NT2 : Matlab done right in C++
BSP++ : parallel application deployment
Limitations of C++ 03
Compile time
Complex customization point
5 of 30
State of the union
What were we working on ?
Boost.Dispatch : tag dispatching abstraction
Boost.SIMD : portable standard SIMD API
NT2 : Matlab done right in C++
BSP++ : parallel application deployment
Limitations of C++ 03
Compile time
Complex customization point
Heavy dependency on Boost
5 of 30
State of the union
What were we working on ?
Boost.Dispatch : tag dispatching abstraction
Boost.SIMD : portable standard SIMD API
NT2 : Matlab done right in C++
BSP++ : parallel application deployment
Limitations of C++ 03
Compile time
Complex customization point
Heavy dependency on Boost
Dependances on 3rd parties
5 of 30
State of the union
6 of 30
Ocean Eleven
Anticipated features
Type deduction
Variadic templates
Anonymous functions
Tuples
Threading support
Anticipated Benet
7 of 30
Ocean Eleven
Anticipated features
Type deduction
Variadic templates
Anonymous functions
Tuples
Threading support
Anticipated Benet
Shorter compile-time
7 of 30
Ocean Eleven
Anticipated features
Type deduction
Variadic templates
Anonymous functions
Tuples
Threading support
Anticipated Benet
Shorter compile-time
Simpler interaction wit user
7 of 30
Ocean Eleven
Anticipated features
Type deduction
Variadic templates
Anonymous functions
Tuples
Threading support
Anticipated Benet
Shorter compile-time
Simpler interaction wit user
Less external dependency
7 of 30
Ocean Eleven
Anticipated features
Type deduction
Variadic templates
Anonymous functions
Tuples
Threading support
Anticipated Benet
Shorter compile-time
Simpler interaction wit user
Less external dependency
Did I say shorter compile-time ?
7 of 30
Initial migration
What we did rst
Used auto/decltype here and there
Used variadic templates where it was obvious
Used std::future for threading
Used lambda as short-cut to algorithm customization
8 of 30
Initial migration
What we did rst
Used auto/decltype here and there
Used variadic templates where it was obvious
Used std::future for threading
Used lambda as short-cut to algorithm customization
Well, well, well ...
Underwhelming results : compile time still unpleasant
Smelly code to adapt lagging compilers
STL QoI varies wildly between compilers
Customization was still problematic
8 of 30
The Million Dollars Man
Lesson #1
When migrating to C++ 14, consider rebuilding the
code base in a C++ 14 idiomatic way.
9 of 30
C++ 14 is the new black
auto and decltype
Principles
auto lets compiler nd the type of a variable
auto is usable as function return
decltype computes types of expressions
Effects
Shorter, more generic code
Prevent type ‘intuition’ errors
Less symbol for the compiler to determine
11 of 30
auto and decltype
When to use auto ?
Almost Always Auto (H. Sutter)
Except : non-template public API return type
Except : concrete type is needed for outside reasons
Caveat : auto deduction rules
When to use decltype ?
Meta-programming tasks
SFINAE context in auto return type
12 of 30
Lesson Learnt
Lesson #2
Follow the Almost Always Auto philosophy in a viral
way to ensure compile-time performance
13 of 30
Variadics Templates
Principles
typename... Ts is a pack of types
Ts... is the pack expansion
Applicable to integral templates parameter
Applicable to lambdas parameters
Effects
Less macros for variadics functions support
... pack expansion generates code
... works on arbitrary expression containing a pack
14 of 30
Variadics Templates examples
template<typename Pred, typename... Ts>
struct all;
template<typename Pred, typename T>
struct all : Pred::apply<T>::type
{};
template<typename Pred, typename H, typename... Ts>
struct all : and_ < typename all<Pred,H>::type
, typename all<Pred,Ts...>::type
>
{};
15 of 30
Variadics Templates examples
template<bool... Bs> struct bools_ {};
template<typename Pred, typename... Ts>
struct all : is_same< bools_<true, typename Pred<Ts>::type...>
, bools_<typename Pred<Ts>::type..., true>
>
{};
15 of 30
Variadics Templates examples
template<typename F, typename... Ts>
F for_each_args(F f, Ts&&...a)
{
return initializer_list<int>{(ref(f)(forward<Ts>(a)),0)...}, f;
}
16 of 30
Variadics Templates
Turtles all the way down
Don’t recurse variadics unless forced too
Each recursion generate symbols and need mangling
Instead, turn your code into something that can be comma separated
Effects
Less symbols generated
Slimer executable
Faster compile-time
17 of 30
Lesson Learnt
Lesson #3
With variadics templates, it’s variadic all the way down
18 of 30
Lambda functions
Principles
Anonymous function block
Can be variadic, generic
Generates magical callable object for you
Effects
Code is more localized
Less work for the compiler
Enable higher-order programming
19 of 30
Anonymous functions
template<typename F, typename G>
auto compose( F f, G g )
{
return [f,g](auto x) { return f(g(x)); }
}
auto sqr_sin = compose( [](float x) { return x*x; }
, &::sinf
)
auto x = sqr_fin(1.758f);
20 of 30
Anonymous functions
template<typename C, typename T, typename F>
typename std::enable_if<C::value,T&&>::type select(T&& t, F&&)
{
return std::forward<T>(t);
}
template<typename C, typename T, typename F>
typename std::enable_if<!C::value,F&&>::type select(T&&, F&& f)
{
return std::forward<F>(f);
}
20 of 30
Anonymous functions
// Somewhere in a container constructor
std::for_each ( begin, end
, select<std::is_trivial<type>>
( [](auto ) {}
, [&a](auto x) { alloc_t::construct(a,&x); }
)
);
20 of 30
Lesson Learnt
Lesson #4
If your issues is solved by a higher order function, use
polymorphic/variadic lambdas functions
21 of 30
But wait, there’s more
Truths ...
Lambda are just magic functor type
Lambda’s capture are stored as members
All done automagically by the compiler
22 of 30
But wait, there’s more
Truths ...
Lambda are just magic functor type
Lambda’s capture are stored as members
All done automagically by the compiler
... and Consequences
Lambda can be used as throw-away struct
Those structs have function interface
Cheap way to get a tuple !
22 of 30
Rule #1 - Don’t speak about expression templates
Expression Templates in 4 bullets
Way to implement DSL in C++
Operators evaluates a meta-AST
AST is transformed at compile-time
Allow arbitrary code generation for high level API
Known Issues
Compile Time Hog
Complex code base (e.g Boost.Proto)
Interaction with C++ 11
23 of 30
The lambda tree that hides the type forest
Tree, Tuples, all the same
Heterogeneous tuples are Trees
A AST is basically a types tree
Implements AST as tuples ...
... tuple simplemented as lambda
Benets
Lambda wash away symbol name
Better compile time because of shorter names
Correct behavior with move semantic
24 of 30
One sec, Hold My Beer !
template<typename C0, typename C1> auto as_expr(C0&& c0, C1&& c1)
{
auto erase_type = [&]() {
struct node {
storage_type_t<C0&&> c0_;
storage_type_t<C1&&> c1_;
explicit node(C0&& a, C1&& b)
: c0_{std::forward<C0>(a)}
, c1_{std::forward<C1>(b)}
{}
};
return node{std::forward<C0>(c0), std::forward<C1>(c1)};
};
25 of 30
One sec, Hold My Beer !
using node = decltype(erase_type());
return expr<node> { std::forward<C0>(c0)
, std::forward<C1>(c1)
};
}
25 of 30
One sec, Hold My Beer !
template <typename T>
auto f(T&& t)
{
return as_expr(std::forward<T>(t), std::forward<T>(t));
}
some_type x;
std::cout << typeid(f(x)).name() << ”n”;
std::cout << typeid(f(f(x))).name() << ”n”;
std::cout << typeid(f(f(f(x)))).name() << ”n”;
std::cout << typeid(f(f(f(f(x))))).name() << ”n”;
25 of 30
One sec, Hold My Beer !
expr<‘public: <lambda_009ab8f375e07b4c1155929143898761>
::operator()(void)const ’::‘2’::node,void>
expr<‘public: <lambda_f2b41fa0275084c9467959ede97530cb>
::operator()(void)const ’::‘2’::node,void>
expr<‘public: <lambda_37974d88904c635bc611f74424f19963>
::operator()(void)const ’::‘2’::node,void>
expr<‘public: <lambda_ac503c8f3aa72c2953f3b0f0037dfa56>
::operator()(void)const ’::‘2’::node,void>
25 of 30
Lesson Learnt
Lesson #5
Use lambda as disposable data structures to reduce
symbol size.
26 of 30
It’s a Wrap !
Conclusion
What we learnt
C++ 14 change the DNA of the language
Code must adapt to C++ 14 deeply
Don’t be afraid to be creative, it *is* rewarding
28 of 30
Conclusion
What we learnt
C++ 14 change the DNA of the language
Code must adapt to C++ 14 deeply
Don’t be afraid to be creative, it *is* rewarding
Hat tipping in the general direction of :
Louis Dionne : GSoC student extraordinaire, Boost.Hana author
Agustín ”K-ballo” Bergé : Mind-blowing C++ guru
Edouard Alligand : brigand’s co-author
Jonathan Poelen : brigand’s day 1 adopter and contributor
28 of 30
Thanks for your attention

More Related Content

What's hot

(Costless) Software Abstractions for Parallel Architectures
(Costless) Software Abstractions for Parallel Architectures(Costless) Software Abstractions for Parallel Architectures
(Costless) Software Abstractions for Parallel ArchitecturesJoel Falcou
 
C++ Programming Language
C++ Programming Language C++ Programming Language
C++ Programming Language Mohamed Loey
 
Java cơ bản java co ban
Java cơ bản java co ban Java cơ bản java co ban
Java cơ bản java co ban ifis
 
C++17 introduction - Meetup @EtixLabs
C++17 introduction - Meetup @EtixLabsC++17 introduction - Meetup @EtixLabs
C++17 introduction - Meetup @EtixLabsStephane Gleizes
 
HDR Defence - Software Abstractions for Parallel Architectures
HDR Defence - Software Abstractions for Parallel ArchitecturesHDR Defence - Software Abstractions for Parallel Architectures
HDR Defence - Software Abstractions for Parallel ArchitecturesJoel Falcou
 
C programming & data structure [arrays & pointers]
C programming & data structure   [arrays & pointers]C programming & data structure   [arrays & pointers]
C programming & data structure [arrays & pointers]MomenMostafa
 
Archi Modelling
Archi ModellingArchi Modelling
Archi Modellingdilane007
 
Programming For Problem Solving Lecture Notes
Programming For Problem Solving Lecture NotesProgramming For Problem Solving Lecture Notes
Programming For Problem Solving Lecture NotesSreedhar Chowdam
 
Chapter Eight(1)
Chapter Eight(1)Chapter Eight(1)
Chapter Eight(1)bolovv
 
C programming & data structure [character strings & string functions]
C programming & data structure   [character strings & string functions]C programming & data structure   [character strings & string functions]
C programming & data structure [character strings & string functions]MomenMostafa
 

What's hot (20)

(Costless) Software Abstractions for Parallel Architectures
(Costless) Software Abstractions for Parallel Architectures(Costless) Software Abstractions for Parallel Architectures
(Costless) Software Abstractions for Parallel Architectures
 
C Programming - Refresher - Part III
C Programming - Refresher - Part IIIC Programming - Refresher - Part III
C Programming - Refresher - Part III
 
Computer Programming- Lecture 8
Computer Programming- Lecture 8Computer Programming- Lecture 8
Computer Programming- Lecture 8
 
C++11
C++11C++11
C++11
 
Computer Programming- Lecture 10
Computer Programming- Lecture 10Computer Programming- Lecture 10
Computer Programming- Lecture 10
 
Computer Programming- Lecture 7
Computer Programming- Lecture 7Computer Programming- Lecture 7
Computer Programming- Lecture 7
 
C++ Programming Language
C++ Programming Language C++ Programming Language
C++ Programming Language
 
Computer Programming- Lecture 9
Computer Programming- Lecture 9Computer Programming- Lecture 9
Computer Programming- Lecture 9
 
Java cơ bản java co ban
Java cơ bản java co ban Java cơ bản java co ban
Java cơ bản java co ban
 
Computer Programming- Lecture 5
Computer Programming- Lecture 5 Computer Programming- Lecture 5
Computer Programming- Lecture 5
 
C++17 introduction - Meetup @EtixLabs
C++17 introduction - Meetup @EtixLabsC++17 introduction - Meetup @EtixLabs
C++17 introduction - Meetup @EtixLabs
 
HDR Defence - Software Abstractions for Parallel Architectures
HDR Defence - Software Abstractions for Parallel ArchitecturesHDR Defence - Software Abstractions for Parallel Architectures
HDR Defence - Software Abstractions for Parallel Architectures
 
C programming & data structure [arrays & pointers]
C programming & data structure   [arrays & pointers]C programming & data structure   [arrays & pointers]
C programming & data structure [arrays & pointers]
 
Lecture 12: Classes and Files
Lecture 12: Classes and FilesLecture 12: Classes and Files
Lecture 12: Classes and Files
 
Cs2251 daa
Cs2251 daaCs2251 daa
Cs2251 daa
 
Interm codegen
Interm codegenInterm codegen
Interm codegen
 
Archi Modelling
Archi ModellingArchi Modelling
Archi Modelling
 
Programming For Problem Solving Lecture Notes
Programming For Problem Solving Lecture NotesProgramming For Problem Solving Lecture Notes
Programming For Problem Solving Lecture Notes
 
Chapter Eight(1)
Chapter Eight(1)Chapter Eight(1)
Chapter Eight(1)
 
C programming & data structure [character strings & string functions]
C programming & data structure   [character strings & string functions]C programming & data structure   [character strings & string functions]
C programming & data structure [character strings & string functions]
 

Viewers also liked

Cecti rodrigo lopez - buqueda del clique
Cecti   rodrigo lopez - buqueda del clique Cecti   rodrigo lopez - buqueda del clique
Cecti rodrigo lopez - buqueda del clique Roderik Lowenstein
 
Reto3 - Creación de insignias
Reto3 - Creación de insigniasReto3 - Creación de insignias
Reto3 - Creación de insigniasSabka RJ
 
ESO 2º UD 1 Estadística descriptiva (trabajo cooperativo)
ESO 2º UD 1 Estadística descriptiva (trabajo cooperativo)ESO 2º UD 1 Estadística descriptiva (trabajo cooperativo)
ESO 2º UD 1 Estadística descriptiva (trabajo cooperativo)Jose Gallegos
 
Elements of C++11
Elements of C++11Elements of C++11
Elements of C++11Uilian Ries
 
DuPage County Presentation: Maya Angelou and Speech Writing
DuPage County Presentation: Maya Angelou and Speech WritingDuPage County Presentation: Maya Angelou and Speech Writing
DuPage County Presentation: Maya Angelou and Speech WritingAmy Vujaklija
 
Mock Servers - Fake All the Things!
Mock Servers - Fake All the Things!Mock Servers - Fake All the Things!
Mock Servers - Fake All the Things!Atlassian
 

Viewers also liked (9)

Cecti rodrigo lopez - buqueda del clique
Cecti   rodrigo lopez - buqueda del clique Cecti   rodrigo lopez - buqueda del clique
Cecti rodrigo lopez - buqueda del clique
 
New pop.pptx.pptx.pptx.pptx
New pop.pptx.pptx.pptx.pptxNew pop.pptx.pptx.pptx.pptx
New pop.pptx.pptx.pptx.pptx
 
Sports in the world
Sports in the world Sports in the world
Sports in the world
 
Tesis de-albahaca-2016-2017
Tesis de-albahaca-2016-2017Tesis de-albahaca-2016-2017
Tesis de-albahaca-2016-2017
 
Reto3 - Creación de insignias
Reto3 - Creación de insigniasReto3 - Creación de insignias
Reto3 - Creación de insignias
 
ESO 2º UD 1 Estadística descriptiva (trabajo cooperativo)
ESO 2º UD 1 Estadística descriptiva (trabajo cooperativo)ESO 2º UD 1 Estadística descriptiva (trabajo cooperativo)
ESO 2º UD 1 Estadística descriptiva (trabajo cooperativo)
 
Elements of C++11
Elements of C++11Elements of C++11
Elements of C++11
 
DuPage County Presentation: Maya Angelou and Speech Writing
DuPage County Presentation: Maya Angelou and Speech WritingDuPage County Presentation: Maya Angelou and Speech Writing
DuPage County Presentation: Maya Angelou and Speech Writing
 
Mock Servers - Fake All the Things!
Mock Servers - Fake All the Things!Mock Servers - Fake All the Things!
Mock Servers - Fake All the Things!
 

Similar to The Goal and The Journey - Turning back on one year of C++14 Migration

Cpp17 and Beyond
Cpp17 and BeyondCpp17 and Beyond
Cpp17 and BeyondComicSansMS
 
How to avoid bugs using modern C++
How to avoid bugs using modern C++How to avoid bugs using modern C++
How to avoid bugs using modern C++PVS-Studio
 
C++ Concepts and Ranges - How to use them?
C++ Concepts and Ranges - How to use them?C++ Concepts and Ranges - How to use them?
C++ Concepts and Ranges - How to use them?Mateusz Pusz
 
Glimpses of C++0x
Glimpses of C++0xGlimpses of C++0x
Glimpses of C++0xppd1961
 
[C++ korea] effective modern c++ study item 3 understand decltype +이동우
[C++ korea] effective modern c++ study   item 3 understand decltype +이동우[C++ korea] effective modern c++ study   item 3 understand decltype +이동우
[C++ korea] effective modern c++ study item 3 understand decltype +이동우Seok-joon Yun
 
Debugging and Profiling C++ Template Metaprograms
Debugging and Profiling C++ Template MetaprogramsDebugging and Profiling C++ Template Metaprograms
Debugging and Profiling C++ Template MetaprogramsPlatonov Sergey
 
CP4151 Advanced data structures and algorithms
CP4151 Advanced data structures and algorithmsCP4151 Advanced data structures and algorithms
CP4151 Advanced data structures and algorithmsSheba41
 
C++11 and 64-bit Issues
C++11 and 64-bit IssuesC++11 and 64-bit Issues
C++11 and 64-bit IssuesAndrey Karpov
 
Consequences of using the Copy-Paste method in C++ programming and how to dea...
Consequences of using the Copy-Paste method in C++ programming and how to dea...Consequences of using the Copy-Paste method in C++ programming and how to dea...
Consequences of using the Copy-Paste method in C++ programming and how to dea...Andrey Karpov
 
Gude for C++11 in Apache Traffic Server
Gude for C++11 in Apache Traffic ServerGude for C++11 in Apache Traffic Server
Gude for C++11 in Apache Traffic ServerApache Traffic Server
 
Modern c++ (C++ 11/14)
Modern c++ (C++ 11/14)Modern c++ (C++ 11/14)
Modern c++ (C++ 11/14)Geeks Anonymes
 
Cling the llvm based interpreter
Cling the llvm based interpreterCling the llvm based interpreter
Cling the llvm based interpreterRoberto Nogueira
 
[GRCPP] Introduction to concepts (C++20)
[GRCPP] Introduction to concepts (C++20)[GRCPP] Introduction to concepts (C++20)
[GRCPP] Introduction to concepts (C++20)Dimitrios Platis
 

Similar to The Goal and The Journey - Turning back on one year of C++14 Migration (20)

Cpp17 and Beyond
Cpp17 and BeyondCpp17 and Beyond
Cpp17 and Beyond
 
How to avoid bugs using modern C++
How to avoid bugs using modern C++How to avoid bugs using modern C++
How to avoid bugs using modern C++
 
Legacy is Good
Legacy is GoodLegacy is Good
Legacy is Good
 
C++ Concepts and Ranges - How to use them?
C++ Concepts and Ranges - How to use them?C++ Concepts and Ranges - How to use them?
C++ Concepts and Ranges - How to use them?
 
Beyond C++17
Beyond C++17Beyond C++17
Beyond C++17
 
Glimpses of C++0x
Glimpses of C++0xGlimpses of C++0x
Glimpses of C++0x
 
[C++ korea] effective modern c++ study item 3 understand decltype +이동우
[C++ korea] effective modern c++ study   item 3 understand decltype +이동우[C++ korea] effective modern c++ study   item 3 understand decltype +이동우
[C++ korea] effective modern c++ study item 3 understand decltype +이동우
 
Debugging and Profiling C++ Template Metaprograms
Debugging and Profiling C++ Template MetaprogramsDebugging and Profiling C++ Template Metaprograms
Debugging and Profiling C++ Template Metaprograms
 
3 algorithm-and-flowchart
3 algorithm-and-flowchart3 algorithm-and-flowchart
3 algorithm-and-flowchart
 
Intro to c++
Intro to c++Intro to c++
Intro to c++
 
CP4151 Advanced data structures and algorithms
CP4151 Advanced data structures and algorithmsCP4151 Advanced data structures and algorithms
CP4151 Advanced data structures and algorithms
 
C++11 and 64-bit Issues
C++11 and 64-bit IssuesC++11 and 64-bit Issues
C++11 and 64-bit Issues
 
Consequences of using the Copy-Paste method in C++ programming and how to dea...
Consequences of using the Copy-Paste method in C++ programming and how to dea...Consequences of using the Copy-Paste method in C++ programming and how to dea...
Consequences of using the Copy-Paste method in C++ programming and how to dea...
 
Gude for C++11 in Apache Traffic Server
Gude for C++11 in Apache Traffic ServerGude for C++11 in Apache Traffic Server
Gude for C++11 in Apache Traffic Server
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programming
 
Lab 1.pptx
Lab 1.pptxLab 1.pptx
Lab 1.pptx
 
Modern c++ (C++ 11/14)
Modern c++ (C++ 11/14)Modern c++ (C++ 11/14)
Modern c++ (C++ 11/14)
 
lecture 2.pptx
lecture 2.pptxlecture 2.pptx
lecture 2.pptx
 
Cling the llvm based interpreter
Cling the llvm based interpreterCling the llvm based interpreter
Cling the llvm based interpreter
 
[GRCPP] Introduction to concepts (C++20)
[GRCPP] Introduction to concepts (C++20)[GRCPP] Introduction to concepts (C++20)
[GRCPP] Introduction to concepts (C++20)
 

Recently uploaded

Cloud-Computing_CSE311_Computer-Networking CSE GUB BD - Shahidul.pptx
Cloud-Computing_CSE311_Computer-Networking CSE GUB BD - Shahidul.pptxCloud-Computing_CSE311_Computer-Networking CSE GUB BD - Shahidul.pptx
Cloud-Computing_CSE311_Computer-Networking CSE GUB BD - Shahidul.pptxMd. Shahidul Islam Prodhan
 
DR PROF ING GURUDUTT SAHNI WIKIPEDIA.pdf
DR PROF ING GURUDUTT SAHNI WIKIPEDIA.pdfDR PROF ING GURUDUTT SAHNI WIKIPEDIA.pdf
DR PROF ING GURUDUTT SAHNI WIKIPEDIA.pdfDrGurudutt
 
Complex plane, Modulus, Argument, Graphical representation of a complex numbe...
Complex plane, Modulus, Argument, Graphical representation of a complex numbe...Complex plane, Modulus, Argument, Graphical representation of a complex numbe...
Complex plane, Modulus, Argument, Graphical representation of a complex numbe...MohammadAliNayeem
 
Top 13 Famous Civil Engineering Scientist
Top 13 Famous Civil Engineering ScientistTop 13 Famous Civil Engineering Scientist
Top 13 Famous Civil Engineering Scientistgettygaming1
 
Furniture showroom management system project.pdf
Furniture showroom management system project.pdfFurniture showroom management system project.pdf
Furniture showroom management system project.pdfKamal Acharya
 
An improvement in the safety of big data using blockchain technology
An improvement in the safety of big data using blockchain technologyAn improvement in the safety of big data using blockchain technology
An improvement in the safety of big data using blockchain technologyBOHRInternationalJou1
 
Arduino based vehicle speed tracker project
Arduino based vehicle speed tracker projectArduino based vehicle speed tracker project
Arduino based vehicle speed tracker projectRased Khan
 
Activity Planning: Objectives, Project Schedule, Network Planning Model. Time...
Activity Planning: Objectives, Project Schedule, Network Planning Model. Time...Activity Planning: Objectives, Project Schedule, Network Planning Model. Time...
Activity Planning: Objectives, Project Schedule, Network Planning Model. Time...Lovely Professional University
 
Low rpm Generator for efficient energy harnessing from a two stage wind turbine
Low rpm Generator for efficient energy harnessing from a two stage wind turbineLow rpm Generator for efficient energy harnessing from a two stage wind turbine
Low rpm Generator for efficient energy harnessing from a two stage wind turbineAftabkhan575376
 
Attraction and Repulsion type Moving Iron Instruments.pptx
Attraction and Repulsion type Moving Iron Instruments.pptxAttraction and Repulsion type Moving Iron Instruments.pptx
Attraction and Repulsion type Moving Iron Instruments.pptxkarthikeyanS725446
 
RESORT MANAGEMENT AND RESERVATION SYSTEM PROJECT REPORT.pdf
RESORT MANAGEMENT AND RESERVATION SYSTEM PROJECT REPORT.pdfRESORT MANAGEMENT AND RESERVATION SYSTEM PROJECT REPORT.pdf
RESORT MANAGEMENT AND RESERVATION SYSTEM PROJECT REPORT.pdfKamal Acharya
 
RM&IPR M5 notes.pdfResearch Methodolgy & Intellectual Property Rights Series 5
RM&IPR M5 notes.pdfResearch Methodolgy & Intellectual Property Rights Series 5RM&IPR M5 notes.pdfResearch Methodolgy & Intellectual Property Rights Series 5
RM&IPR M5 notes.pdfResearch Methodolgy & Intellectual Property Rights Series 5T.D. Shashikala
 
Planetary Gears of automatic transmission of vehicle
Planetary Gears of automatic transmission of vehiclePlanetary Gears of automatic transmission of vehicle
Planetary Gears of automatic transmission of vehicleahmedmostafa941217
 
Electrostatic field in a coaxial transmission line
Electrostatic field in a coaxial transmission lineElectrostatic field in a coaxial transmission line
Electrostatic field in a coaxial transmission lineJulioCesarSalazarHer1
 
Supermarket billing system project report..pdf
Supermarket billing system project report..pdfSupermarket billing system project report..pdf
Supermarket billing system project report..pdfKamal Acharya
 
"United Nations Park" Site Visit Report.
"United Nations Park" Site  Visit Report."United Nations Park" Site  Visit Report.
"United Nations Park" Site Visit Report.MdManikurRahman
 
ENCODERS & DECODERS - Digital Electronics - diu swe
ENCODERS & DECODERS - Digital Electronics - diu sweENCODERS & DECODERS - Digital Electronics - diu swe
ENCODERS & DECODERS - Digital Electronics - diu sweMohammadAliNayeem
 
KIT-601 Lecture Notes-UNIT-3.pdf Mining Data Stream
KIT-601 Lecture Notes-UNIT-3.pdf Mining Data StreamKIT-601 Lecture Notes-UNIT-3.pdf Mining Data Stream
KIT-601 Lecture Notes-UNIT-3.pdf Mining Data StreamDr. Radhey Shyam
 
School management system project report.pdf
School management system project report.pdfSchool management system project report.pdf
School management system project report.pdfKamal Acharya
 
Peek implant persentation - Copy (1).pdf
Peek implant persentation - Copy (1).pdfPeek implant persentation - Copy (1).pdf
Peek implant persentation - Copy (1).pdfAyahmorsy
 

Recently uploaded (20)

Cloud-Computing_CSE311_Computer-Networking CSE GUB BD - Shahidul.pptx
Cloud-Computing_CSE311_Computer-Networking CSE GUB BD - Shahidul.pptxCloud-Computing_CSE311_Computer-Networking CSE GUB BD - Shahidul.pptx
Cloud-Computing_CSE311_Computer-Networking CSE GUB BD - Shahidul.pptx
 
DR PROF ING GURUDUTT SAHNI WIKIPEDIA.pdf
DR PROF ING GURUDUTT SAHNI WIKIPEDIA.pdfDR PROF ING GURUDUTT SAHNI WIKIPEDIA.pdf
DR PROF ING GURUDUTT SAHNI WIKIPEDIA.pdf
 
Complex plane, Modulus, Argument, Graphical representation of a complex numbe...
Complex plane, Modulus, Argument, Graphical representation of a complex numbe...Complex plane, Modulus, Argument, Graphical representation of a complex numbe...
Complex plane, Modulus, Argument, Graphical representation of a complex numbe...
 
Top 13 Famous Civil Engineering Scientist
Top 13 Famous Civil Engineering ScientistTop 13 Famous Civil Engineering Scientist
Top 13 Famous Civil Engineering Scientist
 
Furniture showroom management system project.pdf
Furniture showroom management system project.pdfFurniture showroom management system project.pdf
Furniture showroom management system project.pdf
 
An improvement in the safety of big data using blockchain technology
An improvement in the safety of big data using blockchain technologyAn improvement in the safety of big data using blockchain technology
An improvement in the safety of big data using blockchain technology
 
Arduino based vehicle speed tracker project
Arduino based vehicle speed tracker projectArduino based vehicle speed tracker project
Arduino based vehicle speed tracker project
 
Activity Planning: Objectives, Project Schedule, Network Planning Model. Time...
Activity Planning: Objectives, Project Schedule, Network Planning Model. Time...Activity Planning: Objectives, Project Schedule, Network Planning Model. Time...
Activity Planning: Objectives, Project Schedule, Network Planning Model. Time...
 
Low rpm Generator for efficient energy harnessing from a two stage wind turbine
Low rpm Generator for efficient energy harnessing from a two stage wind turbineLow rpm Generator for efficient energy harnessing from a two stage wind turbine
Low rpm Generator for efficient energy harnessing from a two stage wind turbine
 
Attraction and Repulsion type Moving Iron Instruments.pptx
Attraction and Repulsion type Moving Iron Instruments.pptxAttraction and Repulsion type Moving Iron Instruments.pptx
Attraction and Repulsion type Moving Iron Instruments.pptx
 
RESORT MANAGEMENT AND RESERVATION SYSTEM PROJECT REPORT.pdf
RESORT MANAGEMENT AND RESERVATION SYSTEM PROJECT REPORT.pdfRESORT MANAGEMENT AND RESERVATION SYSTEM PROJECT REPORT.pdf
RESORT MANAGEMENT AND RESERVATION SYSTEM PROJECT REPORT.pdf
 
RM&IPR M5 notes.pdfResearch Methodolgy & Intellectual Property Rights Series 5
RM&IPR M5 notes.pdfResearch Methodolgy & Intellectual Property Rights Series 5RM&IPR M5 notes.pdfResearch Methodolgy & Intellectual Property Rights Series 5
RM&IPR M5 notes.pdfResearch Methodolgy & Intellectual Property Rights Series 5
 
Planetary Gears of automatic transmission of vehicle
Planetary Gears of automatic transmission of vehiclePlanetary Gears of automatic transmission of vehicle
Planetary Gears of automatic transmission of vehicle
 
Electrostatic field in a coaxial transmission line
Electrostatic field in a coaxial transmission lineElectrostatic field in a coaxial transmission line
Electrostatic field in a coaxial transmission line
 
Supermarket billing system project report..pdf
Supermarket billing system project report..pdfSupermarket billing system project report..pdf
Supermarket billing system project report..pdf
 
"United Nations Park" Site Visit Report.
"United Nations Park" Site  Visit Report."United Nations Park" Site  Visit Report.
"United Nations Park" Site Visit Report.
 
ENCODERS & DECODERS - Digital Electronics - diu swe
ENCODERS & DECODERS - Digital Electronics - diu sweENCODERS & DECODERS - Digital Electronics - diu swe
ENCODERS & DECODERS - Digital Electronics - diu swe
 
KIT-601 Lecture Notes-UNIT-3.pdf Mining Data Stream
KIT-601 Lecture Notes-UNIT-3.pdf Mining Data StreamKIT-601 Lecture Notes-UNIT-3.pdf Mining Data Stream
KIT-601 Lecture Notes-UNIT-3.pdf Mining Data Stream
 
School management system project report.pdf
School management system project report.pdfSchool management system project report.pdf
School management system project report.pdf
 
Peek implant persentation - Copy (1).pdf
Peek implant persentation - Copy (1).pdfPeek implant persentation - Copy (1).pdf
Peek implant persentation - Copy (1).pdf
 

The Goal and The Journey - Turning back on one year of C++14 Migration

  • 1. Migration of C++ Libraries to C++14 The Goal and the Journey numscaleUnlocked software performance Joel Falcou NumScale SAS Meeting C++ 2015 1 of 30
  • 2. The Times, They’are-a-changing Isn’t it 2015 already ? Code base migration to C++ 11/14 is a clear concern now Time to support in compilers Time to adopt the new standard Worried ? Isn’t the new C++ even creepier ? Is <feature X> really worth it ? Will my coworkers get it ? 2 of 30
  • 4. Sustainable C++ What is Sustainability for C++ ? Code intent must be obvious Code must be clear for you and “future you” Code must be clear for your coworkers Are C++ 11 and 14 sustainable ? We claim that yes Complex and simple tasks are easier This talk is what we learnt 3 of 30
  • 6. State of the union What were we working on ? Boost.Dispatch : tag dispatching abstraction Boost.SIMD : portable standard SIMD API NT2 : Matlab done right in C++ BSP++ : parallel application deployment Limitations of C++ 03 5 of 30
  • 7. State of the union What were we working on ? Boost.Dispatch : tag dispatching abstraction Boost.SIMD : portable standard SIMD API NT2 : Matlab done right in C++ BSP++ : parallel application deployment Limitations of C++ 03 Compile time 5 of 30
  • 8. State of the union What were we working on ? Boost.Dispatch : tag dispatching abstraction Boost.SIMD : portable standard SIMD API NT2 : Matlab done right in C++ BSP++ : parallel application deployment Limitations of C++ 03 Compile time Complex customization point 5 of 30
  • 9. State of the union What were we working on ? Boost.Dispatch : tag dispatching abstraction Boost.SIMD : portable standard SIMD API NT2 : Matlab done right in C++ BSP++ : parallel application deployment Limitations of C++ 03 Compile time Complex customization point Heavy dependency on Boost 5 of 30
  • 10. State of the union What were we working on ? Boost.Dispatch : tag dispatching abstraction Boost.SIMD : portable standard SIMD API NT2 : Matlab done right in C++ BSP++ : parallel application deployment Limitations of C++ 03 Compile time Complex customization point Heavy dependency on Boost Dependances on 3rd parties 5 of 30
  • 11. State of the union 6 of 30
  • 12. Ocean Eleven Anticipated features Type deduction Variadic templates Anonymous functions Tuples Threading support Anticipated Benet 7 of 30
  • 13. Ocean Eleven Anticipated features Type deduction Variadic templates Anonymous functions Tuples Threading support Anticipated Benet Shorter compile-time 7 of 30
  • 14. Ocean Eleven Anticipated features Type deduction Variadic templates Anonymous functions Tuples Threading support Anticipated Benet Shorter compile-time Simpler interaction wit user 7 of 30
  • 15. Ocean Eleven Anticipated features Type deduction Variadic templates Anonymous functions Tuples Threading support Anticipated Benet Shorter compile-time Simpler interaction wit user Less external dependency 7 of 30
  • 16. Ocean Eleven Anticipated features Type deduction Variadic templates Anonymous functions Tuples Threading support Anticipated Benet Shorter compile-time Simpler interaction wit user Less external dependency Did I say shorter compile-time ? 7 of 30
  • 17. Initial migration What we did rst Used auto/decltype here and there Used variadic templates where it was obvious Used std::future for threading Used lambda as short-cut to algorithm customization 8 of 30
  • 18. Initial migration What we did rst Used auto/decltype here and there Used variadic templates where it was obvious Used std::future for threading Used lambda as short-cut to algorithm customization Well, well, well ... Underwhelming results : compile time still unpleasant Smelly code to adapt lagging compilers STL QoI varies wildly between compilers Customization was still problematic 8 of 30
  • 19. The Million Dollars Man Lesson #1 When migrating to C++ 14, consider rebuilding the code base in a C++ 14 idiomatic way. 9 of 30
  • 20. C++ 14 is the new black
  • 21. auto and decltype Principles auto lets compiler nd the type of a variable auto is usable as function return decltype computes types of expressions Effects Shorter, more generic code Prevent type ‘intuition’ errors Less symbol for the compiler to determine 11 of 30
  • 22. auto and decltype When to use auto ? Almost Always Auto (H. Sutter) Except : non-template public API return type Except : concrete type is needed for outside reasons Caveat : auto deduction rules When to use decltype ? Meta-programming tasks SFINAE context in auto return type 12 of 30
  • 23. Lesson Learnt Lesson #2 Follow the Almost Always Auto philosophy in a viral way to ensure compile-time performance 13 of 30
  • 24. Variadics Templates Principles typename... Ts is a pack of types Ts... is the pack expansion Applicable to integral templates parameter Applicable to lambdas parameters Effects Less macros for variadics functions support ... pack expansion generates code ... works on arbitrary expression containing a pack 14 of 30
  • 25. Variadics Templates examples template<typename Pred, typename... Ts> struct all; template<typename Pred, typename T> struct all : Pred::apply<T>::type {}; template<typename Pred, typename H, typename... Ts> struct all : and_ < typename all<Pred,H>::type , typename all<Pred,Ts...>::type > {}; 15 of 30
  • 26. Variadics Templates examples template<bool... Bs> struct bools_ {}; template<typename Pred, typename... Ts> struct all : is_same< bools_<true, typename Pred<Ts>::type...> , bools_<typename Pred<Ts>::type..., true> > {}; 15 of 30
  • 27. Variadics Templates examples template<typename F, typename... Ts> F for_each_args(F f, Ts&&...a) { return initializer_list<int>{(ref(f)(forward<Ts>(a)),0)...}, f; } 16 of 30
  • 28. Variadics Templates Turtles all the way down Don’t recurse variadics unless forced too Each recursion generate symbols and need mangling Instead, turn your code into something that can be comma separated Effects Less symbols generated Slimer executable Faster compile-time 17 of 30
  • 29. Lesson Learnt Lesson #3 With variadics templates, it’s variadic all the way down 18 of 30
  • 30. Lambda functions Principles Anonymous function block Can be variadic, generic Generates magical callable object for you Effects Code is more localized Less work for the compiler Enable higher-order programming 19 of 30
  • 31. Anonymous functions template<typename F, typename G> auto compose( F f, G g ) { return [f,g](auto x) { return f(g(x)); } } auto sqr_sin = compose( [](float x) { return x*x; } , &::sinf ) auto x = sqr_fin(1.758f); 20 of 30
  • 32. Anonymous functions template<typename C, typename T, typename F> typename std::enable_if<C::value,T&&>::type select(T&& t, F&&) { return std::forward<T>(t); } template<typename C, typename T, typename F> typename std::enable_if<!C::value,F&&>::type select(T&&, F&& f) { return std::forward<F>(f); } 20 of 30
  • 33. Anonymous functions // Somewhere in a container constructor std::for_each ( begin, end , select<std::is_trivial<type>> ( [](auto ) {} , [&a](auto x) { alloc_t::construct(a,&x); } ) ); 20 of 30
  • 34. Lesson Learnt Lesson #4 If your issues is solved by a higher order function, use polymorphic/variadic lambdas functions 21 of 30
  • 35. But wait, there’s more Truths ... Lambda are just magic functor type Lambda’s capture are stored as members All done automagically by the compiler 22 of 30
  • 36. But wait, there’s more Truths ... Lambda are just magic functor type Lambda’s capture are stored as members All done automagically by the compiler ... and Consequences Lambda can be used as throw-away struct Those structs have function interface Cheap way to get a tuple ! 22 of 30
  • 37. Rule #1 - Don’t speak about expression templates Expression Templates in 4 bullets Way to implement DSL in C++ Operators evaluates a meta-AST AST is transformed at compile-time Allow arbitrary code generation for high level API Known Issues Compile Time Hog Complex code base (e.g Boost.Proto) Interaction with C++ 11 23 of 30
  • 38. The lambda tree that hides the type forest Tree, Tuples, all the same Heterogeneous tuples are Trees A AST is basically a types tree Implements AST as tuples ... ... tuple simplemented as lambda Benets Lambda wash away symbol name Better compile time because of shorter names Correct behavior with move semantic 24 of 30
  • 39. One sec, Hold My Beer ! template<typename C0, typename C1> auto as_expr(C0&& c0, C1&& c1) { auto erase_type = [&]() { struct node { storage_type_t<C0&&> c0_; storage_type_t<C1&&> c1_; explicit node(C0&& a, C1&& b) : c0_{std::forward<C0>(a)} , c1_{std::forward<C1>(b)} {} }; return node{std::forward<C0>(c0), std::forward<C1>(c1)}; }; 25 of 30
  • 40. One sec, Hold My Beer ! using node = decltype(erase_type()); return expr<node> { std::forward<C0>(c0) , std::forward<C1>(c1) }; } 25 of 30
  • 41. One sec, Hold My Beer ! template <typename T> auto f(T&& t) { return as_expr(std::forward<T>(t), std::forward<T>(t)); } some_type x; std::cout << typeid(f(x)).name() << ”n”; std::cout << typeid(f(f(x))).name() << ”n”; std::cout << typeid(f(f(f(x)))).name() << ”n”; std::cout << typeid(f(f(f(f(x))))).name() << ”n”; 25 of 30
  • 42. One sec, Hold My Beer ! expr<‘public: <lambda_009ab8f375e07b4c1155929143898761> ::operator()(void)const ’::‘2’::node,void> expr<‘public: <lambda_f2b41fa0275084c9467959ede97530cb> ::operator()(void)const ’::‘2’::node,void> expr<‘public: <lambda_37974d88904c635bc611f74424f19963> ::operator()(void)const ’::‘2’::node,void> expr<‘public: <lambda_ac503c8f3aa72c2953f3b0f0037dfa56> ::operator()(void)const ’::‘2’::node,void> 25 of 30
  • 43. Lesson Learnt Lesson #5 Use lambda as disposable data structures to reduce symbol size. 26 of 30
  • 45. Conclusion What we learnt C++ 14 change the DNA of the language Code must adapt to C++ 14 deeply Don’t be afraid to be creative, it *is* rewarding 28 of 30
  • 46. Conclusion What we learnt C++ 14 change the DNA of the language Code must adapt to C++ 14 deeply Don’t be afraid to be creative, it *is* rewarding Hat tipping in the general direction of : Louis Dionne : GSoC student extraordinaire, Boost.Hana author Agustín ”K-ballo” Bergé : Mind-blowing C++ guru Edouard Alligand : brigand’s co-author Jonathan Poelen : brigand’s day 1 adopter and contributor 28 of 30
  • 47. Thanks for your attention