Roger Orr gave this month’s ACCU presentation on Making Templates Easier in C++. He showed two techniques that people commonly use to tailor template implementations for specific types: Tag Dispatch and SFINAE (via enable_if).
With Tag Dispatch, you can switch to different implementations of a template function using traits classes based on one of the input parameter types (e.g. use std::iterator_traits to target a faster implementation for random access iterators). The downside is that you often have to duplicate code across the different implementations.
With SFINAE, you can use typedefs within a parameter type to disable particular overloads. E.g. STL containers have a ::value_type typedef, so you can use that to differentiate between collections and scalar inputs. The downside is that you sometimes have to add additional, defaulted template parameters to allow the compiler to distinguish between otherwise identical template definitions.
Roger then introduced
constexpr if from C++17 and concepts from C++20.
The advantages of
constexpr if are that it can be used both inside and outside templates and specialisations can be defined inline. Any code that would not compile can be put inside a
constexpr if and will be discarded. This seems more straightforward than the recursive template solutions Roger showed earlier in the talk.
Concepts are intended to help define the requirements of a template in a way visible to the compiler as well as the developer. Reusing concept definitions should leave to a domain-specific language that helps within a project. Better still, use of a template parameter type that doesn’t satisfy concept requirements will generate a more helpful error message than if SFINAE were used to achieve the constraints.
The finale was an overview of the new SpaceShip operator, !
The video is now available on the SkillsMatter website.
The premise of this book is that the brilliant Robert Puller has been convicted of treason against the USA and is being held in a maximum security military prison. His brother, the gifted investigator John Puller, still believes in him, even when he escapes during a storm. John Puller works with the intrepid Veronica Knox to investigate the escape and to clear his brother’s name. They focus on the witnesses who gave testimony against Robert Puller. If he is innocent, they can’t be, so the investigators have to uncover the truth behind their lies.
This book made a good holiday read – if you have the impression that recent Baldacci books are a bit lightweight, this one won’t change your mind, but it is quite entertaining.
This Harry Bosch thriller starts with an investigation into the murder of a Chinese convenience store owner. It happens that this very man gave shelter to Harry in his shop during a riot, so he resolves to do everything he can to track down the culprit. During the investigation, the author answers a lingering question – how did Harry suddenly find himself looking after his teenage daughter, in later books in the series? The daughter, Madeline, was living with her mother Eleanor Wish in Hong Kong – they become an integral part of this story when a Triad gang decide to ward off Harry’s murder investigation by kidnapping Maddie.
The book has plenty of plot twists to keep the reader’s interest, but I found it too far-fetched. Identify the location of the kidnapping from a fleeting, blurred view out of the window in the ransom video? Find Maddie in the middle of Hong Kong, a city Bosch hardly knows, given just 24 hours? No problem, and why not leave a trail of destruction behind when Bosch catches a flight home with Maddie? A nice touch is when another of the author’s characters, lawyer Micky Haller, steps in to defend Bosch from any awkward charges from the Hong Kong police.
A friend sent me a link to some Jack Reacher quotes and I was delighted to discover that it listed a book in the series that I hadn’t read – “Running Blind”. I ordered it immediately – alas when it arrived, it turned out to be “The visitor”, a book I had already read, just published under another name in the U.S.
This book sees Jack Reacher in a relationship with Jodie, the high-flying daughter of his old boss, General Garber. It’s the closest he’s got to settling down – he inherited Garber’s old house (which sounds great by the way), he loves Jodie – all is well. Except that he cannot escape the nagging voice that tells him to move on – and eventually, he will.
The book centres on a series of macabre murders, where army women are found dead in a bath of green paint – cause of death, motive and method all unknown. In a side plot, Reacher sees that his favourite restaurant is being threatened by a protection racket – so he steps in, fearlessly as ever, to take on the thugs. Unfortunately, his brand of rough justice is witnessed by a couple of FBI agents, and Reacher is forcibly recruited by them to help investigate the bath tub murders. It turns out he knew a couple of the women involved, and was being followed as a suspect. He satisfies his yearning for travel by flying around the country investigating, accompanied by the lovely Special Agent Lisa Harper.
The book finishes with Reacher solving the case and his girlfriend’s career really taking off as she is made partner by her law firm. It’s clear their days together are numbered and by the next book, he’ll be a loner again.
I was lucky to get a ticket to hear Andrew Blake’s Lovelace lecture, on the subject of “Machines that (learn to) See”.
Machine vision works nowadays. Machines can: navigate using vision; separate object from background; recognise a wide variety of objects, and track their motion. These abilities are great spin-offs in their own right, but are also part of an extended adventure in understanding the nature of intelligence through visual perception.
The speaker was Laboratory Director at Microsoft Research, Cambridge and his team was behind the the Kinect technology. He is now Research Director at the Turing Institute.
The lecture covered the history of machine vision over the last 50 years, the rise and fall of different approaches to AI over the decades, and finally the recent successes of analysis-by-synthesis and empirical recognisers.
This is the third novel by Mark Gimenez that features A. Scott Fenney, a brilliant Dallas lawyer. His way of life was changed dramatically when forced to defend a young woman against a murder charge in The Color of Law, and we saw his sense of duty come to the fore when he defended his ex-wife against another murder charge in Accused.
It’s fair to say, then, that Mark Gimenez gives Fenney a pretty hard time. The dilemmas that are set for him remind me of Dick Barton, Special Agent, a radio play from the 1940s. One team of writers was tasked with setting Dick Barton the most impossible challenges, then another set of writers had to devise a way out – the competitiveness between the teams adding to the tension. The difference here is that A. Scott Fenney is not a man that would take an easy way out – his sense of duty is so profound that he faces impossible moral dilemmas head on, regardless of the consequences to his personal life.
In this story, we see Fenney installed as a federal judge. He has to rule on whether the President has broken constitutional law by issuing an order to allow illegal immigrants to become citizens of America. He also has to consider whether to free a terrorist accused of plotting to blow up a stadium in Dallas during the Super Bowl. The attorney general and the president are counting on him to detain the suspect – the only problem is the absence of any evidence against him.
I think Gimenez is at his best with this character, especially because we continue to hear about his family life as his teenage daughters grow up and become a key part of the plot in this book. He also gives a sly reference to Bookman, the main character in his earlier book, Con Law.
I’ve been learning Python for a few months and am starting to use it at work, so I thought it was about time to read a book about Python. This book has been excellent. No only does it follow format of the time-honoured ‘Effective’ series pioneered by Scott Meyers, it also features practical, useful code examples. In particular, his JsonMixin class was immediately relevant to some work I’ve been doing to generically serialise to/from JSON documents – see Item 26 “Use Multiple Inheritance Only for Mix-In Utility Classes”.
The author has also taken the time to record hours of video lessons for Safari Online subscribers, so you can view additional material as he works through the items in the book.