News

Course: Boost Your Productivity with Modern C++ -- Peter Gottschling

peter-gottschling.jpgA repeat of last year's popular course, again being held in English and German:

Boost Your Productivity with Modern C++

by Peter Gottschling

Abstract:

Templates (generic programming)

  • Function templates
  • Class templates
  • Variadic Templates (C++11)
  • Concepts
  • Specialization
  • Template arguments that are not types
  • Functors
  • Lambda functions (C++11)

Standard Template Library

  • Iterator concept
  • Containers
  • Functions
  • Meta-programming
  • Let the compiler compute
  • Providing type informations
  • Auto and decltype (C++11)
  • Const-adaptive classes
  • Expression templates

Other advanced and new techniques

  • Calling functions from derived classes without overhead
  • RValues and move semantics (C++11)
  • Initialization lists (C++11)
  • New for-loops (C++11)

Peter Gottschling is author of the Matrix Template Library 4, co-author of the Boost Graph Library and other scientific libraries. He is vice-chair of DIN's programming language group and head of the German delegation in the ISO committee for C++ standardization. He is managing director of SimuNova and taught C++ at TU Dresden, TU Berlin and Indiana University.

Quick Q:Is it possible in C++ to iterate over a std::map with unpacked key and value?

Quick A: An easy solution is not supported by the standard, it may come later.

Recently on SO:

Is it possible in C++ to do std::map<> “for element : container” iteration with named variables (eg, key and value) instead of .first and .second?

You could write a class template:

template <class K, class T>
struct MapElem {
    K const& key;
    T& value;

    MapElem(std::pair<K const, T>& pair)
        : key(pair.first)
        , value(pair.second)
    { }
};

with the advantage of being able to write key and value but with the disadvantage of having to specify the types:

for ( MapElem<int, std::string> kv : my_map ){
    std::cout << kv.key << " --> " << kv.value;
}

And that won't work if my_map were const either. You'd have to do something like:

template <class K, class T>
struct MapElem {
    K const& key;
    T& value;

    MapElem(std::pair<K const, T>& pair)
        : key(pair.first)
        , value(pair.second)
    { }

    MapElem(const std::pair<K const, std::remove_const_t<T>>& pair)
        : key(pair.first)
        , value(pair.second)
    { }
};

for ( MapElem<int, const std::string> kv : my_map ){
    std::cout << kv.key << " --> " << kv.value;
}

It's a mess. Best thing for now is to just get used to writing .first and .second and hope that the structured bindings proposal passes, which would allow for what you really want:

for (auto&& [key, value] : my_map) {
    std::cout << key << " --> " << value;
}

Sessions and object lifetimes--Andrzej Krzemieński

How will you move?

Sessions and object lifetimes

by Andrzej Krzemieński

From the article:

In this post we will see how C++ object lifetime can be used to control the duration of sessions: time spent owing and using a resource. The goal is to get a better understanding of what tools the language offers for using and sharing resources efficiently...

CppCast Episode 52: Macchina.io with Günter Obiltschnig

Episode 52 of CppCast the only podcast for C++ developers by C++ developers. In this episode Rob and Jason are joined by Günter Obiltschnig to discuss the macchina.io library for IoT C++ development.

CppCast Episode 52: Macchina.io with Günter Obiltschnig

by Rob Irving and Jason Turner

About the interviewee:

Günter is the founder of the POCO C++ Libraries and macchina.io open source projects. He has been programming computers since age 12. In his career he has programmed everything from 8-bit home computers (C64, MSX) to IBM big iron systems (COBOL and JCL, VM/CMS and CICS), various Unix systems, OpenVMS, Windows NT in its various incarnations, the Mac (classic Mac OS and OS X), to embedded devices and iPhone/iPad. He has a diploma (MSc. equivalent) in Computer Science from the University of Linz, Austria.

His current main interests are embedded systems, cross-platform C++ development, JavaScript and, foremost, the Internet of Things. When not working, he spends time with his family or enjoys one of his hobbies — sailing, running, swimming, skiing, listening to or making music, and reading.

CppCon opens Call for Submissions

CppCon has announced its call for submission for 2016. 

CppCon: The C++ Conference

Call for Submission

From the announcement:

The deadline for submissions is May 22nd and the conference face gathering for the entire C++ community. The conference is organized by the C++ community for the community and so we invite you to present.

 

Using C++ Coroutines to simplify async UWP code--Eric Mittelette

The async pattern needed to write UWP apps (or simply "Universal apps") is not so easy to grasp, especially in C++. Eric from the Visual C++ team explains how the experimental Coroutines feature available in Visual Studio 2015 helps simplify async UWP code:

Using C++ Coroutines to simplify async UWP code

From the article:

C++ Coroutines can simplify your async code, and make the code easy to understand, write, and maintain...

C++ Weekly Episode 5: Intro To ChaiScript

Episode 5 of C++ Weekly with Jason Turner.  

Intro To ChaiScript

by Jason Turner

About the show:

In this episode Jason shows some basic getting started with ChaiScript code and goes over some of the more interesting features of the language.