HNHacker News
TopNewBestAskShowJobs

Manu343726

7 karma · joined September 23, 2014

submissionscomments
Manu343726··on The Sunset of C and C++
I think the point here is that depending on Boost (Or similar libraries) should not be a problem.

Consider python's pip. Bootstrapping a python codebase is simple, just run pip install -r requirements_file.txt. The bootstrapping itself may take some time, but it's automatic and simple to do.

We need exactly the same for C and C++. Bootstrapping huge C/C++ libs will never be done in a couple of minutes, compiling those take time. But the process of triggering that bootstrap can (and should) be simple and natural (I think we achieved that with boost on biicode. Of course everything can be improved). That's what a C/C++ dependency manager means. Forget to elide large compile times, that's a matter of how the language works. But let's try to make gluing C/C++ libraries together an easy to "call" task.

Manu343726··on Metaprogramming with Modern C++: The Haskell Metaphor
The key here is to be objective, not falling on a flame thread. C++ templates are ugly, I'm agree, but they are useful and heavily used. Lets make them simple to use with some abstractions.
Manu343726··on Metaprogramming with Modern C++: The Haskell Metaphor
Haha, that reminds me to a guy who implemented a PROLOG-like language with templates: https://github.com/abudnik/tcalc
Manu343726··on Metaprogramming with Modern C++: The Haskell Metaphor
"Programming in XML notation is starting to look good, suddenly" I hate the typename ::type pattern. tml::eval helps a lot, but still involves a lot of nested template "calls". To deal with this, I'm working on a continuation system for C++ templates: https://github.com/Manu343726/Flux
Manu343726··on Metaprogramming with Modern C++: The Haskell Metaphor
Exactly. if is a C++ keyword. I selected tml::conditional following the Standard std::conditional. The boost::mpl library uses mpl::if_, for example.
Manu343726··on Metaprogramming with Modern C++: The Haskell Metaphor
As I said in the post, common day to day C++ has (usually) nothing to do with metaprogramming. But huge generic libraries, like most of the STL implementations, rely heavily on template metaprogramming.

Those libraries usually have their own hardcoded tricks and metafunctions. What I'm trying with Turbo is to provide all that functionality in a portable and easy way.

Manu343726··on Template Metaprogramming with Modern C++: templates in depth
+1 to alexandrescu's "Modern C++" showing the expressive power of C++. Also, imho, one o the key points of the book is how Alexandrescu criticises the OO patterns of the so horrible Gang Of Four. Anybody who have readed their book in depth should note that they provide a poor cookbook with "Do you have this problem, copy-paste that code" notes and an implementation provided by someone thats completely biased with all the OOP buzzwords, but never implemented them seriously in a real language.
Manu343726··on Template Metaprogramming with Modern C++: templates in depth
I'm agree with you and aware about the fact that the Fibonacci metafunction is not a good example of real metaprogramming (Computing Fibonacci series using tmp has no much sense). I only picked that example because its recursive structure is pretty well known (Is one of the most common first examples used to teach recursion), so fits well to show people how a complex template is instanced, which is the idea of that part of the post. Compare that with using an instance of std::vector, for example. Is a much more realistic example, but people usually doesn't know about the inside of a vector and how it's structured internally. The main objective of these posts is to explain tmp in away that everybody understands it well. When we all are well covered about the basics, we will can get into more complex and realistic cases in depth. That's exactly why more complex examples included in the post, like build_string, are not explained in depth. Are more a proof of concept.
Manu343726··on Template Metaprogramming with Modern C++: templates in depth
There could be a bug on the code snippets included inside the post, sorry. Check the code running at compiler explorer, it's working and you can see clearly the result string literal at the end of the assembly.

The point of the example is: We represent a string as a variadic pack of chars, and build_string is a metafunction that builds that kind of string recursively given a starting character and a size. Inside that metafunction we define an aux metafunction build_string_impl that does the job, we only have to pass the required initial parameters (The count of chars and the initial empty string). The first partial specialization acts as the recursive case of that function, and the second is the base case (note count is 0 in that case).

Manu343726··on Template Metaprogramming with Modern C++: templates in depth
The term "Modern C++" refers to the fact that most of the C++ industry still depends on or develops C++98/03 code. Is "Modern" compared to that, and the term is used to refer to state of the art C++ instead of old C++98.