July 2014

N4127: Checked-dereference conditions -- Eelis van der Weegen

A new WG21 paper is available. If you are not a committee member, please use the comments section below or the std-proposals forum for public discussion.

Document number: N4127

Date: 2014-07-20

Checked-dereference conditions

by Eelis van der Weegen

Excerpt:

This is a proposal to add a new form of condition...

For example,  if (T x : e) s  translates to  if (auto && __p = e) { T x = *__p; s }  for some invisible name __p.

Translation for the new form of condition in a while or for loop is analogous.

The "next generation" version where the type defaults to auto && is also proposed.

CppCon Third Keynote -- Boris Kolpackov

CppCon has announced its third keynote, filling out the keynote slots for this year’s event. It’s by respected gaming industry veteran Mike Acton on data-oriented design, which is essential for high performance -- or even reasonable performance -- on modern systems from servers to smartphones.

If you're wondering why data-oriented design is so 'essential,' as a backgrounder check out slides 31-37 of Herb Sutter's April 2014 talk and the cited example of a 50x performance difference achieved by doing nothing but changing the order of objects in memory. That's just an appetizer for Acton's keynote, and it's applicable to way more than gaming.

You won't want to miss this or any of this year's other keynotes and over 100 sessions in the 2014 program. From the announcement:

Data-Oriented Design and C++

by Mike Acton

The transformation of data is the only purpose of any program. Common approaches in C++ which are antithetical to this goal will be presented in the context of a performance-critical domain (console game development). Additionally, limitations inherent in any C++ compiler and how that affects the practical use of the language when transforming that data will be demonstrated.

Speaker’s bio: Mike Acton is Engine Director at Insomniac Games. When he’s not searching for new ways to optimize Insomniac’s engine, he dreams up new ways to help the development community. Mike can often be found extolling the virtues of understanding the data and hardware first along with programming for performance.

Inheriting Constructors in C++11 -- 741MHz

Following up on Monday's linked article:

Inheriting Constructors in C++11

by 741MHz

From the article:

Delegating Constructors [... are] extremely useful in boosting efficiency, [but] it does not solve the problem when programmer wants to create a derived class that has exactly the same set of constructor as its base class or classes. In which case programmers are forced to tediously duplicate constructors of the base class...

C++11 solves this problem by introducing constructor inheritance. In a derived class, programmers can write a single using T::T; statement that makes a derived class automatically inherit constructors of a base class. For example: ...

Trip Report: C++ Standards Committee Meeting in Rapperswil, June 2014 -- Botond Ballo

Here's one participant's view of the recent standards meeting with some interesting personal perspective.

Trip Report: C++ Standards Committee Meeting in Rapperswil, June 2014

by Botond Ballo

From the article:

Last [month] I attended another meeting of the ISO C++ Standards Committee in Rapperswil, Switzerland (near Zurich). This is the third Committee meeting I have attended; you can find my reports about the previous two here (September 2013, Chicago) and here (February 2014, Issaquah). These reports, particularly the Issaquah one, provide useful context for this post.

With C++14′s final ballot being still in progress, the focus of this meeting was the various language and library Technical Specifications (TS) that are planned as follow-ups to C++14, and on C++17. ...

CppCon Program Highlights, 6 of N -- The Rubber and the Road

The CppCon 2014 conference program has been posted for the upcoming September conference. We've received requests that the program continue to be posted in "bite-sized" posts, a few sessions at a time, to make the 100+ sessions easier to absorb, so here is another set of talks. This series of posts will conclude once the entire conference program has been posted in this way.

 

C++ developers live where the rubber meets the road, and so CppCon features lots of solid real-world rubber-meets-the-road technical content. Here are specific topics that likely apply to your codebase today, presented by the people who solving these problems today in demanding environments ranging from working on the world's fastest databases to the world's leading financial systems.

In this post:

  • Common-Sense Acceleration of Your MLOC Build
  • C++11 in the Wild: Techniques from a Real Codebase
  • Making Allocators Work

 

Common-Sense Acceleration of Your MLOC Build

In this talk, I lay out detailed examples of steps I took to dramatically improve build times, and ultimately developer productivity, in very large, legacy C/C++ codebases. Is it worth the extra money for SSD or a 15K RPM SAS? How do I make ccache and distcc work together? How do I profile-optimize my toolchain? What network topology issues come into play? These questions, and more, are addressed in detail so you can immediately apply what you've learned to shorten the timeline between when you make a change to your code and when you see it in action.

Speaker: Matt Hargett, CTO, PacerPro. Matt Hargett is Chief Technology Officer at PacerPro, and lives in San Francisco with his husband of 14 years. His first programming was on a TI 99/4a with his mother, and his first reverse engineering was on an 8086 to make shareware games easier to finish. Matt co-authored Pragmatic Unit Testing in C#, and has spoken at conferences around the world on network security, reverse engineering, unit testing, and static analysis. His hobbies include world travel, playing video games, and writing/publishing indie pop songs under the moniker "the making of the making of."

 

C++11 in the Wild: Techniques from a Real Codebase

This talk presents several reusable constructs from a production C++11 codebase, each of which would not be possible without C++11's new features. Auto() is what Alexandrescu's ScopeGuard looks like after a dozen years of C++ evolution. make_iterable() constructs a container from a pair of iterators, enabling simple "foreach" iteration over legacy containers. spaceship() is an efficient "strcmp" for tuples. Time permitting, we'll look at some more arcane code samples.

Speaker: Arthur O'Dwyer, MemSQL. Arthur O'Dwyer worked for many years at Green Hills Software, making the world's most optimizing C and C++ compilers. Now he works at MemSQL, making the world's fastest distributed SQL database.

 

Making Allocators Work

Memory is an important property for every object, as whatever resources it manages, it must occupy some memory. THe ability to customize memory allocation is important for every C++ program that cares about performance, debug ability and support.

The original C++ standard supported an allocator parameter for every container, yet this feature was widely derided or ignored, as it was underspecified to the point it could not portably be used. C++11 makes significant changes to the allocator model, that simply its use while making it more powerful.

The Library Fundamentals TS goes further, allowing allocators' type to be supplied at runtime, rather than compile type, using classic object oriented polymorphism - yet building on the infrastructure laid down in C++11.

This material should be of interest to both library authors and consumers, although clearly there are more details for the implementers to absorb. It also includes an interesting case study in C++11 compile time reflection, as required to implement the new 'allocator_traits' facility.

Speaker: Alisdair Meredith, Bloomberg LP and ISO C++ Library Working Group Chair. Alisdair Meredith is a software developer at BloombergLP in New York, and the C++ Standard Committee Library Working Group chair. He has been an active member of the C++ committee for just over a decade, and by a lucky co-incidence his first meeting was the kick-off meeting for the project that would become C++11, and also fixed the contents of the original library TR. He is currently working on the BDE project, BloombergLP's open source libraries that offer a foundation for C++ development, including a standard library implementation supporting the polymorphic allocator model proposed for standardization.

 

Delegating Constructors in C++11 -- 741MHz

In case you missed it on 741MHz:

Delegating Constructors in C++11

by 741MHz

From the article:

C++ has caught up with other popular object-oriented languages such as Scala, Java, C# and others when it comes to constructor delegation, a feature that is now supported as per 2011 core language specification of ISO C++. This solves a common problem with repetitive coding, which is tedious and fragile, that C++ programmers had to do in order to provide multiple class constructors.

...

C++11 allows that a constructor of a class type “A” may have an initializer list that invokes another constructor of the same type. Therefore, programmers can get rid of undesirable common initialization function and duplicate all at once by writing the code like this: ...

Boost 1.56.0 beta 1 released

Boost release 1.56.0 beta 1 is now available from SourceForge

This release contains 2 new libraries:

  • Align: Memory alignment functions, allocators, and adaptors, from Glen Fernandes.
  • Type_Index: Runtime/Compile time copyable type info, from Antony Polukhin.

Modularization

Boost version control has migrated to a system using git submodules. This shouldn't make too much of a difference to users, although the directory structure is now a bit different.

Parts of some libraries have been moved into different modules, and several new modules have been extracted from existing code. All header paths should remain the same.

The new modules are:

  • Assert: Customizable assert macros. Maintained by Peter Dimov.
  • Core: Core utilities used by other libraries, with minimal dependencies. Maintained by Peter Dimov, Glen Fernandes and Andrey Semashev.
  • Lexical_Cast: General literal text conversions, such as an int represented a string, or vice-versa, from Kevlin Henney.
  • Throw_Exception: A common infrastructure for throwing exceptions from Boost libraries, from Emil Dotchevski.
  • Winapi: Windows API declarations without <windows.h>, for internal Boost use.

For details of what's in the release, see http://www.boost.org/users/history/version_1_56_0.html.


Note that the links to files on this web page are for the final release - use the SourceForge link above to get the beta files.

Please download the beta, give it a try. If you encounter any problems, please report them on the boost mailing list.

CppCon Program Highlights, 5 of N: Modern C++ and Databases

The CppCon 2014 conference program has been posted for the upcoming September conference. We've received requests that the program continue to be posted in "bite-sized" posts, a few sessions at a time, to make the 100+ sessions easier to absorb, so here is another set of talks. This series of posts will conclude once the entire conference program has been posted in this way.

 

Whether you're using an in-memory flat database or a cloud-scale RDBMS, SQL and ODB databases continue to be a critical layer of modern software. But how do you use them well with modern C++? The following CppCon talks address this question, and as always are presented by the right people -- Those Who Know and Those Who Do, as usual with an international global perspective and including a two-part talk by CppCon's own Boris Kolpackov.

In this post:

  • sqlpp11, An SQL Library Worthy Of Modern C++
  • Persisting C++ Classes in Relational Databases with ODB
  • ODB, Advanced Weapons and Tactics

 

sqlpp11, An SQL Library Worthy Of Modern C++

SQL and C++ are both strongly typed languages. They should play well together. But most C/C++ interfaces to SQL databases are string based. They force the developer to effectively hide the SQL types, names and expression structures from the compiler. This defers the validation of SQL expressions until runtime, i.e. unit tests or even production. And the strings might even be vendor specific, because different databases expect different dialects of SQL in those strings.

That feels wrong. Modern C++ can do better.

This talk gives an introduction to sqlpp11, a templated embedded domain specific language for SQL in C++. It allows you to build type-safe SQL expressions with type-safe results, all of which can be verified at compile time, long before your code enters unit tests or even production.

In addition to its obvious use with relational databases, sqlpp11 can also serve as an SQL frontend for all kinds of data sources: Since sqlpp11 offers complete SQL expression trees even at compile time, it isn't hard to apply SQL expressions to std::vector or std::map for instance, or streams, or XML, or JSON, you name it. With your help, sqlpp11 could become for C++ what LINQ is for C#.

Speaker: Roland Bock, Head of Development, PPRO Financial Ltd., London/Munich.  Roland is Head of Development at PPRO Financial Ltd, an FCA regulated e-Money institute offering prepaid MasterCard card programs and comprehensive financial solutions for international electronic payment transactions. Since 2008 he has been using SQL in C++. Being unhappy with the string-based approach of most SQL libraries, he decided to do something about it and developed a type-safe EDSL for SQL in C++: sqlpp11, see https://github.com/rbock/sqlpp11. In his spare time Roland is preparing sqlpp11 to be proposed for boost and possibly also for the C++ standard. He lives and codes in Munich (Germany). C++ is his preferred language, especially since the arrival of C++11.

 

Persisting C++ Classes in Relational Databases with ODB

ODB is an open source, cross-platform and cross-database (SQLite, PostgreSQL, MySQL, MS SQL Server, Oracle) object-relational mapping (ORM) system for C++. It allows you to persist C++ objects to a relational database without having to deal with tables, columns, or SQL, and without manually writing any mapping code.

In the first part of this two-part talk we will cover the basics of transactionally persisting, loading, updating, and deleting simple C++ classes in a database as well as querying the database for objects. We will then look into persisting C++ classes that have more interesting data members, such as containers and pointers to objects, or that form a polymorphic hierarchy. Support for C++11, Qt, and Boost value types, containers, and smart pointers will also be covered.

Targeting 5 different database systems at the same time may sound like a daunting task but as we will see it is not that hard with ODB. Life would also be a lot easier if our C++ classes never changed. The next best thing is to have comprehensive tooling support. So we will conclude the first half with a discussion of database schema evolution and its support in ODB.

ODB, Advanced Weapons and Tactics

Hiding a relational database behind an ORM does not work. Did I just say that? Yes! Performance and scalability limitations always get in the way. Should we then throw away the whole ORM idea and go back to SQL? We don't have to. In fact, the bulk of ODB features were specifically designed to resolve these limitations without degenerating to JOINs and SQL. And that's what the second part of this talk is all about: bulk operations, object caches, lazy pointers, views, change-tracking containers, optimistic concurrency, object sections (partitions), and prepared and cached queries. By the end of the second half you will be ready for anything that real-world C++ object persistence and database access can throw at you.

Speaker: Boris Kolpackov Boris Kolpackov is a founder and chief software designer at Code Synthesis, a company focusing on the development of open-source tools and libraries for C++. For the past 10 years Boris has been working on solving interesting problems in the context of C++ using domain-specific languages (DSL), C++ parsing, source-to-source translation, and code generation. His notable projects to date include the ODB C++ ORM system as well as XSD and XSD/e XML Schema to C++ compilers.

CppCon Bonus Talk: C++ in MS Office -- Boris Kolpackov

cppcon-051.PNGThe CppCon organizers left a few slots in the CppCon 2014 program for "invited talks" on important but otherwise under-represented topics (such as game development, mobile and embedded systems, etc) or generally interesting and unusual uses of C++. On Tuesday, they announced the first two invited talks on Facebook’s heavy use of C++ in their server infrastructure.

Today, they announced another:

Bonus Talk: C++ in MS Office

by Boris Kolpackov

From the announcement:

Tony Antoun, Igor Zaika: "How Microsoft Uses C++ to Deliver Office (and More) Across iOS, Android, Windows, and Mac"

What does it take to target multiple major mobile devices (as well as traditional environments) with portable, efficient, single-source code? This talk demonstrates architectures, techniques, and lessons learned rooted in actual experience with using C++ to deliver several major cross-platform projects across iOS, Android, Windows, and Mac: Microsoft Office (Word, Excel, PowerPoint, OneNote) and the SQL Server PowerBI. Each presents a different case study: For example, Office already used C++, whereas PowerBI was originally written in Silverlight and then rewritten in C++; Office is a set of user-facing apps, whereas PowerBI is a system component. Although some of these are demanding first-tier “Cadillac” applications, we expect this experience to be a model for the future as more and more apps fall into this category and use C++ to target many popular platforms from (mostly) a single source base.

This talk covers the following key topics and tradeoffs: Rich vs. reach, including access to latest OS features (e.g., iOS 8 additions) and hardware features (e.g., vector units, GPUs). Consistency of functionality. Client code vs. server/service web code. Sharing vs. quality, including dialing appropriately between more shared code and high quality code. Drawing the line between the bulk of C++ code and interfacing with non-C++ for UX and PALs (platform adaptation/abstraction layers) for target-specific user interface and system services. Architecting PALs, including why “mini-PALs” rather than an “über-PAL.” Forcing “doing the right thing” and good architecture with composable components. How C++ enables things not feasible using other technologies. Velocity and enabling faster cross-platform development and deployment. Cost of maintenance, including time, size, and complexity (both breadth and depth). And, last but not least, developing in a single modern C++ source base built with different evolving C++ compilers, including VC++ and Clang/LLVM.

Speakers’ bio: Tony Antoun is Director of Development for APEX, focusing on delivering Office on all Apple platforms and form factors (iPhone, iPad, Mac), as well as aligning the Office experience on other major platforms (Win32, WinRT, Android). Before that, Dev Manager for SQL PowerBI – a cross-platform interactive client data visualization solution (iOS, WinRT, Web) connected to the SQL Reporting cloud service. Before that, Dev Manager for HD-DVD, cross-platform client solution for High Definition interactivity of media experiences (Win32, WinCE, Linux, Xbox).

Igor Zaika is the Development Manager for the Office Core Experience team at Microsoft, responsible for shared UX components and application framework used by Office applications. Before that, Igor worked in various areas related to Office client applications, ranging from building Word Object Model and integrating VBA (Visual Basic for Applications) with Office, to shipping first version of OneNote for the WinRT platform. Before joining Microsoft, Igor worked on 3D CAD application and contributed to the Kronos project.