& ldquo; Conditional & rdquo; alias templates

In a type like the unspecialized template struct pointer_traits (i.e. template <class Ptr> struct pointer_traits), there exists a member alias template rebind that is defined to be Ptr::rebind<U>, if it exists, or some other type otherwise. Th

Advantages of sending tags on a normal overload resolution

Plain and simple: what's the advantage of tag dispatching over normal overload resolution? These are both compile-time processes right? So there shouldn't be a 'performance winner' I suppose. And every tag dispatching case should be able, to some ext

Casting an object to a subset of its bases

I have a class defined as follows: template< typename... > class Base; template< typename T > class Base<T>{ //pure virtual functions dependent on T public: virtual ~Base() = default; }; template< typename... Ts > class Base<Ts.

Is it possible to unravel a model of its arguments in C ++?

This question already has an answer here: Changing value_type of a given STL container 3 answers Assume I receive two arguments to a template, T1 and T2. If I know T1 is itself a templated class (e.g., a container), and T2 can be anything, is it poss

Implement a function model to fill multi-dimensional objects

Filling multi-dimensional objects (arrays, nested standard containers, etc) in C++ has always been annoying to me. Nested loops are usually used. For example, to fill a 3-dimensional object obj with value v, you may write something like for (auto& x

Definition of conditional type aliases

I have a type like this: template<typename T> struct wrapper { using foo = typename T::foo; using bar = typename T::bar; using baz = typename T::baz; // More of those... }; I would like foo, bar, baz and equivalent type aliases to be defined if and

How can I generate a tuple of N type T?

I want to be able to write generate_tuple_type<int, 3> which would internally have a type alias type which would be std::tuple<int, int, int> in this case. Some sample usage: int main() { using gen_tuple_t = generate_tuple_type<int, 3>::

Inherit typedefs?

This question already has an answer here: Where and why do I have to put the "template" and "typename" keywords? 5 answers I've been confused recently by a few code examples -- sometimes it seems that inheriting typedefs exposed by a b

Metaprogramming in Swift

Coming from C++, I'm trying to do some metaprogramming in Swift. For example, I'd like to implement a metafunction that adds two numbers. I've tried something like this: protocol IntWrapper { class var value: Int { get } } struct A: IntWrapper { stat

Typedef C ++ to rename functions

I would like to be able to typedef functions in order to be able to use template metaprogramming as a function selector (like in the example below). I've also tried passing the function as a template argument. In both cases the error arises because t

How can I get the most internal type of template setting?

Q In a dummy example of a class typedef myStruct<myStruct<myStruct<int>>> mv; int is the innermost template parameter. How can I get the type of that parameter for arbitrary nesting depth? Desired Result A mechanism to acquire the innerm

Struggling with the implementation of a list of types

For educational purposes I want to write my own c++11 based typelist. The bare list looks like this: template <typename ... Ts> struct type_list; template <typename T, typename ... Ts> struct type_list<T, Ts ...> { typedef T Head; typede

Using Boost :: odeint with Eigen :: Matrix as a state vector

I'm trying to utilize the ODE integration capabilities of Boost using the Matrix class from Eigen 3 as my state vector, but I'm running into problems deep into Boost that I don't understand how to address. A minimal example of what I'm trying to do:

Calculate values ​​using template size_t param

This question already has an answer here: Template Metaprogramming - Difference Between Using Enum Hack and Static Const 3 answers What is the C++ way to calculate some values using template params? template<typename T, size_t SIZE> class ThreadSafe

Calculating the factorial of a small integer at compile time

I just implemented (once again) a recursive template for computing the factorial of an integer at compile time (who would had thought that some day I'll actually need it!). Still, instead of rolling my own, I went to Boost looking for an answer. Howe

Framework plugin in C ++ with

I'm designing (brainstorming) a C++ plugin framework for an extensible architecture. Each plugin registers an interface, which is implemented by the plugin itself. Such framework may be running on relatively capable embedded devices (e.g. Atom/ARM) s

ID of the compilation constant

Given the following: template<typename T> class A { public: static const unsigned int ID = ?; }; I want ID to generate a unique compile time ID for every T. I've considered __COUNTER__ and the boost PP library but have been unsuccessful so far. How