Introduction to the Boost C++ Libraries for KDE developers. Volker Krause

Similar documents
SERIOUS ABOUT SOFTWARE. Qt Core features. Timo Strömmer, May 26,

Introduction to C++11 and its use inside Qt

QStringView. everywhere. Marc Mutz, Senior Software Engineer at KDAB

CSE : Python Programming

Applied Type Erasure in Qt 5. Stephen Kelly KDAB

Homework 4. Any questions?

Purpose of Review. Review some basic C++ Familiarize us with Weiss s style Introduce specific constructs useful for implementing data structures

C++ Review. CptS 223 Advanced Data Structures. Larry Holder School of Electrical Engineering and Computer Science Washington State University

Consider the program...

Exception Namespaces C Interoperability Templates. More C++ David Chisnall. March 17, 2011

Welcome to Teach Yourself Acknowledgments Fundamental C++ Programming p. 2 An Introduction to C++ p. 4 A Brief History of C++ p.

CS201 Some Important Definitions

The C Programming Language

C++ for numerical computing

Introduction to C++ Introduction. Structure of a C++ Program. Structure of a C++ Program. C++ widely-used general-purpose programming language

Introduction to C++ with content from

CS93SI Handout 04 Spring 2006 Apr Review Answers

ECE 3574: Applied Software Design. Integration Testing

Lesson 13 - Vectors Dynamic Data Storage

The Foundation of C++: The C Subset An Overview of C p. 3 The Origins and History of C p. 4 C Is a Middle-Level Language p. 5 C Is a Structured

Overview. The Whited Sepulchre Four Strings to a Bow λ-connectedness

Software Development with C++ Templates

Test-Driven Development with Qt and KDE

Evaluation Issues in Generic Programming with Inheritance and Templates in C++

III. Classes (Chap. 3)

+ C++11. Qt5 with a touch of C++11. Matthew Eshleman covemountainsoftware.com

Linear Structures. Linear Structure. Implementations. Array details. List details. Operations 4/18/2013

CopperSpice: A Pure C++ GUI Library. Barbara Geller & Ansel Sermersheim CPPCon - September 2015

COSC 2P95. Procedural Abstraction. Week 3. Brock University. Brock University (Week 3) Procedural Abstraction 1 / 26

Developing PIM Applications with Akonadi. Till Adam / Volker Krause

Exercise 6.2 A generic container class

Linear Structures. Linear Structure. Implementations. Array details. List details. Operations 2/10/2013

Embedding Python in Your C Programs

CS 251 INTERMEDIATE SOFTWARE DESIGN SPRING C ++ Basics Review part 2 Auto pointer, templates, STL algorithms

6.S096 Lecture 4 Style and Structure

1/29/2011 AUTO POINTER (AUTO_PTR) INTERMEDIATE SOFTWARE DESIGN SPRING delete ptr might not happen memory leak!

CSE 374 Programming Concepts & Tools. Hal Perkins Spring 2010

What will happen if we try to compile, link and run this program? Do you have any comments to the code?

The Automated Analysis of Header Files for Support of the Standardization Process

Arrays. Returning arrays Pointers Dynamic arrays Smart pointers Vectors

CSE 303: Concepts and Tools for Software Development

Subroutines. Subroutine. Subroutine design. Control abstraction. If a subroutine does not fit on the screen, it is too long

CS3215. Outline: 1. Introduction 2. C++ language features 3. C++ program organization

Function Binding. Special thanks to: John Edwards. Randy Gaul

Templating functions. Comp Sci 1570 Introduction to C++ Administrative notes. Review. Templates. Compiler processing. Functions Overloading

PyROOT: Seamless Melting of C++ and Python. Pere MATO, Danilo PIPARO on behalf of the ROOT Team

Appendix. Grammar. A.1 Introduction. A.2 Keywords. There is no worse danger for a teacher than to teach words instead of things.

Simulating Partial Specialization

Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

Lab 6. Out: Wednesday 9 March 2005

Domain Specific Debugging Tools

RAD Studio XE3 The Developer Force Multiplier

Beyond UX: building solid middleware with Qt (and QML)

More loops Ch

Lecture 20: templates

CS 153 Lab4 and 5. Kishore Kumar Pusukuri. Kishore Kumar Pusukuri CS 153 Lab4 and 5

Frama-Clang, a C++ front-end for Frama-C

QUIZ. What is wrong with this code that uses default arguments?

GUI in C++ PV264 Advanced Programming in C++ Nikola Beneš Jan Mrázek Vladimír Štill. Faculty of Informatics, Masaryk University.

multiple variables having the same value multiple variables having the same identifier multiple uses of the same variable

of the minimum polling period, the ability to support asynchronous events, a

Appendix B Boost.Python

G52CPP C++ Programming Lecture 20

INF 212 ANALYSIS OF PROG. LANGS FUNCTION COMPOSITION. Instructors: Crista Lopes Copyright Instructors.

memory_resource_ptr: A Limited Smart Pointer for memory_resource Correctness

Operating Systems CMPSCI 377, Lec 2 Intro to C/C++ Prashant Shenoy University of Massachusetts Amherst

Oh my. Maya is Qt! Kristine Middlemiss, Autodesk Developer Consultant, Autodesk Developer Network

Quiz Start Time: 09:34 PM Time Left 82 sec(s)

Lecture 5. Function Pointers

Topics Covered Thus Far. CMSC 330: Organization of Programming Languages. Language Features Covered Thus Far. Programming Languages Revisited

Artemis Documentation

C++ Primer. CS 148 Autumn

CS201 Latest Solved MCQs

Code optimization techniques

PIC 10A Objects/Classes

Using Scala for building DSL s

CS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University

Introduction to C++ Introduction to C++ 1

CSE 374 Programming Concepts & Tools

STL components. STL: C++ Standard Library Standard Template Library (STL) Main Ideas. Components. Encapsulates complex data structures and algorithms

A Threading Snarl. Michael Stahl, Red Hat, Inc LibreOffice Bern 2014 Conference: A Threading Snarl

CS 376b Computer Vision

the gamedesigninitiative at cornell university Lecture 7 C++ Overview

Data Abstraction. Hwansoo Han

Qt + Maemo development

CMSC 330: Organization of Programming Languages

COS2614. Tutorial letter 203/1/2018. Programming: Contemporary Concepts. Semester 1. School of Computing. Discussion of Solutions to Assignment 3

FINAL TERM EXAMINATION SPRING 2010 CS304- OBJECT ORIENTED PROGRAMMING

Building a (resumable and extensible) DSL with Apache Groovy Jesse Glick CloudBees, Inc.

CIS 190: C/C++ Programming. Lecture 12 Student Choice

Chapter 21a Other Library Issues

Dr Markus Hagenbuchner CSCI319. Distributed Systems Chapter 3 - Processes

Name: Username: I. 20. Section: II. p p p III. p p p p Total 100. CMSC 202 Section 06 Fall 2015

Allocation & Efficiency Generic Containers Notes on Assignment 5

Basic Principles of OO. Example: Ice/Water Dispenser. Systems Thinking. Interfaces: Describing Behavior. People's Roles wrt Systems

Introduction to Lock-Free Programming. Olivier Goffart

Intro to OOP Visibility/protection levels and constructors Friend, convert constructor, destructor Operator overloading a<=b a.

Asynchronous Database Access with Qt 4.x

CSE 333 Final Exam 3/19/14

Improving the Return Value of Erase-Like Algorithms

Transcription:

Introduction to the Boost C++ Libraries for KDE developers Volker Krause volker@kdab.com

What is Boost? Comprehensive set of platform-independent C++ libs http://www.boost.org Free Software About 100 modules, 80% header-only Staging ground for the next C++ standard library Pushes C++ to its limits

Whirlwind Tour through Boost Containers Data Structures Iterators Algorithms Function Objects Higher Order Programming Generic Programming Template Metaprogramming Preprocessor Metaprogramming Text Processing Parser Generation Concurrency Math and Statistics Image Processing Platform Abstraction Python Binding Generation Unit testing...

Boost vs. Qt/KDE No GUI components Some overlap with Qt/KDE (~ 20 modules): Platform abstraction Signals Date/Time, RegExp, Serialization Smart Pointers (since Qt 4.6) Ease of use vs. flexibility Documentation STL-style naming

#1 usage in KDE: Smart Pointers Feature equivalent smart pointers in Qt since 4.6 Widely known concept and widely used in KDE already Shared Pointer Scoped Pointer Weak Pointer More powerful than you might think...

Custom Deleter QMutex *mutex =...; { } boost::shared_ptr<qmutex> mutex_releaser( mutex, std::mem_fun(&qmutex::unlock) ); mutex->lock();...

#2 usage in KDE: boost::bind Many STL and Qt algorithms require a function pointer or function object as argument Cumbersome when done manually: static void laterdeleter( QObject *obj ) { } obj->deletelater(); // possible lots of other code QList<QObject*> l =...; std::for_each( l.begin(), l.end(), laterdeleter );

Define function objects in-place In-place member call: std::for_each( l.begin(), l.end(), boost::bind(&qobject::deletelater, _1) ); In-place member call with arguments: QObject *parent =...; std::for_each( l.begin(), l.end(), boost::bind(&qobject::setparent, _1, parent ) );

Lame, show me something useful! Sort by arbitrary properties of an object: QList<QObject*> l =...; qsort( l.begin(), l.end(), boost::bind(&qobject::objectname, _1) < boost::bind(&qobject::objectname, _2) );

So, how does this work exactly? boost::bind() returns a function object Number of arguments depend on number of used placeholders (_X) boost::bind( &f, a, _2, b, _1 )( x, y ) f( a, y, b, x ) Works for global and member functions (ie. no std::mem_fun needed, first argument is the object) There are overloaded operators for these function objects:!, ==,!=, <, <=, >, >=, &&, Cascading is possible as well

Slightly more complex: boost::graph We work a lot with tree/graph structures, mostly without realizing that though We rarely use graph algorithms though Boost has a comprehensive graph library Requires slightly more work to use, due to lack of explicit graph data structures and/or standardized interfaces (like we have for lists) Example: Find the most specific type from a set of mime-types

Create a graph... QVector<PluginInfo> plugins; const PluginInfo& findbestmatch( KmimeType::Ptr mimetype ) { boost::adjacency_list<> graph( matchingindexes.size() ); for ( int i = 0, end = plugins.size() ; i!= end ; ++i ) { for ( int j = 0; j!= end; ++j ) { if ( i!= j && mimetype->is( plugins[j].mimetype() ) ) boost::add_edge( j, i, graph ); } }...

... and sort it... QVector<int> order; order.reserve( plugins.size() ); try { boost::topological_sort( graph, std::back_inserter( order ) ); } catch ( boost::not_a_dag &e ) { } kwarning() << "Mimetype tree is not a DAG!"; return plugins[order.first()]; }

Compatibility with Qt Qt containers are STL compatible #undef QT_NO_STL Container-like structures such as QString and QByteArray have STL support for reading but not for writing: QList<QByteArray> list =...; QByteArray result = boost::join( list,, );

Conclusions Do not reinvent the wheel! *) Steep learning curve, but it will pay off nevertheless But also keep in mind: Prefer equivalent Qt classes Limit use in public API (no BC guarantees) *) Unless when having a strong NIH policy

Thanks for listening! Questions? Special thanks to my colleagues Marc Mutz, Stephen Kelly and Kevin Ottens for voluntarily or involuntarily providing content for this talk :)