The Expressive C++17 Coding Challenge
The ink is dry on C++17!
Actually it had dried a few times already. But the drier the ink, the sooner we get to use this new standard in production code.
Now how do we learn all those new additions to the language? And how do we know to use them to write even more expressive code?
We’ve been thinking about that lately with Bartek from bfilipek.com, and we came up with something.
We’re going to make you CRAM new C++17 features into your code, and make it as expressive as can be! It’s time for a new challenge: the…
The Expressive C++17 coding challenge
Coding challenges are a fun way to learn together. You may have participated to a couple of them on Fluent C++ already. But this time Bartek and I are organizing a joint challenge simultaneously on the two blogs.
I’m thrilled about this challenge because you can find useful resources on C++17 on Bartek’s blog (he has been very intense on C++17 lately), and Fluent C++ has growing contents about writing expressive C++. This is as much material to put into practice to write expressive C++17!
So the purpose of this challenge is to write a piece of code that contains as many features of C++17 as possible, and that is as clear as possible.
But I don’t have C++17 in my production code yet! Should I still try this challenge?
Definitely. With compilers catching up recently (Clang 5 came out just a fortnight ago), and the ink barely dry enough so that you don’t smudge it when you touch it, not many people actually have C++17 in production today.
But as Raoul Borges says, C++17, like Winter, is Coming.
So we need to learn it, and we’d better start now as C++17 adds a lot of new features. Plus, knowing what features are coming in the language show us the direction the language is steering to. And whatever the version we use now, knowing this is helpful for making our current code follow this direction right away, to fit into the bigger picture of C++ and write better code.
So what is this challenge exactly?
The case
The task proposed in the challenge is to write a command line tool that takes in a CSV file, overwrites all the data of a given column by a given value, and outputs the results into a new CSV file.
More specifically, this command line tool should accept the following arguments:
- the filename of a CSV file,
- the name of the column to overwrite in that file,
- the string that will be used as a replacement for that column,
- the filename where the output will be written.
For instance, if the CSV file had a column “City” with various values for the entries in the file, calling the tool with the name of the input file, City
, London
and the name of output file would result in a copy of the initial file, but with all cities set equal to “London”:
Here are small input and output CSV files that can serve as a test case.
Here is how to deal with edge cases:
- if the input file is empty, the program should write “input file missing” to the console.
- if the input file does not contain the specified column, the program should write “column name doesn’t exists in the input file” to the console.
In both cases, there shouldn’t be any output file generated.
And if the program succeeds but there is already a file having the name specified for output, the program should overwrite this file.
If you’d like to write code directly on the page you can use this tech.io playground (this is used for coding, not for submitting – see below for how to submit your solution via Coliru):
The rules of the challenge
- To win the challenge, your code must have as many features of C++17 as possible, as long as they are useful to solve the above case. Please write all those you’ve used in a comment section at the top of your .cpp file.
- To win the challenge, your code must also be as clear as possible (you can write about what you did to achieve this too if you want).
- Please don’t use another library than the standard library.
- To submit a solution, paste your code into this empty coliru (GCC 7.2, note that parallel algorithms aren’t supported – we couldn’t find a platform supporting them yet) to make sure it compiles, click the “Share!” button and add the generated link to the comment section of this post, or on Bartek’s post.
- To be registered in the contest, add your email address at the beginning of your code so that we can get in touch with you. We’ll be sure to add you to the mailing lists of bfilipek.com and Fluent C++ (you can unsubscribe at any time, but you’ll get notified when the results come out).
- If you don’t want to display your email address on your solution you can send it to me or to Bartek privately. The same goes for your entire solution, if you’d like.
- The contests ends on the 15th of October at midnight GMT. So the 15th is ok, the 16th is too late. The results will be published on the 23th of October.
- If two people submit an equivalent solution, the first one wins.
Shall we start?
We do hope you have fun and learn things when coding up your solution. If you want to learn more about C++17, Bartek’s blog has a ton of useful information about it. A good starting point is his collaborative post on C++17 features. And to get inspired on writing expressive code, the contents of Fluent C++ are waiting for you.
It’s time to write some code now! Should you have any question of feedback, don’t hesitate to get in touch with either one of us.
Happy coding!
Don't want to miss out ? Follow:   Share this post!