SlideShare a Scribd company logo
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 Architectures
Joel Falcou
 
C Programming - Refresher - Part III
C Programming - Refresher - Part IIIC Programming - Refresher - Part III
C Programming - Refresher - Part III
Emertxe Information Technologies Pvt Ltd
 
Computer Programming- Lecture 8
Computer Programming- Lecture 8Computer Programming- Lecture 8
Computer Programming- Lecture 8
Dr. Md. Shohel Sayeed
 
C++11
C++11C++11
Computer Programming- Lecture 10
Computer Programming- Lecture 10Computer Programming- Lecture 10
Computer Programming- Lecture 10
Dr. Md. Shohel Sayeed
 
Computer Programming- Lecture 7
Computer Programming- Lecture 7Computer Programming- Lecture 7
Computer Programming- Lecture 7
Dr. Md. Shohel Sayeed
 
C++ Programming Language
C++ Programming Language C++ Programming Language
C++ Programming Language
Mohamed Loey
 
Computer Programming- Lecture 9
Computer Programming- Lecture 9Computer Programming- Lecture 9
Computer Programming- Lecture 9
Dr. Md. Shohel Sayeed
 
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
 
Computer Programming- Lecture 5
Computer Programming- Lecture 5 Computer Programming- Lecture 5
Computer Programming- Lecture 5
Dr. Md. Shohel Sayeed
 
C++17 introduction - Meetup @EtixLabs
C++17 introduction - Meetup @EtixLabsC++17 introduction - Meetup @EtixLabs
C++17 introduction - Meetup @EtixLabs
Stephane 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 Architectures
Joel 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
 
Lecture 12: Classes and Files
Lecture 12: Classes and FilesLecture 12: Classes and Files
Lecture 12: Classes and Files
Dr. Md. Shohel Sayeed
 
Cs2251 daa
Cs2251 daaCs2251 daa
Interm codegen
Interm codegenInterm codegen
Interm codegen
Anshul Sharma
 
Archi Modelling
Archi ModellingArchi Modelling
Archi Modelling
dilane007
 
Programming For Problem Solving Lecture Notes
Programming For Problem Solving Lecture NotesProgramming For Problem Solving Lecture Notes
Programming For Problem Solving Lecture Notes
Sreedhar 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
 
New pop.pptx.pptx.pptx.pptx
New pop.pptx.pptx.pptx.pptxNew pop.pptx.pptx.pptx.pptx
New pop.pptx.pptx.pptx.pptx
Katherine Cortés
 
Sports in the world
Sports in the world Sports in the world
Sports in the world
Imagininganeworld1
 
Tesis de-albahaca-2016-2017
Tesis de-albahaca-2016-2017Tesis de-albahaca-2016-2017
Tesis de-albahaca-2016-2017
Gustavo Patricio Pazmiño Barcia
 
Reto3 - Creación de insignias
Reto3 - Creación de insigniasReto3 - Creación de insignias
Reto3 - Creación de insignias
Sabka 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++11
Uilian 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 Writing
Amy 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 Beyond
ComicSansMS
 
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
 
Legacy is Good
Legacy is GoodLegacy is Good
Legacy is Good
Uberto Barbini
 
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
 
Beyond C++17
Beyond C++17Beyond C++17
Beyond C++17
Mateusz Pusz
 
Glimpses of C++0x
Glimpses of C++0xGlimpses of C++0x
Glimpses of C++0x
ppd1961
 
[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 Metaprograms
Platonov Sergey
 
3 algorithm-and-flowchart
3 algorithm-and-flowchart3 algorithm-and-flowchart
3 algorithm-and-flowchart
Rohit Shrivastava
 
Intro to c++
Intro to c++Intro to c++
Intro to c++
temkin abdlkader
 
CP4151 Advanced data structures and algorithms
CP4151 Advanced data structures and algorithmsCP4151 Advanced data structures and algorithms
CP4151 Advanced data structures and algorithms
Sheba41
 
C++11 and 64-bit Issues
C++11 and 64-bit IssuesC++11 and 64-bit Issues
C++11 and 64-bit Issues
Andrey 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 Server
Apache Traffic Server
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programming
ABHISHEK fulwadhwa
 
Lab 1.pptx
Lab 1.pptxLab 1.pptx
Lab 1.pptx
MohammedAlobaidy16
 
Modern c++ (C++ 11/14)
Modern c++ (C++ 11/14)Modern c++ (C++ 11/14)
Modern c++ (C++ 11/14)
Geeks Anonymes
 
lecture 2.pptx
lecture 2.pptxlecture 2.pptx
lecture 2.pptx
Anonymous9etQKwW
 
Cling the llvm based interpreter
Cling the llvm based interpreterCling the llvm based interpreter
Cling the llvm based interpreter
Roberto 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

Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming PipelinesHarnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
Christina Lin
 
Swimming pool mechanical components design.pptx
Swimming pool  mechanical components design.pptxSwimming pool  mechanical components design.pptx
Swimming pool mechanical components design.pptx
yokeleetan1
 
Building Electrical System Design & Installation
Building Electrical System Design & InstallationBuilding Electrical System Design & Installation
Building Electrical System Design & Installation
symbo111
 
14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application
SyedAbiiAzazi1
 
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
ihlasbinance2003
 
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdf
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdfTutorial for 16S rRNA Gene Analysis with QIIME2.pdf
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdf
aqil azizi
 
basic-wireline-operations-course-mahmoud-f-radwan.pdf
basic-wireline-operations-course-mahmoud-f-radwan.pdfbasic-wireline-operations-course-mahmoud-f-radwan.pdf
basic-wireline-operations-course-mahmoud-f-radwan.pdf
NidhalKahouli2
 
Literature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptxLiterature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptx
Dr Ramhari Poudyal
 
Low power architecture of logic gates using adiabatic techniques
Low power architecture of logic gates using adiabatic techniquesLow power architecture of logic gates using adiabatic techniques
Low power architecture of logic gates using adiabatic techniques
nooriasukmaningtyas
 
Series of visio cisco devices Cisco_Icons.ppt
Series of visio cisco devices Cisco_Icons.pptSeries of visio cisco devices Cisco_Icons.ppt
Series of visio cisco devices Cisco_Icons.ppt
PauloRodrigues104553
 
A review on techniques and modelling methodologies used for checking electrom...
A review on techniques and modelling methodologies used for checking electrom...A review on techniques and modelling methodologies used for checking electrom...
A review on techniques and modelling methodologies used for checking electrom...
nooriasukmaningtyas
 
Modelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdfModelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdf
camseq
 
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECTCHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
jpsjournal1
 
PPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testingPPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testing
anoopmanoharan2
 
Technical Drawings introduction to drawing of prisms
Technical Drawings introduction to drawing of prismsTechnical Drawings introduction to drawing of prisms
Technical Drawings introduction to drawing of prisms
heavyhaig
 
Exception Handling notes in java exception
Exception Handling notes in java exceptionException Handling notes in java exception
Exception Handling notes in java exception
Ratnakar Mikkili
 
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODELDEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
gerogepatton
 
PROJECT FORMAT FOR EVS AMITY UNIVERSITY GWALIOR.ppt
PROJECT FORMAT FOR EVS AMITY UNIVERSITY GWALIOR.pptPROJECT FORMAT FOR EVS AMITY UNIVERSITY GWALIOR.ppt
PROJECT FORMAT FOR EVS AMITY UNIVERSITY GWALIOR.ppt
bhadouriyakaku
 
Recycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part IIIRecycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part III
Aditya Rajan Patra
 
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTSHeap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Soumen Santra
 

Recently uploaded (20)

Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming PipelinesHarnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
 
Swimming pool mechanical components design.pptx
Swimming pool  mechanical components design.pptxSwimming pool  mechanical components design.pptx
Swimming pool mechanical components design.pptx
 
Building Electrical System Design & Installation
Building Electrical System Design & InstallationBuilding Electrical System Design & Installation
Building Electrical System Design & Installation
 
14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application
 
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
 
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdf
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdfTutorial for 16S rRNA Gene Analysis with QIIME2.pdf
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdf
 
basic-wireline-operations-course-mahmoud-f-radwan.pdf
basic-wireline-operations-course-mahmoud-f-radwan.pdfbasic-wireline-operations-course-mahmoud-f-radwan.pdf
basic-wireline-operations-course-mahmoud-f-radwan.pdf
 
Literature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptxLiterature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptx
 
Low power architecture of logic gates using adiabatic techniques
Low power architecture of logic gates using adiabatic techniquesLow power architecture of logic gates using adiabatic techniques
Low power architecture of logic gates using adiabatic techniques
 
Series of visio cisco devices Cisco_Icons.ppt
Series of visio cisco devices Cisco_Icons.pptSeries of visio cisco devices Cisco_Icons.ppt
Series of visio cisco devices Cisco_Icons.ppt
 
A review on techniques and modelling methodologies used for checking electrom...
A review on techniques and modelling methodologies used for checking electrom...A review on techniques and modelling methodologies used for checking electrom...
A review on techniques and modelling methodologies used for checking electrom...
 
Modelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdfModelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdf
 
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECTCHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
 
PPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testingPPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testing
 
Technical Drawings introduction to drawing of prisms
Technical Drawings introduction to drawing of prismsTechnical Drawings introduction to drawing of prisms
Technical Drawings introduction to drawing of prisms
 
Exception Handling notes in java exception
Exception Handling notes in java exceptionException Handling notes in java exception
Exception Handling notes in java exception
 
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODELDEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
 
PROJECT FORMAT FOR EVS AMITY UNIVERSITY GWALIOR.ppt
PROJECT FORMAT FOR EVS AMITY UNIVERSITY GWALIOR.pptPROJECT FORMAT FOR EVS AMITY UNIVERSITY GWALIOR.ppt
PROJECT FORMAT FOR EVS AMITY UNIVERSITY GWALIOR.ppt
 
Recycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part IIIRecycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part III
 
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTSHeap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
 

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