C++ templates Turing-complete?

I’ve done a turing machine in C++11. Features that C++11 adds are not significant for the turing machine indeed. It just provides for arbitrary length rule lists using variadic templates, instead of using perverse macro metaprogramming :). The names for the conditions are used to output a diagram on stdout. i’ve removed that code to … Read more

How can you iterate over the elements of an std::tuple?

I have an answer based on Iterating over a Tuple: #include <tuple> #include <utility> #include <iostream> template<std::size_t I = 0, typename… Tp> inline typename std::enable_if<I == sizeof…(Tp), void>::type print(std::tuple<Tp…>& t) { } template<std::size_t I = 0, typename… Tp> inline typename std::enable_if<I < sizeof…(Tp), void>::type print(std::tuple<Tp…>& t) { std::cout << std::get<I>(t) << std::endl; print<I + 1, … Read more

Templated check for the existence of a class member function?

Yes, with SFINAE you can check if a given class does provide a certain method. Here’s the working code: #include <iostream> struct Hello { int helloworld() { return 0; } }; struct Generic {}; // SFINAE test template <typename T> class has_helloworld { typedef char one; struct two { char x[2]; }; template <typename C> … Read more

tech