template-meta-programming Questions

1

Solved

I have a number of nested loops with small sizes I, J, ... known at compile time, e.g. for(int i = 0; i < I; ++i) { for(int j = 0; j < J; ++j) { // ... // do sth with (i,j,...) } } I ...
Marcelenemarcelia asked 29/7, 2016 at 7:52

5

Solved

I have an attribute vector that can hold different types: class base_attribute_vector; // no template args template<typename T> class raw_attribute_vector : public base_attribute_vector; r...
Gurgle asked 28/7, 2016 at 18:28

4

Solved

I'm managing units conversion. Say us that I reached a state where I achieve that. The heart of my conversion between different units lies on the following generic template function: template <c...
Cattle asked 28/7, 2016 at 13:21

2

Solved

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 ...
Battlement asked 27/7, 2016 at 21:3

2

Suppose we have function such as template <typename T, unsigned N> void foo(); and for simplicity assume that we know that only (constant) values N_1, N_2 ... N_k are valid for N. Now, su...

3

Solved

Intro I'm looking for a pattern to convert C++ type traits into their variadic counterparts. A methodology to approach the problem would be appreciated and generative programming patterns to autom...

3

Solved

I have the following piece of code (c++11): template <typename F, typename FirstT, typename... FIn> auto min_on(F f, FirstT first, FIn... v) -> typename std::common_type<FirstT, FIn....

4

C++14 will have functions whose return type can be deduced based on the return value. auto function(){ return "hello world"; } Can I apply this behaviour to functions that use enable_if for th...

1

With std::is_constructible one can question some given type for the presence of a certain constructor: struct A {}; struct B { explicit B(int, A, double) {} }; int main() { std::cout<<std...
Daley asked 19/4, 2015 at 21:12

3

Solved

There are tons of questions about the least common ancestor algorithm, but this one is different because I'm trying to determine the LCA at compile-time, and my tree is neither binary nor a search ...

3

Solved

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 possible for me to determine the base temp...
Thorsten asked 9/4, 2016 at 2:16

3

Solved

Consider the following code, which has an unreachable call to undefinedFunction. void undefinedFunction(); template <bool b = false> void foo() { static_assert(b == false); if (b) undefi...
Borszcz asked 8/4, 2016 at 22:3

3

Solved

I am trying to write a general static_for implementation that can accept bounds, an increment function & a comparison function to run a loop through. I have been using this construct with simpl...
Orosco asked 7/4, 2016 at 22:4

4

I have some performance critical code that involves sorting a very short fixed-length array with between around 3 and 10 elements in C++ (the parameter changes at compile time). It occurred to me ...

1

Solved

Currently, only doubles can produce a template of chars in a user defined literal: template <char...> double operator "" _x(); // Later 1.3_x; // OK "1.3"_y; // C++14 does not allow a _y use...

4

Solved

template<class... Foos> // N = sizeof...(Foos) template<typename... Args> // M = sizeof...(Args) void split_and_call(Args&&... args) { // Using Python notation here... Foos[0]...
Ferdinandferdinanda asked 29/8, 2015 at 17:21

12

Solved

I'm told that the template system in C++ is Turing-complete at compile time. This is mentioned in this post and also on wikipedia. Can you provide a nontrivial example of a computation that exploi...
Clemens asked 9/10, 2008 at 20:53

1

Solved

TL;DR I want to write a template function Process(T value) that behaves differently for different values depending on the existence of a non-member function CreateProcessor<T>(). What can I d...
Grippe asked 11/3, 2016 at 12:5

2

Solved

Preface. I'm trying to get somewhat deeper understanding of C++ template metaprogramming and it seems, that I'm stuck... I'm writing a library, which we will use for binary data [de]serialization. ...
Vicar asked 1/12, 2014 at 3:51

4

Solved

Say I have a simple nullary template function templated on a single parameter, with two specializations, one for unsigned long, and one for size_t (contents not important): template<typename T&...
Cytogenesis asked 15/2, 2016 at 22:23

2

Solved

Following my original question and considering some of the proposed solutions I came up with this for C++14: #include <algorithm> #include <exception> #include <iterator> #includ...
Turnout asked 10/2, 2016 at 15:14

1

Solved

Thanks to some trickery I'm able to generate a table at compile time, the values in the table are not very useful though. For example a table 5x5 looks like this: 1,2,3,4,5, 1,2,3,4,5, 1,2,3,4,5, ...
Perennial asked 11/2, 2016 at 8:58

1

Defining multi-dimensional array using the T[][][] syntax is easy. However, this creates a raw array type which doesn't fit nicely into modern C++. That's why we have std::array since C++11. But th...

1

Solved

Originated from this CodeReview topic: #include <cstddef> #include <algorithm> #include <iostream> #include <type_traits> #include <utility> template <typen...

1

Solved

I know about std::is_pod. But it checks more than just aggregate types. Or, is std::is_pod just the best we can do? Basically, I want to write a function template for this: template <typename ...

© 2022 - 2024 — McMap. All rights reserved.