Questions tagged [template-meta-programming]

Template meta-programming is a meta-programming technique in which templates are used by a compiler to generate temporary source code, which is merged by the compiler with the rest of the source code and then compiled.

Wikipedia entry.

Template meta-programming is a meta-programming technique in which templates are used by a compiler to generate temporary source code, which is merged by the compiler with the rest of the source code and then compiled.

The template outputs include compile time constants, data structures and functions; this technique can be described as a "compile time" execution. It can be used to control the generation of optimized code based on the compile time type being used, and "static polymorphism" (also known by the pattern name CRTP).

2288 questions
1
vote
2 answers

How to transform this list of types with brigand?

I have the following list of types: using ComponentList = brigand::list How can I transform the previous list into a new list that would look like this: using ComponentHandleList =…
1
vote
2 answers

How to create a tuple of fix types whose size is a known at compile time in C++17?

I would like to create a tuple type of common element type whose length is known at compile time. For example if I have static constexpr const std::size_t compiletime_size = 2; using tuple_int_size_2 = magic (int,…
motam79
  • 3,542
  • 5
  • 34
  • 60
1
vote
1 answer

Address of an empty base optimized subobject

Let's say that I have a value: int i = 0; And an empty class eligible for being empty-base optimized: struct Empty{ // stuff that passes // static_assert( std::is_empty::value ); }; Is it legal to: Empty& e =…
1
vote
0 answers

Retrieving std::tuple object given its member value references

Let's say that I have an std::tuple: std::tuple< int, float, bool > my_tuple; and a function: void my_function( int& i, float& f, bool& b); Is it possible to retrieve the my_tuple object from within my_function if I can guarantee that its…
1
vote
1 answer

Providing generic interface with TMP and SFINAE

At the moment, I have the below working code where using class X, I provide a generic interface for multiple classes - I only expect a static f function to be present, but neither do I fix the return type nor the parameters: #include…
1
vote
3 answers

Unwrapping variadic template structs

I'm trying to create an variant struct, i.e. a struct that contains one of so many types. Here is my attempt so far: template struct OneOf { union { Type value; OneOf rest; …
1
vote
1 answer

Unpack tuple to member initialization or superclass constructor

Is it possible to initialize a member of a class (or call superclass constructor) by using the arguments contained in a tuple? Please note that I am aware of std::make_from_tuple() and std::apply() but they cannot be used in this scenario. Consider…
1
vote
4 answers

How do I use std::is_pod in a template argument?

I'm trying to get one set of behavior when something is a pod, and something else when it's not through template meta programming. I've written the below code, but I get a compilation error. I want to get: yep nope but I get the following compiler…
Carbon
  • 3,828
  • 3
  • 24
  • 51
1
vote
1 answer

Use templated type injected via a template

This is my first time trying to apply does concept which are undoubtedly hard to grasp. I have created a generic logger type which can, at compile time, decide if the log level is high enough for output. Here is an example of the problem on compiler…
1
vote
1 answer

How to implement a C++ metafunction that operates on pairs of sequences

I have this implementation of computing the elementwise product of two index sequences template constexpr auto product_sequence_impl( index_sequence, index_sequence ) -> …
Greg von Winckel
  • 2,261
  • 2
  • 16
  • 14
1
vote
1 answer

C++: Is it possible to write a function that appends a differently typed element to an array of variant?

I'm trying to write a function, that will, for example, take an: std::array, 4> and a double d, and return: std::array, 5> with d appended to the end of the array, but…
Sebastian
  • 715
  • 6
  • 13
1
vote
1 answer

Member detection based on custom void_t implementation

I've got the book C++ Templates the complete guide and I'm trying to implement some of the described techniques. One of these is member function detection, but my implementation seems not working. I can't use void_t as I'm using C++11, but I copied…
svoltron
  • 365
  • 1
  • 10
1
vote
1 answer

Creating an index_sequence of N zeros

I've been trying to write a zero_sequence type which either creates an index_sequence of a specified number of zeros or uses an existing index_sequence as to produce a new one with the same number of values, but all zero. I'm perplexed as to why…
1
vote
1 answer

Is it possible to define a template parameter pack array

Possible duplicate: Is it possible to "store" a template parameter pack without expanding it? Similar to the question above, I'd like to explore this more and store a variadic array. template void foo(Args(&...args)[N])…
1
vote
3 answers

SFINAE failing to work with intermediary type traits

Consider the following test code: // Preprocessor #include #include // Structure with no type alias template struct invalid { }; // Structure with a type alias template struct valid { using type =…
Vincent
  • 57,703
  • 61
  • 205
  • 388
1 2 3
99
100