template-meta-programming Questions
1
Solved
I would like to find out if a type defines a member function with a template argument but the template argument is constrained with SFINAE.
Example I have a type A with a single function foo
str...
Cammiecammy asked 10/4, 2018 at 14:3
2
Solved
Currently, I have a variant of map types, where I hard-code all variations of key-value pairs, as such:
// for example, if we support std::string and int types as key-value pair
using MapCombinato...
Timberlake asked 26/3, 2018 at 12:46
1
Solved
Problem description:
C++17 introduces std::invocable<F, Args...>, which is nice to detect if a type... is invocable with the given arguments. However, would there be a way to do it for any a...
Trollop asked 8/3, 2018 at 6:1
1
Solved
This question combines several pieces of code and is a bit complicated, but I tried slimming it down as much as possible.
I am trying to use std::enable_if to conditionally invoke the correct cons...
Carbamate asked 14/3, 2018 at 20:20
2
Solved
I want to convert an "array" of bool to a integer sequence.
So I need to compute an std::array at compile time.
Here is my code
#include <array>
template<typename InputIt, typename T &...
Instrument asked 4/3, 2018 at 15:50
2
Solved
In C++17, void_t allow to easily do SFINAE with class/struct templates:
template <class T, class = void>
struct test {
static constexpr auto text = "general case";
};
template <...
Pus asked 1/3, 2018 at 8:24
1
Solved
Consider the following code, where a functor derived, inherits from two base classes base1 and base2 each providing different overloads:
// Preamble
#include <iostream>
#include <function...
Prindle asked 2/3, 2018 at 7:54
1
Solved
Is it possible to use metaprogramming tricks to allow SFINAE on assembly blocks? For example to detect if an instruction like "CPUID" is available on a processor: (this is not valid code, but illus...
Deem asked 29/1, 2018 at 13:11
2
Solved
Gcc and clang seem to disagree on whether this code should compile or not:
#include <type_traits>
template <typename Signature, int N = 0>
struct MyDelegate { };
template <typenam...
Savell asked 25/1, 2018 at 15:54
3
Solved
I am referring to this answer:
https://mcmap.net/q/543057/-template-specialization-multiple-defined-symbols
I ran into a similar issue as the OP of the cited question,
having a function
template...
Anglaangle asked 23/1, 2018 at 13:12
1
Solved
The other day, I discovered that this was possible:
template <class T> struct base {};
struct derived: base<int> {};
int main()
{
// The base class template is accessible here
typen...
Magna asked 15/1, 2018 at 18:36
1
I would like to have only one template function. So I came up with like...
template<typename Iteratable, size_t N,
typename =
std::enable_if_t<
std::is_same_v<Iteratable, const std::i...
Reverent asked 2/1, 2018 at 12:37
5
Solved
Consider the following example:
template <class T> class method_traits;
template <class T, class Ret, class... Arg> class method_traits<Ret(T::*)(Arg...)> {
public:
using type =...
Gemmagemmate asked 22/10, 2017 at 15:55
1
Solved
Suppose I have a compile-time constexpr array and a variadic class template with a set of non-type parameters of the same type as the elements of the array.
My objective is to instantiate the clas...
Furore asked 13/11, 2017 at 11:45
2
Solved
I recently ran across this puzzle, was finally able to struggle out a hacky answer (using index arrays), and wanted to share it (answer below). I am sure there are answers that use template recursi...
Barrada asked 4/7, 2012 at 3:32
3
Solved
I recently watched a video which inspired me to write my own neural network system, and I wanted to have the amount of nodes in the network be adjustable.
At first I achieved this at runtime by pa...
Semiotic asked 28/10, 2017 at 12:53
1
How do you write a simple C++ code to simply run a for loop with a certain unrolling factor?
For instance, I need to write a for loop that assigns a value of i to each index of the array, i.e, A[i]...
Polyglot asked 22/10, 2017 at 6:4
2
Solved
I have found this example/class in a book for creating SDBM hashes at compile time. Unfortunately it does not compile (neither with c++11 nor c++14). I am getting error: call to non-constexpr funct...
Amphitropous asked 22/10, 2017 at 9:0
6
Solved
Lets say, I have
two lists of non-type template parameteres (which might have a different type)
a template foo that takes one value of each of those lists as a parameter
How can I create a va...
Spies asked 19/10, 2017 at 13:53
1
I have an object which holds a unique_ptr and as such can't be copy constructed without doing a deep copy (which I don't want).
I'd like to have std::any hold that object, but the only alternatives...
Equipoise asked 20/10, 2017 at 15:14
1
I claim that this program ought to be well-formed: it declares a constexpr member function of S<int>. However, both GCC and Clang reject this program.
template<class T>
struct S {
con...
Peccant asked 17/10, 2017 at 0:7
1
Solved
Given an multi-dimensional array with shape [A][B][C][D] but stored as a 1-dim array with length [A*B*C*D]. I want to use template meta-programming to simplify the index-computation. The index (a,b...
Thromboplastic asked 23/7, 2017 at 19:52
2
Solved
I have simplified my somewhat more difficult problem to this:
http://coliru.stacked-crooked.com/a/2660b33492651e92
#include <iostream>
#include <string>
#include <type_traits>
...
Senzer asked 6/10, 2017 at 15:5
4
Solved
Given two or more example functions, is it possible to write templated code which would be able to deduce the arguments of a function provided as a template parameter?
This is the motivating examp...
Agc asked 2/10, 2017 at 21:4
2
Solved
I'm trying to write an RAII-compliant resource wrapper, and I'm getting stuck on how to form the semantics of the template parameters.
For example, I could write a function to delete my resource:
...
Fool asked 2/10, 2017 at 16:59
© 2022 - 2024 — McMap. All rights reserved.