template-meta-programming Questions

3

Solved

Given this type: template<typename ...As> struct Base {}; I need to implement a function template<int i, typename ...As> constexpr auto Tail() { static_assert(i < sizeof...(As)...
Honourable asked 28/5, 2019 at 14:44

2

Solved

I am building a state-machine where state transitions are described as a variant, i.e.: using table = std::variant< /* state event followup-state */ transition<start, success<sock>, c...

3

Solved

Having the following piece of code: #include <iostream> #include <type_traits> template <typename F, typename = typename std::enable_if< std::is_function< F >::value &g...
Pinson asked 21/6, 2016 at 14:8

1

Solved

We consider the goal of creating two different types, using the exact same syntax. This can be easily done with lambdas: auto x = []{}; auto y = []{}; static_assert(!std::is_same_v<decltype(x),...
Shannanshannen asked 2/4, 2019 at 12:53

3

Solved

I'm trying to detect if a specific overload for my function is callable. I assumed I could do something similar to this answer, but I believe the issue is that the function signature template<ty...
Preoccupation asked 10/5, 2019 at 6:57

5

I'm trying to implement a fast function dispatcher using compile time generated arrays to being able to use it at runtime in O(1). Some lines of code just to clarify: template<int i> void f...
Serval asked 14/11, 2018 at 10:19

1

Solved

I'm trying to find the best method to have a kind of "object" that can be either specialized or "linked" to another type. For instance you cannot specialize a class to make it become a simple int,...

1

Solved

I'm struggling to understand how deduction works in the following case: template<class Category, Category code> struct AImpl { }; template<class Category, Category code> struct AHelpe...

2

Solved

I would like to split a template parameter pack. Something like this. How could I go about doing this? template< typename... Pack > struct TypeB : public TypeA< get<0, sizeof...(Pack)/...

6

Solved

From the cppreference.com article on std::enable_if, Notes A common mistake is to declare two function templates that differ only in their default template arguments. This is illegal because de...

2

Solved

#include <functional> #include <sys/types.h> #include <sys/socket.h> std::function<decltype(::bind)> mockbind = ::bind; int main() { } The code above works on most of t...
Ariel asked 30/8, 2017 at 16:24

2

Solved

In some contexts, it could be useful/necessary to have a for loop evaluated/unrolled at compile time. For example, to iterate over the elements of a tuple, one needs to use std::get<I>, which...

3

Solved

I implemented a Visit function (on a variant) that checks that the currently active type in the variant matches the function signature (more precisely the first argument). Based on this nice answer...

3

Solved

Is there a method to decide whether something can be constexpr evaluated, and use the result as a constexpr boolean? My simplified use case is as follows: template <typename base> class deriv...
Fitzger asked 21/3, 2019 at 20:10

5

(Spoiler - this is a self-answered question) Let's pretend I have two index sequences, for example using i1 = std::index_sequence<1, 3, 5, 7>; and using i2 = std::index_sequence<2, 4, 6, 8...

2

Solved

Im trying to create some tool to create a list of types based on combinations of other types. Lets say we have three types struct A{}; struct B{}; struct C{}; I want to get a list of tuples wh...

2

I am trying to write a template to calculate the power of a number during compile time (I am not a template meta-programming expert so any comment is appreciated). Below is the code: template<t...
Radicalism asked 18/2, 2019 at 13:41

2

Solved

I am trying to do N-dimensionally nested metaloops with template metaprogramming. The nesting part is trivial, however passing all the arbitrary number of iteration indices as template parameters t...

3

Solved

I need to know the exact number of arguments that a lambda has. I do not care for their types, I just need a count. auto lambda0 = [&]() { ... }; auto lambda1 = [&](int32_t a) { ... }; aut...
Gallium asked 27/1, 2019 at 15:38

2

Solved

I am trying to achieve the following using c++ template metaprogramming. I wish to build up a list of types and then collect these types together and do further compile-time processing on the list....
Around asked 9/9, 2013 at 15:29

4

Solved

I wanted to define a variadic tuple type to represent coordinates. For example, for some magic type: template <unsigned int N> struct CoordT { typedef std::tuple<_some_magic_> coord_t...

3

Solved

Before the introduction of concepts and constraints, there are several ways to simulate this compile-time check. Take a "order()" function for example: (how to implement LessThanComparable wi...
Attah asked 25/12, 2018 at 13:9

2

Solved

I am trying to use if constexpr in the following way: template<template <typename First, typename Second> class Trait, typename First, typename Second, typename... Rest> constexpr boo...
Enlargement asked 17/12, 2018 at 15:50

3

Solved

#include <type_traits> template<typename T> struct remove_cvref { using type = std::remove_cv_t< std::remove_reference_t<T>>; }; template<typename T> using remove_...
Gravelly asked 16/12, 2018 at 9:34

3

Solved

Here is my implementation of converting binary literal to decimal: template<char Head, char... Tail> constexpr int operator"" _b() { if constexpr (sizeof... (Tail) == 0) { return Head - ...

© 2022 - 2024 — McMap. All rights reserved.