template-meta-programming Questions

0

The whole bunch of "stateful" metaprogramming can be achieved by forcing template reevaluation. Here I don't want to discuss whether one should or should not use or depend on it. But sinc...
Rheumatism asked 8/2, 2023 at 14:53

2

Who knows how to implement C++ std::make_index_sequence reverse version. To get - make_index_sequence_reverse<int, 5> = <4,3,2,1,0>. Thank you!
Laruelarum asked 18/7, 2018 at 18:30

5

Solved

I have a class whose behavior I am trying to configure. template<int ModeT, bool IsAsync, bool IsReentrant> ServerTraits; Then later on I have my server object itself: template<typename T...
Hypercorrect asked 5/2, 2013 at 22:16

1

Solved

Why I get a compilation error if uncomment line #1 and comment line #2? Demo: https://godbolt.org/z/KW6dhsrKd #include <utility> template <typename, std::size_t> concept prefix = true;...
Hypothermia asked 16/1, 2023 at 11:0

5

Solved

I want to make a function which returns a power of integer. Please read the fmuecke's solution in power of an integer in c++ . However, I want to generalize his solution to the arbitrary type T. ...
Mignonmignonette asked 8/5, 2013 at 14:45

3

Solved

Consider this code: #include <iostream> typedef long xint; template<int N> struct foz { template<int i=0> static void foo(xint t) { for (int j=0; j<10; ++j) { foo<i+1&gt...

3

Solved

I have a simple TypeList implimentation, like this: template<typename... Ts> struct TypeList { static constexpr std::size_t size{ sizeof... (Ts) }; }; struct T1 { }; struct T2 { }; s...
Wordbook asked 10/1, 2017 at 22:21

7

Solved

I would like to use constexpr if to branch at compile time, but it does not seem to be supported by the latest MSVC compiler. Is there an alternative to the following?: template<typename T> ...
Scowl asked 24/4, 2017 at 11:55

6

Solved

Consider the following code: #include <iostream> #include <type_traits> template <class T> constexpr std::size_t type_hash(T) noexcept { // Compute a hash for the type // DO ...
Cahill asked 24/5, 2019 at 11:50

1

Solved

Here we have is_base_of template implementation taken from cppreference.com: namespace details { template <typename B> std::true_type test_pre_ptr_convertible(const B*); //1 template <t...

1

Solved

In one part of my code, I have an abstract function type Function which represents any kind of callable and which can be stored in a heterogeneous container, e.g. std::vector<std::unique_ptr<...

7

Solved

Basically, what I want to achieve is compile-time verification (with possibly nice error message) that registered callable (either a function, a lambda, a struct with call operator) has correct sig...
Mcquiston asked 7/12, 2017 at 15:36

3

Solved

I'm referring to this: #include <utility> template<typename T, typename = std::enable_if_t<std::is_rvalue_reference_v<T&&>>> auto f(T&&) {} int main(){ in...
Carrousel asked 4/7, 2022 at 15:31

1

Solved

I have some std::variant classes, each with several alternatives, and I would like to define a visitor class template that takes a variant as its template parameter and will automatically define a ...
Accessary asked 5/6, 2022 at 18:52

4

Solved

Currently I have: template <typename T> struct typename_struct<T*> { static char const* name() { return (std::string(typename_struct<T>::name()) + "*").c_str(); } }; I wo...
Kati asked 16/7, 2014 at 14:26

2

Is there a way to establish at compile time if a certain function template was specialized? For example, assume the following function template: template<size_t N> void foo(); I want to test...

4

Solved

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...
Fumarole asked 4/11, 2015 at 0:35

0

Suppose we have a current class: template<typename T> struct Inheriter : public T {}; Note that its instantiation would be well-formed only if T is a class/struct that is not declared as fin...

3

Solved

As we all know, classes can't be inherited from fundamental types and from classes that are marked as final. But despite that, the code presented below compiles without any problems on Clang 12 and...
Kilocalorie asked 4/4, 2022 at 12:43

4

Solved

I have a simple code snippet below, which compiles using: g++-9 -std=c++2a -fconcepts This is trying to define a concept that requires the presence of a function. I would expect the output to be ...
Renin asked 15/10, 2019 at 12:20

1

Solved

TL;DR: I am looking for a C++14 equivalent of the following C++20 MWE: template<int sz> struct bits { int v; // note explicit(expr) below explicit(sz > 1) operator bool() const { return ...

1

Solved

Although the idea of template metaprogramming - calculate something at compile time when possible - is wonderful,I wonder if current C++20 features allow us to avoid the TMP fully by using constexp...
Moyer asked 9/2, 2022 at 2:11

1

Solved

Related to, but not the same question as How does std::visit work with std::variant? Implementing std::visit for a single variant conceptually looks like this (in C++ pseudocode): template<class...
Diabolize asked 8/12, 2021 at 1:16

2

Solved

I'm investigating a C++11 idiom which might be called "overloaded lambda": http://cpptruths.blogspot.com/2014/05/fun-with-lambdas-c14-style-part-2.html http://martinecker.com/martincodes/lambda-e...

2

Solved

Is the following code legitimate? template <int N> class foo { public: constexpr foo() { for (int i = 0; i < N; ++i) { v_[i] = i; } } private: int v_[N]; }; constexpr foo<5&gt...

© 2022 - 2024 — McMap. All rights reserved.