February 2015

C++17 Library Papers for Cologne

The first part of a mini series about the Library Papers for the LWG Meeting in Cologne:

C++17 Library Papers for Cologne

by Jens Weller

From the article:

Last fall I did the last series about the Standardization papers for C++. I didn't had the time to finish the last part for the Library subgroup, as Meeting C++ 2014 was getting close too. I'll be attending the next meeting of the Library Working Group in Cologne, which is just a few days away, so I'll do a miniseries for the LWG papers...

Default Constructed Return Value: return {} -- Adi Shavit

Simplify your code using a default constructed return value with `return {}`:

Default Constructed Return Value: return {}

by Adi Shavit

From the article:

It is common for C/C++ functions to return default values, for example, if some internal condition fails.
This is straightforward for native return types. This pattern is often seen in factory methods or functions that return a polymorphic type via a base handle.

If the function has multiple early return points, this default construction needs to be repeated at each such point and each time stating the explicit return type just for calling the default ctor. This is annoying because the compiler already knows the return type.

CppCon 2014 Persisting C++ Classes in Relational Databases with ODB--Boris Kolpackov

While we wait for CppCon 2015 in September, we’re featuring videos of some of the 100+ talks from CppCon 2014. Here is today’s feature:

Persisting C++ Classes in Relational Databases with ODB

by Boris Kolpackov

(watch on YouTube) (watch on Channel 9)

Summary of the talk:

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.

Ranges and Iterators for numerical problems

A guest blog post by Karsten Ahnert at Meeting C++ as a follow up of his talk!

Ranges and Iterators for numerical problems

by Karsten Ahnert

From the article:

In this blog post I am going to show some ideas how one can implement numerical algorithms with ranges. Examples are the classical Newton algorithm for finding the root of a function and ordinary differential equations. The main idea is to put the main loop of the algorithm into range such that the user can...

ODB C++ ORM 2.4.0 Released, Adds Bulk Operations Support

ODB C++ ORM 2.4.0 Released, Adds Bulk Operations Support

by Boris Kolpackov

ODB is an open source 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 of the mapping code.

Major new features in this release:

  • Support for bulk operations in Oracle and SQL Server. Bulk operations can be used to persist, update, or erase a range of objects using a single database statement execution which often translates to a significantly better performance.
  • Ability to join and load one or more complete objects instead of, or in addition to, a subset of their data members with a single SELECT statement execution (object loading views).
  • Support for specifying object and table join types in views (LEFT, RIGHT, FULL, INNER, or CROSS).
  • Support for calling MySQL and SQL Server stored procedures.
  • Support for defining persistent objects as instantiations of C++ class templates.

A more detailed discussion of these features can be found on the blog. For the complete list of new features in this version see the official release announcement.

ODB is written in portable C++ (both C++98/03 and C++11 are supported) and you should be able to use it with any modern C++ compiler. In particular, we have tested this release on GNU/Linux (x86/x86-64/ARM), Windows (x86/x86-64), Mac OS X (x86/x86_64), and Solaris (x86/x86-64/SPARC) with GNU g++ 4.2.x-5.x, MS Visual C++ 2005, 2008, 2010, 2012, and 2013, Sun Studio 12u2, and Clang 3.x.

The currently supported database systems are MySQL, SQLite, PostgreSQL, Oracle, and SQL Server. ODB also provides optional profiles for Boost and Qt, which allow you to seamlessly use value types, containers, and smart pointers from these libraries in your persistent classes.

More information, documentation, source code, and pre-compiled binaries are available on the project's page.

How do I write complex initialization?--Stack Overflow

Quick A: Initialize it using a lambda that’s invoked immediately.

Recently on SO:

Best practice for declaring variable without initialising it, so auto is unavailable

I want to declare two variables of the same type, and have the compiler figure out the types. However I don't want to initialise one of the variables until later. I don't think I can use auto here, so what's the best option?

std::vector<int> v;

// `start` and `end` should be the same type
auto start = v.begin();
??? end;

// complicated code to assign a value to `end` (i.e. putting
// the code in a function or using ?: is not practical here) 
if (...) {
    end = ...;
} else {
    end = v.end();
}

What's the best way to tell the compiler that end should be the same type as start, but without having to initialise the variable?

auto start = v.begin(), end;  // Doesn't work, `end` has to be initialised
decltype(start) end;          // Does work, but not sure if it's best practice

Update

A couple of comments have suggested ways that would work in certain situations, so I am clarifying my situation here:

std::vector<int> v;
int amount = 123;

// `start` and `end` should be the same type
auto start = v.begin();
??? end;

// code to assign a value to `end`
if (amount) {
    end = start + amount;
    amount = 0;
} else {
    end = v.end();
}

I believe a lamda function would be trickier here, because amount is being reset to 0 after end is calculated, so in a lamda function that calculates a value for end, amount = 0 would have to come after the return statement. The only option would be to create more local variables, which would incur an (admittedly tiny) performance penalty.

The Rule of Zero revisited: The Rule of All or Nothing--Arne Mertz

In this article you will find a new rule of thumb:

The Rule of Zero revisited: The Rule of All or Nothing

by Arne Mertz

From the article:

In 2012, Martinho Fernandes coined the Rule of Zero in a blog post. In 2014, Scott Meyers wrote a blog post about a concern with that rule and proposed a Rule of Five Defaults.

Back then, I had written a small comment on Scott’s post that deserves some further elaboration. In this post I am going to wrap up my thoughts about the two posts and propose a “Rule of All or Nothing”...

the asynchronous library - Christophe Henry @ Meeting C++ 2014

A new video from Meeting C++ 2014:

the asynchronous library

by Christophe Henry

From the talk description:

An infrastructure library on which Boost Meta State Machine can build. This will be provided by the Asynchronous library: Active Objects, proxies, threadpools, parallelization algorithms, work-stealing, distributed programming...

2015-02 mid-meeting mailing available

The 2015-02 mailing of new standards papers is now available.

NOTE: A number of these papers have already been publicized on this blog. This is the complete list including ones not previously publicized.

 

WG21 Number Title Author Document Date Mailing Date Previous Version Subgroup Disposition
N4340 Remove Deprecated Use of the register Keyword Alisdair Meredith 2014-11-26 2015-02   Evolution  
N4341 C++ Standard Library Active Issues List (Revision R92) Alisdair Meredith   missing   Library  
N4342 C++ Standard Library Defect Report List (Revision R92) Alisdair Meredith   missing   Library  
N4343 C++ Standard Library Closed Issues List (Revision R92) Alisdair Meredith   missing   Library  
N4344 Suggested Design for Customization Points Eric Niebler   missing   Library  
N4345 Ranges for the Standard Library, Revision 2 Eric Niebler   missing   Library  
N4346 Multidimensional bounds, index and array_view, revision 5 Lukasz Mendakiewicz 2015-01-05 2015-02 N4177 Library  
N4347 Responses to National Body Comments, PDTS 19568, Library Fundamentals Barry Hedquist   missing      
N4348 Making std::function thread-safe Geoffrey Romer 2015-02-02 2015-02 N4159 Library  
N4349 Minutes of WG21 Telecon Jonathan Wakely 2014-12-05 2015-02      
N4350 Agenda and Meeting Notice for WG21 Concepts Meeting Notice (revision 1) Herb Sutter 2015-01-15 2015-02 N4339    
N4351 Responses to National Body Comments, PDTS 19570, C++ Extensions for Parallelism Barry Hedquist 2014-12-23 2015-02      
N4352 Parallelism TS Jared Hoberock 2015-01-08 2015-02 N4310    
N4353 Parallelism TS - Editor's Report Jared Hoberock 2015-01-08 2015-02      
N4354 Parallelism TS - DTS Ballot Document Jared Hoberock 2015-01-08 2015-02      
N4355 Shared Multidimensional Arrays with Polymorphic Layout Carter Edwards 2015-02-04 2015-02   Library  
N4356 Relaxed Array Type Declarator Carter Edwards 2015-02-04 2015-02   Evolution  
N4357 Introduce the [[noexit]] attribute for main as a hint to eliminate destructor calls for objects with static storage duration Jens Maurer 2015-01-19 2015-02 N4226 Evolution  
N4358 Unary Folds and Empty Parameter Packs Thibaut Le Jehan 2015-01-20 2015-02   Evolution  
N4359 A Proposal to Add vector release method just like unique_ptr release method to the Standard Library Jerry Liang 2015-01-09 2015-02   Library  
N4360 Delayed Evaluation Parameters Douglas Boffey 2015-01-22 2015-02   Evolution  
N4361 Concepts Lite TS Andrew Sutton 2015-01-27 2015-02 N4333    
N4362 WG21 2015-01 Skillman Minutes John Spicer 2015-01-27 2015-02      
N4363 Library Fundamentals v1 DTS Jeffrey Yasskin   missing      
N4364 Editor's Report for the Library Fundamentals v1 DTS Jeffrey Yasskin   missing      
N4365 Responses to National Body Comments, ISO/IEC PDTS 19568, C++ Extensions for Library Fundamentals Barry Hedquist 2015-01-29 2015-02      
N4366 LWG 2228: Missing SFINAE rule in unique_ptr templated assignment Howard Hinnant 2015-01-11 2015-02   Library  
N4367 Comparison in C++ Lawrence Crowl 2015-02-08 2015-02   Evolution  
N4368 Introducing alias size_type for type size_t in class std::bitset Vladimir Grigoriev 2015-02-03 2015-02   Library evolution  
N4369 Default argument for second parameter of std::advance Vladimir Grigoriev 2015-01-12 2015-02   Library evolution  
N4370 Networking Library Proposal (Revision 4) Christopher Kohlhoff 2015-02-06 2015-02 N4332 Library  
N4371 Minimal incomplete type support for standard containers, revision 2 Zhihao Yuan 2015-02-04 2015-02 N4056 Library  
N4372 A Proposal to Add a Const-Propagating Wrapper to the Standard Library Jonathan Coe 2015-02-06 2015-02 N4209 Library  
N4373 Atomic View Carter Edwards, Hans Boehm 2015-01-26 2015-02 N4142 Library  
N4374 Linux-Kernel Memory Mode Paul E. McKenney 2015-02-06 2015-02 N4322 Concurrency  
N4375 Out-of-Thin-Air Execution is Vacuous Paul E. McKenney 2015-02-06 2015-02 N4323 Concurrency  
N4376 Use Cases for Thread-Local Storage Paul E. McKenney 2015-02-06 2015-02 N4324 Concurrency  
N4377 C++ Extensions for Concepts PDTS Andrew Sutton 2015-02-09 2015-02      
N4378 Language Support for Contract Assertions John Lakos, Nathan Myers, Alexei Zakharov, Alexander Beels 2015-02-08 2015-02   Evolution  
N4379 FAQ about N4378, Language Support for Contract Assertions John Lakos, Nathan Myers 2015-02-08 2015-02   Evolution  
N4380 Constant View: A proposal for a std::as_const helper function template ADAM David Alan Martin, Alisdair Meredith 2015-02-05 2015-02   Library  

CppCon 2014 How HHVM Uses Modern C++ for Fun and Profit (Literally)--Drew Paroski

While we wait for CppCon 2015 in September, we’re featuring videos of some of the 100+ talks from CppCon 2014. Here is today’s feature:

How HHVM Uses Modern C++ for Fun and Profit (Literally)

by Drew Paroski

(watch on YouTube) (watch on Channel 9)

Summary of the talk:

HHVM is a just-in-time compiler for PHP used by Facebook to serve billions of requests each day. This talk will give a quick overview of HHVM's history and architecture, followed by a deep dive into what made C++ the language of choice for writing HHVM.

C++ hits a sweet spot between performance and control on one end, and safety, maintainability, and convenience on the other.

The topics we’ll cover will include:
how to call into generated machine code from C++;
taking advantage of C++'s power to control "unsafe" details with memory including how memory is allocated, field size and layout, unions, reinterpret_casts, bit-stealing;
integrating generated machine code with C++ exception handling and C++ profiling tools;
leveraging templates and using the X Macro technique to improve performance and maintainability;
and taking advantage of new C++11 features like unrestricted unions and move constructors.
Finally, we'll go over some obstacles we encountered such as generating machine code that calls C++ virtual methods, and how C++'s superb flexibility allowed us to work around these obstacles.