template-meta-programming Questions

2

Solved

I would like to write a sum function with variable number of argument with the condition that it should ignore argument that are not std::is_arithmetic I have figured out a recursive version that ...

5

Solved

Here is a minimal example: struct incomplete_type; template<typename T> struct foo { using type = std::conditional_t<std::is_arithmetic_v<T>, std::conditional_t<sizeof(T) &lt...

3

Solved

I would like to create something similar to rust unsafe scope in C++. The idea is that I have some functions performing number of checks. For example: void check() { if (...) throw exception(......
Biskra asked 30/11, 2018 at 8:15

2

Solved

Here's what I want to do; posting the whole code because it's not too long and also to demonstrate the specific task I'm trying to solve. Basically, I need a way to iterate values from parameter pa...
Gigantopithecus asked 28/11, 2018 at 15:22

3

Solved

I'm struggling with some template programming and I hope you can give me some help. I coded a C++11 interface that, given some structs like: struct Inner{ double a; }; struct Outer{ double x, y,...

2

Solved

I am trying (at compile time) to unpack integers as arguments to a variadic function. The idea would be to have those values packed in an array or in a std::index_sequence (c++14) at compile time. ...
Intinction asked 24/11, 2018 at 9:3

4

Solved

I have following two functions: void bar(const std::string &s) { someCFunctionU(s.c_str()); } void bar(const std::wstring &s) { someCFunctionW(s.c_str()); } Both of these call some C ...
Anti asked 20/11, 2018 at 18:53

3

Solved

I'm trying to practice some template programming. Maybe there's a standard way to do this, and I would be thankful for such answers, but my main goal is to practice the template programming techniq...
Archaeological asked 20/11, 2018 at 13:29

3

Solved

I am new to template meta programming and was trying to create a program that would find if a parameter pack has consecutive same type names. For example <int, int>, <int, char, char> w...

2

Solved

I want to specialize a function for a subset of classes which: have a certain static data member variable, and such variable has only certain possible values. The code below illustrates the intent...

1

Solved

I'm often seeing occurrences of this {} in templated code. I'm not sure I understand what's it doing. For example: std::enable_if_t<std::is_copy_constructible<T&>{} && !std::i...
Lorileelorilyn asked 22/9, 2018 at 5:53

1

Solved

I'm trying to experiment with CRTP but I am puzzled on why the following code does not compile. template<template<class...> class CBase> struct ComponentX : public CBase<ComponentX&...
Mahound asked 20/9, 2018 at 8:54

0

I'm trying to understand why I'm getting different behavior with 2 templates that should be equivalent to me Given template<template<typename...> class TT, typename T1, typename T2> c...

2

I am writing an entity entity component system game engine. As a part of this, I have written a Manager class which will register various IBase implementations and, later, allow me to instantiate t...
Audiphone asked 25/8, 2018 at 16:29

4

I am implementing a binomial coefficient (n choose k) function in C++. Besides using a "normal" function (which is evaluated at runtime) this also can be accomplished using template metaprogramming...
Kinshasa asked 28/7, 2017 at 16:9

2

I remember that ten years ago, there was a piece of code using c++ template meta programming which can deduce the array dimensions from an array name. For example int a[2][3][4][5][6]; cout <&...
Fishbowl asked 21/8, 2018 at 5:52

5

Solved

This previous answer shows how to apply function based on the validity of a call: here. However, it applies to two functions. I was wondering if the concept could be generalized to N functions usin...

1

Solved

Say I have a class of three template type parameters. template<typename Transformer, typename Criteria, typename Strategy> struct ConfiguredPipeline {}; And have the following classes to b...

1

Solved

Using SFINAE, has_value_int<T> and has_value_auto<T> both try to detect whether class T has a static constexpr function named value. Using int to parametrize true_type, has_value_int&...
Taliped asked 27/7, 2018 at 15:34

3

Solved

I've experimenting with C++17 lately and found this: template<size_t i> void recurse() { if constexpr(i == 0) return; return recurse<i - 1>(); } Trying to call recurse<4>();...
Hakluyt asked 18/7, 2018 at 9:26

3

Solved

The following definition has proven to be very useful for me: template<class Func, class... Args> void apply_on_each_args(Func f, Args... args) { (f(args), ...); } Basically, the argument...

1

Solved

I've seen this expression in a library implementation and I basically understand it is been used to foster SFINAE or even to pull the static_assert trigger. It basically takes the form: template ...
Unconformable asked 16/6, 2018 at 14:43

2

Solved

Say I have a large code using Array of Structures (AoS) memory layout. I would like to build a zero-cost abstraction in C++ which allows me to switch between AoS and SoA with as little refactoring ...

4

Solved

I have written a class multi_array which is sort of an extension of std::array to multiple dimensions. template <typename T, std::size_t... N> class multi_array { template <std::size_t.....

3

Solved

Imagine that you have several classes and all of them contain a static variable of the same meaning, but it's names differ in different classes. A toy example: class Point2D { public: static con...
Dicta asked 27/4, 2018 at 13:13

© 2022 - 2024 — McMap. All rights reserved.