A Tiny Metaprogramming Library: Boxing – Part 1

A Tiny Metaprogramming Library episode 3:

Last time we introduced the mathematical concept of function as an entity that takes an input, generating an output. In that process, the function does not change any external state.

We also talked about metafunctions, a way to represent functions operating on C++ types using C++ templates.

After the theory, we followed with some conventions about the specific implementation of metafunctions in our tiny metaprogramming library. We decided that:

  • Any type with a type public member type is considered a metafunction, where type represents the result of that metafunction.That means to take the result of a metafunction we should say typename F::type in most of the situations. We introduced a simple tool tml::eval to help a bit.
  • Our metafunctions are templates, but these are constrained to take type parameters only.

In this post we will learn how to use boxing to pass value parameters as type parameters for our metafunctions. This is not something new but a way to understand what std::integral_constant, one of the fundamentals of <type_traits>, is and what can be used for.
Tiny Metaprogramming library episode 3: boxing.

Continue reading

A Tiny Metaprogramming Library: Extending the Metaphor, entering metafunctions

I know I’m repeating this everytime I write a new article, but it’s one of the key points to make template metaprogramming feasible, which means: TMP is just a functional language. A language with a “Aghhhh, my eyes, please!!! Aaahhhhhg!!!” syntax, but still a functional language.

To start a C++ metaprogramming library the right way, we’d better have a clear idea of what a metafunction is, and how our library represents and manages a metafunction.

Continue reading

A Tiny Metaprogramming Library

It seems people like template metaprogramming. After three successful blog posts about tmp – with 5k views on average each one – I’m sure people like and even want to understand that obscure corner of C++.

It’s not a funny way to play with the compiler only, template metaprogramming is a powerful tool for C++ developers and something that many of us must deal with everyday.

Continue reading

Metaprogramming with Modern C++: The Haskell Metaphor

I 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 ;).

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.

Lets start the game!

Continue reading

Template Metaprogramming with Modern C++: templates in depth

Template Metaprogramming with Modern C++: Templates in depth

The last time  we learnt what metaprogramming was, how metaprogramming in C++ via templates works, and the functional spirit of the embedded language that C++ template metaprogramming is.

In this post we will learn C++ templates in depth: Class and function templates, template parameters, variadic templates, all with in depth examples.
SPOILER: Finally, there is no SFINAE explanation on this post. This has a large amount of contents to be read and understood, I think understanding correctly the template system and the different categories of template parameters is good enough for a single (But large) blog post. Of course, if there is any problem feel free to post a comment here.

Template Metaprogramming Modern C++ in biicode
Continue reading

Template Metaprogramming with Modern C++: Introduction

Template Metaprogramming with Modern C++: Introduction

Any sufficiently complex C++ code is indistinguishable from trolling

Arthur C. Clarke

Preface

Template metaprogramming is one of the things that makes C++ that complex, poor known, and sometimes horrible language. However, its power and expressiveness are some of the best features of C++.

Extensible and fully generic C++ libraries aren’t possible without template metapogramming. Even the Standard Library implementations hide many template metaprogramming tricks to make standard containers and algorithms that generic, high level, and efficient tools we use everyday.

The fact that tmp is a powerful tool can be seen in the evolution of the language, which now has features designed to improve metaprogramming, see C++11 <type_traits>, C++11 variadic templates, C++14 variable templates, C++14std::integer_sequence, etc.

template metaprogramming

Credit: https://gitorious.org/metatrace

Continue reading

Meta-configuration with CMake of C/C++ projects

This blog post is out dated.

If you’re interested on knowing the updates, check our docs for more information.

Project configuration and setup

Project configuration in software development is the process of setting up how your code will be built, managed and/or run. It varies depending on the programming language and tools, as the IDE, used. For instance, when programming in C/C++, the project setup usually comes with defining which artifacts (executables, libraries) will be built from certain source code files, with given compiling and linking options. In Microsoft Visual, this can be mostly done with wizards, menu and contextual commands; e.g. you can configure your directories containing external libraries in a dialog (Project Properties).

 

Meta-configuration with CMake

Continue reading