Metaprogramming with Modern C++: The Haskell Metaphor -- Manu Sánchez

If you are one of who have been following our post series about template metaprogramming with modern C++, at this time you should have become a C++ template Guru. At least thats what I expect wink.

You know about class templates, function templates, value parameters, type parameters, variadic templates… Your template metaprogramming toolbox is full of great things to play with. Thats good, but you want to start playing with your compiler, writting some cool metaprograms.

Metaprogramming with Modern C++: The Haskell Metaphor

by Manu Sánchez

From the article:

Template metaprogramming was used to improve perfomance on high-computing libraries too, with some clever code transformations done thanks to tmp. The best example of this is the blitz++ library, one of the first examples of a real use case of template metaprogramming.

Since C++11 the language has evolved to support some ways of metaprogramming as a common and useful thing. Metaprogramming became a first class citizen in C++, instead of the obscure, magical, and freaking way to abuse the compiler it was at the beginning...

A software design principle: Don’t make me use your design -- Diego Rodríguez-Losada

Developing code in C++ for robotics, I often faced the problem of communicating via serial port with a robot, a sensor or any other device. C and C++ are languages supposedly very close to hardware. Furthermore, they are the most common and oldest mainstream programming languages out there. So communicating over a serial port in a portable way should be straightforward.

A software design principle: Don’t make me use your design

by Diego Rodríguez-Losada

From the article:

I have seen the pattern described in the article a few times in C and C++ projects, but very rarely in other languages (at least those that I have used more as java and python) and I believe there is a reason, not directly related to software design for it: the lack of a widely used dependency manager. And no, OS package managers, installers and so, are not enough to solve this problem. Even if the authors of these libraries decide to decouple the functionality of the SerialPort basic wrapper in their design, there is little gain in it, users should still manually extract those files and integrate them in their projects, which doesn’t sound as reasonable engineering and will produce, for sure, maintenance problems and lack of updates. It is really unlikely that the authors will decide to create a separate project/library for the SerialPort, it is more effort not only to do it in the short term, but also to maintain and work with it in the mid and long terms. So developers just roll out their designs, and fill the functionality in it as required. I’ve done it so many times too...

“Effective Modern C++” from Scott Meyers Review -- CoderGears Team

Today on CoderGrears:

“Effective Modern C++” from Scott Meyers Review

by CoderGears Team

From the article:

This month a new book from Scott Meyers become available, it’s the last one of its Effective software development series (More Effective C++, Effective STL   and Effective C++ ) .

In this book Scott Meyers focus on the new C++11 and C++14 standrads, currently few books talk about them. In the other side many resources are available on the web discussing these new standards. Why I need to read this book?

Here’s our feedback...

The Python API and C++ -- Scott Prager

Some interspecies dating, appropriately on the "multi-paradigm" blog:

The Python API and C++

by Scott Prager

From the article:

Recently, for a job interview task, I was asked to write a Python module with a C or C++ implementation to solve an otherwise simple task. Obviously, I chose C++. While I had never used the Python API before, I found that the existing information on extending Python with C quite sufficient. What surprised me, however, is how little information existed for using C++. A few libraries exist, like Boost.Python, PyCXX, and some utilities that parse C++ to create Python bindings, but I didn't find much in the way of actual information without examining the sources of these libraries. ...

... I have started working on a little utility library (https://github.com/splinterofchaos/py-cxx) for personal use... [The Python C API has] many restrictions and it certainly puts a cramp on C++'s style, but the moral of this store is that just because you need to work with a C API doesn't mean you can't use modern C++ techniques.

N4340: Remove Deprecated Use of the register Keyword -- Alisdair Meredith

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

Document number: N4340

Date: 2014-11-26

Remove Deprecated Use of the register Keyword

by Alisdair Meredith

Excerpt:

The register keyword was deprecated in the 2011 C++ standard, as its effect was already implicit in the language. It remains reserved for future use by the standard, and is time to remove its vestigial specification.

Post-Urbana mailing available

The post-Urbana 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
2014-11-post-Urbana
N4250 WG21 2014-10-24 Telecon Minutes Jonathan Wakely 2014-10-27 2014-11      
N4251 WG21 2014-11 Urbana Minutes Jonathan Wakely 2014-11-21 2014-11      
N4252 PL22.16 2014-11 Urbana Minutes Jonathan Wakely 2014-11-21 2014-11      
N4253 Language Support for Runtime Contract Validation (Revision 9) J. Lakos, A. Zakharov, A. Beels, N. Myers 2014-11-21 2014-11 N4135 Evolution  
N4254 User-defined Literals for size_t and ptrdiff_t Rein Halbersma 2014-11-21 2014-11   Library Evolution  
N4255 Proposed resolution for US104: Allocator-aware regular expressions (rev 3) Mike Spertus 2014-11-03 2014-11 N3254 Library  
N4256 Concurrency TS Working Draft Artur Laksberg   missing N4107 Concurrency  
N4257 Delimited iterators (rev 4) Mike Spertus, Nathan Wilson 2014-11-04 2014-11 N4066 Library Evolution Adopted 2014-11
N4258 Cleaning up noexcept in the Library (Rev 3) Nicolai Josuttis 2014-11-07 2014-11 N4227 Library Adopted 2014-11
N4259 Wording for std::uncaught_exceptions Herb Sutter 2014-11-06 2014-11   Library Adopted 2014-11
N4260 Wording for Atomic Smart Pointers Herb Sutter 2014-11-08 2014-11   Library  
N4261 Proposed resolution for Core Issue 330: Qualification conversions and pointers to arrays of pointers Jens Maurer 2014-11-06 2014-11 N4178 Core Adopted 2014-11
N4262 Wording for Forwarding References Herb Sutter 2014-11-05 2014-11   Core Adopted 2014-11
N4263 Toward a concept-enabled standard library Matt Austern, Gabriel Dos Reis, Eric Niebler, Bjarne Stroustrup, Herb Sutter, Andrew Sutton, Jeffrey Yasskin 2014-11-04 2014-11   Concepts  
N4264 Propogate_const Jonathan Coe   N4209   Library  
N4265 Transactional Memory Support for C++: Wording (revision 3) Jens Maurer 2014-11-07 2014-11   Core  
N4266 Attributes for namespaces and enumerators Richard Smith 2014-11-05 2014-11   Core Adopted 2014-11
N4267 Adding u8 character literals Richard Smith 2014-11-05 2014-11   Core Adopted 2014-11
N4268 Allow constant evaluation for all non-type template arguments Richard Smith 2014-11-05 2014-11   Core Adopted 2014-11
N4269 No sane compiler would optimize atomics JF Bastien   missing   Core  
N4270 Consolidated Revisions to C++ Extensions for Library Fundamentals Alisdair Meredith 2014-11-07 2014-11 N4081 Library Adopted 2014-11
N4271 Minimal Incomplete Type Support for Standard Containers Zhihao Yuan   missing      
N4272 Working Draft, Technical Specification for C++ Extensions for Transactional Memory Michael Wong 2014-11-07 2014-11 N4179 Transactional Memory  
N4273 Uniform Container Erasure (Revision 2) Stephan T. Lavavej 2014-11-06 2014-11   Library Adopted 2014-11
N4274 Relaxing Packaging Rules for Exceptions Thrown by Parallel Algorithms - Proposed Wording (Revision 1) Arch D. Robison, Jared Hoberock, Artur Laksberg 2014-11-14 2014-11 N4157 Concurrency  
N4275 Parallelism PDTS Comment Responses Hans-J. Boehm 2014-11-07 2014-11   Concurrency Adopted 2014-11
N4276 Adding Fused Transform Algorithms to the Parallelism TS Jared Hoberock 2014-11-05 2014-11   Concurrency Adopted 2014-11
N4277 TriviallyCopyable reference_wrapper (Revision 1) Agustín Bergé 2014-11-06 2014-11 N4151 Library Adopted 2014-11
N4278 Concurrency TS Editor's Report Artur Laksberg   missing   Concurrency  
N4279 Improved insertion interface for unique-key maps (Revision 2.3) Thomas Köpp 2014-11-07 2014-11 N4240 Library Adopted 2014-11
N4280 Non-member size() and more (Revison 2) Riccardo Marcangelo 2014-11-06 2014-11 N4155 Library Adopted 2014-11
N4281 C++ Latches and Barriers Alasdair Mackintosh, Olivier Giroux   missing N4204 Library  
N4282 A Proposal for the World's Dumbest Smart Pointer, v4 Walter E. Brown 2014-11-07 2014-11 N3840 Library Adopted 2014-11
N4283 Atomic View Carter Edwards   missing   Concurrency  
N4284 Contiguous Iterators Jens Maurer 2014-11-07 2014-11 N4132 Library Adopted 2014-11
N4285 Cleanup for exception-specification and throw-expression Jens Maurer 2014-11-07 2014-11 N4133 Library Adopted 2014-11
N4286 Resumable Functions (revision 3) Gor Nishanov, Jim Radigan 2014-11-18 2014-11 N4134 Evolution  
N4287 Threads, Fibers and Couroutines (slides deck) Gor Nishanov 2014-11-18 2014-11   Evolution  
N4288 Strike string_view::clear from Library Fundamentals Alisdair Meredith 2014-11-07 2014-11   Library Adopted 2014-11
N4289 Library support for runtime contract violations Nathan Myers   missing   Library  
N4290 Language support for optional contract violations Nathan Myers   missing   Library  
N4291 Language support for block scope assertions Nathan Myers   missing   Library  
N4292 Language support for call-site assertions Nathan Myers   missing   Library  
N4293 C++ language support for contract programming J. Daniel Garcia 2014-11-23 2014-11   Evolution  
N4294 Arrays of run-time bounds as data members J. Daniel Garcia 2014-11-23 2014-11 N3875 Evolution  
N4295 Folding Expressions Andrew Sutton, Richard Smith 2014-11-07 2014-11 N4191 Core Adopted 2014-11
N4296 Working Draft, Standard for Programming Language C++ Richard Smith 2014-11-19 2014-11 N4140    
N4297 Editor's Report -- Programming Languages -- C++ Richard Smith 2014-11-19 2014-11      
N4298 Agenda and Meeting Notice for WG21 Ballot Resolution Telecon Meeting Herb Sutter 2011-11-14 2014-11      
N4299 Source Code Information Capture Robert Douglas   missing      
N4300 Array View Carter Edwards   missing      
N4301 Working Draft, Technical Specification for C++ Extensions for Transactional Memory Michael Wong 2014-11-21 2014-11 N4179    
N4302 Technical Specification for C++ Extensions for Technical Specification for C++ Extensions for Transactional Memory Michael Wong 2014-11-21 2014-11      
N4303 Pointer Safety and Placement New Richard Smith, Hubert Tong 2014-11-21 2014-11   Core  
N4304 C++ Standard Core Language Active Issues, Revision 92 William M. Miller 2014-11-24 2014-11 N4192 Core  
N4305 C++ Standard Core Language Defect Reports and Accepted Issues, Revision 92 William M. Miller 2014-11-24 2014-11 N4193 Core  
N4306 C++ Standard Core Language Closed Issues, Revision 92 William M. Miller 2014-11-24 2014-11 N4192 Core  
N4307 National Body Comment -- ISO/IEC PDTS 19568 -- Technical Specification: C++ Extensions for Library Fundamentals Barry Hedquist 2014-11-12 2014-11      
N4308 National Body Comment -- ISO/IEC PDTS 19570 -- Technical Specification: C++ Extensions for Parallelism Barry Hedquist 2014-11-12 2014-11      
N4309 Return type deduction for explicitly-defaulted and deleted special member functions Michael Price 2014-11-17 2014-11   Evolution  
N4310 Working Draft, Technical Specification for C++ Extensions for Parallelism Jared Hoberock 2014-11-21 2014-11 N4104    
N4311 Parallelism TS Editor's Report Jared Hoberock 2014-11-21 2014-11      
N4312 Programming Languages -- Technical Specification for C++ Extensions for Parallelism Jared Hoberock 2014-11-21 2014-11      
N4313 Improvements to the Concurrency Technical Specification, revision 1 Artur Laksberg 2014-11-21 2014-11 N4123 Concurrency  
N4314 Data-Invariant Functions (revision 2) Jens Maurer 2014-11-15 2014-11 N4145 Library Evolution  
N4315 make_array, revision 3 Zhihao Yuan 2014-11-07 2014-11 N4065 Library  
N4316 std::rand replacement, revision 2 Zhihao Yuan 2014-11-08 2014-11 N4217 Library  
N4317 New Safer Functions to Advance Iterators Patrick Grace 2014-11-17 2014-11   Library Evolution  
N4318 Proposal to add an absolute difference function to the C++ Standard Library Jeremy Turnbull 2014-09-21 2014-11   Library Evolution  
N4319 Contracts for C++: What are the Choices Gabriel Dos Reis, Shuvendu Lahiri, Francesco Logozzo, Thomas Ball, Jared Parsons 2014-11-23 2014-11   Evolution  
N4320 Make exception specifications be part of the type system Jens Maurer 2014-11-20 2014-11   Evolution  
N4321 Towards Implementation and Use of memory_order_consume Paul McKenney 2014-10-05 2014-11 N4215 Concurrency  
N4322 Linux-Kernel Memory Model Paul McKenney 2014-11-20 2014-11   Concurrency  
N4323 Out-of-Thin-Air Execution is Vacuous Paul McKenney 2014-11-20 2014-11 N4216 Concurrency  
N4324 Use Cases for Thread-Local Storage Paul McKenney 2014-11-20 2014-11   Concurrency  
N4325 C++ Standard Evolution Active Issues List (Revision R10) Ville Voutilanen 2014-11-21 2014-11 N4206 Evolution  
N4326 C++ Standard Evolution Completed Issues List (Revision R10) Ville Voutilanen 2014-11-21 2014-11 N4207 Evolution  
N4327 C++ Standard Evolution Closed Issues List (Revision R10) Ville Voutilanen 2014-11-21 2014-11 N4208 Evolution  
N4328 C++ Standard Library Issues History for C++14 Alisdair Meredith 2014-11-24 2014-11   Library  
N4329 C++ Standard Library Active Issues List (Revision R91) Alisdair Meredith 2014-11-24 2014-11 N4245 Library  
N4330 C++ Standard Library Defect Report List (Revision R91) Alisdair Meredith 2014-11-24 2014-11 N4246 Library  
N4331 C++ Standard Library Closed Issues List (Revision R91) Alisdair Meredith 2014-11-24 2014-11 N4247 Library  
N4332 Networking Library Proposal (Revision 3) Christopher Kohlhoff 2014-11-21 2014-11 N4243 Concurrency  
N4333 Concepts Lite Andrew Sutton 2014-11-21 2014-11 N4205 Core  
N4334 Wording for bool_constant Zhihao Yuan 2014-11-21 2014-11   Library  
N4335 Working Draft, C++ Extensions for Library Fundamentals Jeffrey Yasskin 2014-11-21 2014-11 N4081 Library Evolution  
N4336 Working Draft, C++ Extensions for Library Fundamentals, Version 2 Jeffrey Yasskin 2014-11-21 2014-11 N4084 Library Evolution  
N4337 Editor's Report for the Library Fundamentals TS Jeffrey Yasskin 2014-11-21 2014-11   Library Evolution  
N4338 Editor's Report: Technical Specification for C++ Extensions for Transactional Memory Michael Wong 2014-11-21 2014-11   Transactional Memory  
N4339 Agenda and Meeting Notice for WG21 Concepts Meeting Herb Sutter 2014-11-21 2014-11      

 

Free CppCat for Students

CppCat is a static code analyzer integrating into the Visual Studio 2010-2013 environment. The analyzer is designed for regular use and allows detecting a large number of various errors and typos in programs written in C and C++. For the purpose of popularizing it, we've decided to launch a student-support program granting free licenses to every higher school student who will contact and ask us about that. You just need to send us a photo of your student card or transcript.

A few words about static code analysis

Static code analysis tools draw the programmer's attention to those fragments which are very likely to contain errors. Here's a simple example:

double var_z;

....

var_z = ( var_z - 16 / 116 ) / 7.787;

This code is correct from the viewpoint of the language and compiler. It's just a regular situation when division of the integer number 16 by integer number 116 results in 0. Expressions like that are necessary sometimes. However, the analyzer takes a wider perspective of the code and detects an error pattern: if the result of such an integer division is then used together with the double type, it may signal something is wrong.

The analyzer will draw your attention to this suspicious division with the following warning: V636 The '16 / 116' expression was implicitly casted from 'int' type to 'double' type. Consider utilizing an explicit type cast to avoid the loss of a fractional part. An example: double A = (double)(X) / Y;. color.c 125

The code was most likely meant to look as follows:

var_z = ( var_z - 16.0 / 116.0 ) / 7.787;

The division now results in 0,137931 instead of 0.

Static analysis tools can be treated as an extension to compiler warnings. Unlike the compiler, analyzers deal with higher-level constructs and rely on empirical methods trying to guess if the code works the way the programmer wanted it to.

A few words about the CppCat analyzer

CppCat is a static code analyzer which is easy to set and use. It is an excellent tool to get started with the static analysis methodology. It is not as powerful as its big brother PVS-Studio (see their comparison), but it is more than sufficient for most tasks. In any case, CppCat's functionality is surely quite enough for students and single developers.

The analyzer can integrate into Visual Studio 2010, 2012, 2013. Unfortunately, it can't integrate into Express editions and we can't help it as Visual Studio Express editions don't support plugins.

The analyzer supports the following languages: C, C++, C++/CLI, C++/CX.

An important feature of the analyzer is an automated analysis of freshly modified code. After compilation of modified files is finished, CppCat starts analyzing the code in background and displays a warning whenever anything suspicious is found. This feature allows programmers to detect errors at the very early development stage and thus save time on bug search and fixes.

You can download CppCat from the product's website: http://www.cppcat.com

How to get a CppCat license

Using CppCat will help you in acquiring skills of working with static analysis tools and improving your qualification. Static analyzers are growing more and more popular nowadays, so it'll be just good if you can specify in your résumé that you know how to use these tools.

To get a license you just need to send to our email [email protected] a photo or scan of your student card, transcript or other document confirming that you are a higher school student. Please specify your first and second name and the name of your university as it might be very difficult to make out this information from the photo. These data will be used to generate your personal registration key.

The license will be valid through 1 year. If you wish to be able to use CppCat after that, you will have to send us a new photo of your student card.

Building Portable Games in C++ -- Guy Kogus

Fresh on Dr. Dobb's:

Building Portable Games in C++

By Guy Kogus

The cocos-2d-x open source framework can be used to build games, apps, and other interactive software in C++. Here's a hands-on guide to using it to write and port games.

From the article:

Our game, Ready Steady Bang, was written using cocos2d-iphone, which we were considering using for our next game, Ready Steady Play. Then I remembered the C++ gaming framework cocos2d-x and its promise of cross-platform compilation.

In this article, I break down how I developed the Ready Steady Play game using cocos2d-x and discuss the porting travails of moving the final code from iOS to Android and Windows Phone 8. I used v2.2.x of cocos-2dx, but most of this text should be applicable for v3.x...

Container Algorithms -- Eric Niebler

eric-niebler-toronto.PNGSome more details about the Ranges proposal that was well received by the ISO C++ committee at this month's meeting in Urbana-Champaign:

Container Algorithms

by Eric Niebler

From the article:

... So to sum up, in the world of N4128, we have this:

  • Eager algorithms that can mutate but that don’t compose.
  • Lazy algorithms that can’t mutate but do compose.

Whoops! Something is missing. If I want to read a bunch of ints, sort them, and make them unique, here’s what that would look like in N4128:

extern std::vector<int> read_ints();
std::vector<int> ints = read_ints();
std::sort(ints);
auto i = std::unique(ints);
ints.erase(i, ints.end());

Blech! A few people noticed this shortcoming of my proposal. A week before the meeting, I was seriously worried that this issue would derail the whole effort. I needed a solution, and quick.

Container Algorithms

The solution I presented in Urbana is container algorithms. These are composable algorithms that operate eagerly on container-like things, mutating them in-place, then forwarding them on for further processing. For instance, the read+sort+unique example looks like this with container algorithms:

std::vector<int> ints =
    read_ints() | cont::sort | cont::unique;

Much nicer. Since the container algorithm executes eagerly, it can take a vector and return a vector. The range views can’t do that...

Call for volunteers: isocpp.org blog editors

We are looking for additional volunteers to be isocpp.org blog editors.

Here's what you'd do: Just read your daily RSS and other web feeds, which you're probably doing anyway -- we'll suggest a few additional feeds as appropriate ones to watch for your blog section. Then, whenever you encounter a high-quality item that you think would be of broad interest to other modern C++ developers, share it on the isocpp.org blog by posting a brief "link-to style" blog item that lets our readers know about it. Each link-item would consist of just a one-line introductory blurb, a link to the post, and an interesting representative "from the article" passage to give the reader an idea of what it's about so they can decide whether to click and read further. See the isocpp.org style guide for an example of the content and editing.

Here are the roles we are seeking to fill, with a recent example of each type of post:

  • Articles & Books editors to link to new articles, such as experience reports about using modern C++ in a project, insights about using a particular C++ feature, and related things like announcements of new high-quality modern C++ books. Example: linking to a good experience report about using modern C++.
  • "Quick Q" editors to link to useful new Q&A on sites like StackOverflow or Reddit, to make readers aware of interesting questions that have correct answers. Example: linking to a good StackOverflow question.
  • Product News editors to link to announcements about compilers, libraries, and OSS projects of interest. We'd especially like to see more posts about OSS libraries that people maybe don't know about, but should. Example: linking to a good product blog post.
  • Video & Events editors to link to new high-quality videos on C++ topics, and to announcements relating to upcoming C++ events. Examples: see the blog's video category and events category for examples.

Requirements: You should be reasonably familiar with modern C++ so that you can judge whether a prospective item is reasonably accurate, modern, and of likely broad interest to C++ developers. Note that we are actively looking for items at all levels -- introductory (such as how to use a basic C++ features), intermediate, advanced, and "experimental." We want the blog to show a balanced mix of these -- our site should reflect the full range of our community.

Workload: The expected volume will usually be about 2-5 links per week, which should take less than 15 minutes per week of your time. Once you've found something to link to during your usual reading, it only takes a couple of minutes to write the blog post to tell others about it.

Honorarium: A modest honorarium is available for students who are accepted as blog editors. If you are a student and interested in the honorarium, please mention this in your inquiry email.

If you are interested in becoming an isocpp.org blog editor, please inquire at [email protected].