C++ Club - Meeting 147

Episode Date: June 23, 2022

Show notes: https://cppclub.uk/meetings/2022/147/Video: https://youtu.be/rxFeVEVl6O0...

Transcript
Discussion (0)
Starting point is 00:00:00 Welcome to C++ Club. This is meeting 147 that took place on the 7th of April 2022. A quick follow-up. Float Toy. Ivor Hewitt told me about a cool website called Float Toy. It allows you to visualize the binary representation of floating-point numbers of various sizes. You can toggle individual bits in Sine, Exponent and Mantissa, and see how it affects the represented value. Celebrating 25 years of C++ Builder
Starting point is 00:00:40 Embarcadero posted an article celebrating 25 years of C++ Builder. For those like me who remember Turbo C and C++ fondly, this is a bittersweet article reminding how a great product can turn into something very few people use because of the inept owners. They made C++ Builder version 1 freely downloadable for nostalgic value. And there is also a free community version of the modern C++ Builder 11, which is still Windows-only and has a limit of $5,000 of revenue or more than 5 developers per company, before you need to pay big bucks.
Starting point is 00:01:22 It supports FireMonkey, Embarcadero's cross-platform GUI framework, but for some reason doesn't use it to actually be cross-platform. There is a link to a magazine review from 1997 of Boland C++ Builder version 1, including the non-standard C++ features added by Boland in order to support RAD capabilities previously available in Delphi only. They added properties, closures and events, streaming support, expanded RTTI, metaclasses and Virtual Constructors Here is a quote that demonstrates what Embarcadero thinks modern cross-platform support means. Quote The toolchain has a long history of supporting non-Windows platforms. Did you know that Bolon shipped C++ compilers for Nokia and Symbian mobile devices?
Starting point is 00:02:23 Today you can use C++ Builder for Windows and iOS. End quote. I'm a little bitter and sad, as you can tell. I learned programming with Turbo Pascal and Turbo C++. This is how Turbo C screen looked And this is a Wikipedia article about Borland C++ Borland C++ was my favorite IDE before I switched to Microsoft C++ 1.52c for better Windows support I would have liked a more than affordable cross-platform Borland style C++ IDE.
Starting point is 00:03:06 Oh well, there is always C-Lion I guess. C++ and Rust interoperability An article was published on the Tetrain blog describing the current state of Rust and C++ interoperability. The article explains all the available options in detail, including code snippets, but for a short summary let's read the comment on the Reddit thread by the original poster. Quote. The post proposes three approaches based on three available libraries in the Rust ecosystem.
Starting point is 00:03:45 Bind the gen. Start from C or C++ headers of a C or C++ library and generate Rust code that exposes functions able to call the C++ library. Then you can just link with this library statically or dynamically and call its functions. It's automatic, but it doesn't attempt to reconcile the differences of concepts between C++ and Rust. And more importantly, it doesn't attempt to translate what C++ and Rust have in common. Iterators, vectors, string, unique pointer, shared pointer, etc. So it's best suited for very C-like libraries. Option number 2, CPP, uses Rust's macro system to let you write C++ inline inside of your
Starting point is 00:04:39 Rust. The C++ snippets are then compiled by a C++ compiler, and the Rust code to call them using the C ABI is generated. Since C++ snippets are C++, you can directly call other C++ libraries from the C++ snippets. However, the boundary between C++ and Rust remains somewhat low level with this solution. It has native understanding of UniquePointer, but that's pretty much it. Option number three. CXX uses Rust's macro system to let you declare a special Rust module containing items like types and functions to be either shared, understood by both C++ and Rust and passed by value between the languages, or opaquely exposed from one language to the
Starting point is 00:05:33 other. You'll need to manipulate the type behind a pointer when on the other language. This approach is nice because it pre-binds for you some C++ and Rust standard types, vectors, strings, and concepts, exceptions and Rust result types. At the basic levels, all three libraries are built upon the C API and API, since it is the common language that both Rust and C++ understand. In CXX, however, you don't really see the use of the basic C API, since some high-level
Starting point is 00:06:08 concepts are translated between C++ and Rust. End quote. I read that Microsoft is exploring Rust for some of their codebases. I wonder what they'll use if they need C++ interop.
Starting point is 00:06:26 Minimum Viable Declarative GUI in C++ Jean-Michel Sellerier wrote an article that introduces a minimal declarative C++ GUI library. Like, really minimal, when declaring a struct is enough to define a user interface. Later this declaration is included in another magical file which produces the declared UI. The resulting interface can be rendered by Qt via QML or another backend like Nuclea, which is a C-based immediate mode UI engine. In the Reddit thread, people are generally impressed until they discover all the macros
Starting point is 00:07:14 the author had to add to improve the syntax. Also, the code is under GPLv3, so be careful not to remember any of it, or you'll have to open-source your brain. ULID. Universally Unique Lexicographically Sortable Identifier. ULID is a replacement for UUID that is human-readable and lexicographically sortable. It is encoded in 26-character string as opposed to 36-character UUID. Uses base 32 encoding for readability, which means no ambiguous characters.
Starting point is 00:07:54 And doesn't use special characters, which makes it URL-safe. Implementations exist in many languages, including an MIT-licensed C++ version. Next time you need a UUID in your software, see if ULID is a better fit for your needs. C++ for mathematicians. A Redditor asks, what are good books about mathematical programming in C++. It's a long thread, but some suggestions from it were
Starting point is 00:08:29 numerical recipes you can read the ebook for free online, including source code. An article by David Goldberg that I mentioned previously many times called What Every Computer Scientist Should Know About Floating-Point Arithmetic and lectures Object-Oriented Programming for Scientific Computing from University of Heidelberg with lecture notes and slides. Crow web framework. A Redditor writes, quote, a year and a half ago I picked up an abandoned C++ web framework. Today we released version 1. Quote, Crow is a simple and easy to use C++ web application framework.
Starting point is 00:09:28 We picked it up as an abandoned project about a year and a half ago and have been fixing, optimizing, and adding many features. End quote. Crow is header-only, comes under BSD 3.0 license, uses C++ 11.14, and is pretty fast and easy to use. These are the benchmarks. As you can see it's pretty efficient compared with
Starting point is 00:09:54 other C++ and non-C++ web frameworks and it's easy to use as it is similar to Python's Flask. Several Redditors in the thread used Crow before and were very glad to see it revived. Injected class names Raymond Chen writes, C++ has a feature called InjectedClassNames, which lets you refer to the class being defined by its plain name without needing to fully qualify it with namespaces and template parameters. You have probably been taking advantage of this feature without even realizing it."
Starting point is 00:10:38 The snippet of code is a class template which is called wrapper and inside of it when you declare its default constructor you don't need to use the template parameter and you just write wrapper, parentheses and then calibrate and the definition. Base class names are also injected, unless they are inherited privately. This is the related CPP reference article, quote, Constructors do not have names, but the injected class name of the enclosing class is considered to name a constructor in constructor declarations and definitions. End quote.
Starting point is 00:11:31 In the corresponding Reddit thread, Stefan T. Lovewaite says, the injected class name can be used as a template name or a type name. So both wrapper on angle brackets T and wrapper are valid in the code snippet that we talked about. Good to know. NVIDIA is building a quantum computing C++ compiler. Bryce Lelbach tweets, quote, we're building a new C++ compiler for quantum computing.
Starting point is 00:12:08 End quote. He links to the article, NVIDIA, we are a quantum computing company. A quote from the article. At NVIDIA's GTC spring event this week, the company announced that it is developing a new quantum compiler called NVQ++ that targets the Quantum Intermediate Representation specification for a low-level machine language that quantum and classical computers can use to talk to each other." The Reddit thread is brutal.
Starting point is 00:12:42 Quote Nvidia can't even build a C++ compiler for normal computing, so I'm sure this will go just perfect. Someone replies I have similar experience working with Nvidia. Their software is known as something to avoid at all cost at our workplace. The thread has many other hilarious comments like this one Oh man, I can't wait for Yosotis' book on move semantics in a quantum C++ compiler
Starting point is 00:13:13 and of course quote genuine question why C++ over Rust? C++ show and tell, April 2022. The C++ show and tell on Reddit is becoming a regular thing. This is the April edition. It's a long thread. My highlights are binary black hole collisions. RISC-V username emulator library. With this you can embed a virtual CPU RISC-V into your software.
Starting point is 00:14:02 For whatever reason. I don't know here a new GUI GDB front-end looks very nice interactive GPU CUDA raytracer the example images are really nice. Monocle Security Video Surveillance System. This one's a commercial product with some open-source free components. I think the client software is open, and there is an open API, but the server side is paid. Black Sun, a space exploration game with an AI text chat sidekick.
Starting point is 00:15:02 I kind of understand the idea and the appeal, but on the other hand, if you're fighting in space, do you really want to use a text chat to talk to your assistant? And Nominus Rex, a command line bulk file rename utility. Next we have a library SPD log or SPD log version 1.10. The highlights of this release are FMT version bumped to 8.1.1 Added file event handler hooks to handle after-start and before-end logging events, which allow to have prolog and epilog sections in the log file. And added UDP logging sync.
Starting point is 00:16:03 SpeedyLog comes under MIT license and can be used as a header only or compiled library. it's available in all major package managers, works on Linux, Windows, Mac OS and Android and requires just C++ 11. Reddit thread has positive vibes using subscript operator with tuples Daisy Holman tweets cute C++ trick of the day ever wished you could index into a tuple using operator square brackets you can do that with numeric literal operator templates. Maybe don't use it in production, but let's see what's going on here. Line 5 declares template index that has a sizeT template parameter determining the index value. Lines 6 to 13 declare a user-defined literal operator, underscore i, which has template
Starting point is 00:17:09 parameter of type char... that gets the actual characters in literal. I haven't seen this trick before. It's different from how you normally define a user literal that takes a string. But both styles are described on CppReference. Lines 8 to 12 produce a return value from the UserLiteral operator, which has the type index, and the template parameter value, determined by a lambda, which is immediately invoked on line 12. Lines 9 to 11 iterate through the characters in the literal and convert them to an integer using ASCII table arithmetic. Lines 15 to 21 define a custom class indexTuple, privately derived from stdTuple,
Starting point is 00:18:06 which adds a subscript operator template on line 20 that takes a value of type index and deduces its size. It then uses the deduced size value to call stdGet to index into the tuple. And lines 24, 25 demonstrate the usage of class index tuple by indexing into it using its subscript operator passing 1 underscore i as the index parameter. Some interesting responses on Twitter. Barry Revzin says, Don't need the std string, can just iterate over chars by itself. It gets deduced as an initializer list of char. And Philippe Payan says, The real magic to me is how 10 underscore i turns into the operator double quotes underscore
Starting point is 00:19:07 i with two char template values, namely 1 and 0, each of type char, obviously. How does that happen? How is 1 0 broken down into 1 and 0? And Daisy Holman replies, compilers are magic, but also the easier answer is because the standard says it has to. And then Philippe Ayan follows up. He says, I got it. I found it in the standard section 12.8 user-defined literals.
Starting point is 00:19:37 Point five. I understand this as basically your operator is getting bytes from the source code through the non-type template list of characters. So yeah, cool technique. I hate it. Hacking C++ posted a list of C++ videos. The tweet reads, I've started a new list of talks, tutorials, and other educational videos related to C++. It's organized by topic, like generic programming, C++20, best practices, modules, CMake, and
Starting point is 00:20:16 so on. The list index has over 700 videos and is a great learning resource. That's it for today. I'll leave you with these two tweets. First is Viktor Zverovich, who says, My code is standard compliant. Did you mean compliant? No. And the second tweet by Patricia Ars
Starting point is 00:20:47 who says computer science is half remembering something and googling the rest. Thank you for joining me. Until next time. Bye-bye.

There aren't comments yet for this episode. Click on any sentence in the transcript to leave a comment.