C++ User Group Meetings in December

The monthly listing of upcoming C++ User Group Meetings on Meeting C++:

C++ User Group Meeting in December 2015

by Jens Weller

From the article:

The montly overview on C++ User Group meetings, this time for December. Meeting C++ is just a few days away, so I'm excited to see that again, so many groups are meeting. Also there are few new user groups worth mentioning! 2 x India (Delhi, Udaipur), Sydney, Beijing, Zürich, Sacramento and Ann Arbor! A new trend seems to be to form learning groups and meet weekly for a in depth C++ tutorial...

Quick Q: Why destructor disabling the generation of implicit move functions?

Quick A: Because it means that your class is handling a ressource, thus the compiler cannot know how to move.

Recently on SO:

Why destructor disabling the generation of implicit move functions?

"The Rule of Zero" is in fact about something else than what special member functions are generated and when. It is about a certain attitude to class design. It encourages you to answer a question:

Does my class manage resources?

If so, each resource should be moved to its dedicated class, so that your classes only manage resources (and do nothing else) or only accumulate other classes and/or perform same logical tasks (but do not manage resources).

It is a special case of a more general Single Responsibility Principle.

When you apply it, you will immediately see that for resource-managing classes you will have to define manually move constructor, move assignment and destructor (rarely will you need the copy operations). And for the non-resource classes, you do not need to (and in fact you probably shouldn't) declare any of: move ctor/assignment, copy ctor/assignment, destructor.

Hence the "zero" in the name: when you separate classes to resource-managing and others, in the "others" you need to provide zero special member functions (they will be correctly auto-generated.

There are rules in C++ what definition (of a special member function) inhibits what other definitions, but they only distract you from understanding the core of the Rule of Zero.

For more information, see:

Quick Q: const-reference qualified member function

Quick A: Delete the r-value reference overload of the function.

Recently on SO:

const-reference qualified member function

A temporary can be bound to a const& qualified object and the ref-qualifier effectively qualifies the implicitly passed object (*this). If you want to prevent calls on temporaries but allow lvalues, you can = delete the rvalue reference overload and implement the lvalue version. Using const qualified reference qualifiers for both operators requires just one implemented and one = deleted implementation:

class File {
    // ...
    FILE* _file;
public:
    operator FILE*() const&& = delete;
    operator FILE*() const& { return this->_file; }
    // ...
};

The net-effect is that you can use the conversion only for objects to which you go an lvalue:

int main() {
    File       f;
    File const cf{};

    FILE* fp = f;              // OK
    FILE* cfp = cf;            // OK
    FILE* tfp = File();        // ERROR: conversion is deleted
    FILE* mfp = std::move(cf); // ERROR: conversion is deleted 
}

Quick Q: std::timed_mutex::try_lock* fail spuriously

Quick A: it is authorized to do so for performance reasons.

Recently on SO:

Quick Q: std::timed_mutex::try_lock* fail spuriously

According to: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2010/n3209.htm

On the other hand, there are strong reasons to require that programs be written to tolerate spurious try_lock() failures:

  1. As pointed out in Boehm, Adve, "Foundations of the C++ Concurrency Memory Model", PLDI 08, enforcing sequential consistency for data-race-free programs without spurious try_lock() failures requires significantly stronger memory ordering for lock() operations on try_lock()-compatible mutex types. On some architectures that significantly increases the cost of uncontended mutex acquisitions. This cost appears to greatly outweigh any benefit from prohibiting spurious try_lock() failures.
  2. It allows a user-written try_lock() to fail if, for example, the implementation fails to acquire a low-level lock used to protect the mutex data structure. Or it allows such an operation to be written directly in terms of compare_exchange_weak.
  3. It ensures that client code remains correct when, for example, a debugging thread is introduced that occasionally acquires locks in order to be able to read consistent values from a data structure being checked or examined. Any code that obtains information from try_lock() failure would break with the introduction of another thread that purely locks and reads the data structure.

CppCast Episode 35: CppCon Wrapup with Jon Kalb

Episode 35 of CppCast the only podcast for C++ developers by C++ developers. In this episode Rob and Jason are joined by Jon Kalb to talk about this year's Cppcon, his trip to the Kona standards committee meeting and much more.

CppCast Episode 35: CppCon Wrapup with Jon Kalb

by Rob Irving and Jason Turner

About the interviewee:

Jon has been writing C++ for two and half decades and does onsite C++ training. He chairs the CppCon and C++Now conferences and the C++ Track for the Silicon Valley Code Camp. He serves as chair of the Boost Libraries Steering Committee and is a Microsoft MVP.

Overload resolution -- Andrzej KrzemieĊ„ski

An introduction to function template specialization, function (template) overloading, argument dependent lookup (ADL) and overload resolution:

Overload resolution

by Andrzej Krzemieński

From the article:

This post is an introduction to another one that I intend to write in the future...

Announcing the VS GDB Debugger extension--Marc Goodner

Annoucing a new tool in Visual Studio:

Announcing the VS GDB Debugger extension

by Marc Goodner

From the article:

Earlier this year I wrote a post on how you could debug C++ code on Linux from Visual Studio. It was a bit cumbersome, but it was doable. Today we are releasing the Visual Studio GDB Debugger extension preview. This will enable debugging remote Linux targets including IoT devices...

2015-11 post-Kona mailing available

The 2015-11 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
SD-1 2015 PL22.16/WG21 document list John Spicer 2015-11-16 2015-11      
2015-11 post-Kona
N4553 Working Draft, C++ extensions for Concepts Andrew Sutton 2015-10-02 2015-11 N4549 Concepts  
N4554 Editor's report for the Concepts TS Andrew Sutton 2015-10-02 2015-11   Concepts  
N4555 February 2016 WG21 Meeting Barry Hedquist 2015-10-09 2015-11      
N4556 WG21 telecon minutes Marhsall Clow 2015-10-09 2015-11      
N4557 WG21 2015-07-20 Telecon (revised) Roger Orr 2015-10-24 2015-11      
N4558 Kona WG21 Minutes Jonathan Wakely 2015-11-16 2015-11      
N4559 Kona PL22.16 Minutes Jonathan Wakely 2015-11-16 2015-11      
N4560 Working Draft, C++ Extensions for Ranges Eric Niebler, Casey Carter 2015-11-06 2015-11      
N4561 Ranges Editor's Report Eric Niebler 2015-11-05 2015-11      
N4562 Working Draft, C++ Extensions for Library Fundamentals, Version 2 Geoffrey Romer 2015-11-05 2015-11 N4529    
N4563 Editor's Report for the Library Fundamentals TS Geoffrey Romer 2015-11-05 2015-11      
N4564 C++ Extensions for Library Fundamentals, Version 2 PDTS Geoffrey Romer 2015-11-05 2015-11      
N4565 Record of Response: National Body Comments ISO/IEC PDTS 19571 Technical Specification: C++ Extensions for Concurrency Barry Hedquist 2015-11-06 2015-11      
N4566 Editor's Report -- Working Draft, Standard for Programming Language C++ Richard Smith 2015-11-09 2015-11      
N4567 Working Draft, Standard for Programming Language C++ Note: Richard Smith 2015-11-09 2015-11 N4527    
P0001R1 Removing Deprecated Register Keyword Alisdair Meredith 2015-10-21 2015-11 P0001R0 Core Adopted 2015-10
P0002R1 Removing Deprecated Operator++ for bool Alisdair Meredith 2015-10-23 2015-11 P0002R0 Core Adopted 2015-10
P0004R1 Removing Deprecated Aliases in iostreams Alisdair Meredith 2015-10-19 2015-11 P0004R0 Library Evolution  
P0005R1 Adopt not_fn from Library Fundamentals 2 for C++17 Alisdair Meredith, Stephan T. Lavavej, Tomasz Kamiński 2015-10-18 2015-11 P0005R0 Library Revised P0005R2
P0005R2 Adopt not_fn from Library Fundamentals 2 for C++17 Alisdair Meredith, Stephan T. Lavavej, Tomasz Kamiński 2015-10-23 2015-11 P0005R1 Library  
P0007R1 Constant View: A proposal for a std::as_const helper function template ADAM David Alan Martin, Alisdair Meredith 2015-10-22 2015-11 P0007R0 Library Evolution  
P0012R1 Make exception specifications be part of the type system, version 5 Jens Maurer 2015-10-22 2015-11 P0012R0   Adopted 2015-10
P0013R1 Logical Operator Type Traits (revison 1) Jonathan Wakely 2015-10-23 2015-11 P0013R0 Library Evolution Adopted 2015-10
P0014R1 Proposal to add the multiline option to std::regex for its ECMAScript engine Nozomu Katō 2015-10-30 2015-11 P0014R0 Library Evolution  
P0017R1 Extension to aggregate initialization Oleg Smolsky 2015-10-24 2015-11 P0017R0 Evolution  
P0018R1 Lambda Capture of *this by Value H. Carter Edwards, Christian Trott, Hal Finkel, Jim Reus, Robin Maffeo, Ben Sander 2015-10-23 2015-11 P0018R0 Evolution  
P0022R1 Proxy Iterators for the Ranges Extensions Eric Niebler 2015-11-06 2015-11 P0022R0 Library  
P0025R1 An algorithm to "clamp" a value between a pair of boundary values Martin Moene, Niels Dekker 2015-10-29 2015-11 P0025R0 Library  
P0030R1 Proposal to Introduce a 3-Argument Overload to std::hypot Benson Ma 2015-11-06 2015-11 P0030R0 Library  
P0032R1 Homogeneous interface for variant, any and optional (Revision 1) Vicente J. Botet Escriba 2015-11-05 2015-11 P0032R0 Library Evolution  
P0051R1 C++ generic overload function (Revision 1) Vicente J. Botet Escriba 2015-11-05 2015-11 P0051R0 Library Evolution  
P0057R1 Wording for Coroutines Gor Nishanov 2015-11-06 2015-11 P0057R0 Core, Library Evolution  
P0061R1 __has_include for C++17 Clark Nelson 2015-10-23 2015-11 P0061R0   Adopted 2015-10
P0083R1 Splicing Maps and Sets (Revision 3) Alan Talbot, Jonathan Wakely, Howard Hinnant, James Dennett 2015-11-07 2015-11 P0083R0 Library Evolution  
P0092R1 Polishing Howard Hinnant 2015-10-20 2015-11 P0092R0 Library Evolution  
P0100R1 Comparison in C++ Lawrence Crowl 2015-11-07 2015-11 P0100R0 Library Evolution  
P0112R1 Networking Library (Revision 7) Christopher Kohlhoff 2015-10-23 2015-11 P0112R0 Library Evolution Adopted 2015-10
P0136R1 Rewording inheriting constructors (core issue 1941 et al) Richard Smith 2015-10-19 2015-11 P0136R0 Core Adopted 2015-10
P0144R0 Structured Bindings Herb Sutter 2015-10-14 2015-11   Evolution  
P0145R0 Expression Order of Evaluation Gabriel Dos Reis, Herb Sutter, Jonathan Caves 2015-10-01 2015-11   Evolution  
P0147R0 The Use and Implementation of Contracts Lawrence Crowl 2015-11-08 2015-11   Evolution  
P0148R0 memory_resource_ptr: A Limited Smart Pointer for memory_resource Correctness Pablo Halpern, Dietmar Kühl 2015-10-14 2015-11   Library Evolution  
P0151R0 Proposal of Multi-Declarators Andrew Tomazos 2015-10-16 2015-11   Evolution  
P0152R0 constexpr atomic::is_always_lock_free Olivier Giroux, JF Bastien, Jeff Snyder 2015-10-21 2015-11 N4509 Concurrency  
P0153R0 std::atomic_object_fence(mo, T&&...) Olivier Giroux, JF Bastien 2015-11-05 2015-11 N4522    
P0154R0 constexpr std::thread::hardware_{true,false}_sharing_size JF Bastien, Olivier Giroux 2015-10-24 2015-11 N4523    
P0155R0 Task Block R5 Pablo Halpern, Arch Robison, Hong Hong, Artur Laksberg, Gor Nishanov, Herb Sutter 2015-10-22 2015-11 N4411 Library Adopted 2015-10
P0156R0 Variadic lock_guard (Rev. 3) Mike Spertus 2015-10-21 2015-11 N4498 Evolution  
P0157R0 Handling Disappointment in C++ Lawrence Crowl 2015-11-07 2015-11   Evolution  
P0158R0 Couroutines belong in a TS Jamie Allsop, Jonathan Wakely, Christopher Kohlhoff, Anthony Williams, Roger Orr, Andy Sawyer, Jonathan Coe, Arash Partow 2015-11-06 2015-11   Evolution  
P0159R0 Draft of Technical Specification for C++ Extensions for Concurrency Artur Laksberg 2015-10-22 2015-11     Adopted 2015-10
P0160R0 Wording for removing defaults for unary folds Jens Maurer 2015-10-23 2015-11   Core  
P0162R0 A response to "P0055R0: On Interactions Between Coroutines and Networking Library" Christopher Kohlhoff 2015-11-06 2015-11      
P0163R0 shared_ptr::weak_type Arthur O'Dwyer 2015-10-23 2015-11   Library Evolution  
P0164R0 Core Language Working Group "ready" Issues William M. Miller 2015-10-23 2015-11   Core Adopted 2015-10
P0165R0 C++ Standard Library Issues to be moved in Kona Marshall Clow 2015-10-23 2015-11   Library Adopted 2015-10
P0166R0 Three interesting questions about contracts J. Daniel Garcia 2015-11-06 2015-11   Evolution  
P0167R0 Core Language Working Group "ready" Issues after the October, 2015 (Kona) meeting William M. Miller 2015-11-10 2015-11   Core  
P0169R0 regex and Unicode character types Nozomu Katō 2015-11-03 2015-11   Library evolution  
P0170R0 Wording for Constexpr Lambda Faisal Vali 2015-11-01 2015-11 N4487 Evolution  
P0171R0 Response To: Resumable Expressions P0114R0 Gor Nishanov 2015-11-06 2015-11   Evolution  
P0172R0 Abominable Function Types Alisdair Meredith 2015-11-10 2015-11   Library Evolution