template-meta-programming Questions

4

Solved

I've seen types that have corresponding to_string() function, but haven't overloaded operator<<(). So, when inserting to stream, one has to << to_string(x) which is verbose. I'm wonderi...
Sinatra asked 22/1, 2016 at 6:56

2

Solved

The following code does not compile, and I just can't figure out why. template <class T, class... Ts> typename std::enable_if<sizeof...(Ts) > 0>::type func() { // nop } The error...

2

Solved

I have a type like this: template<typename T> struct wrapper { using foo = typename T::foo; using bar = typename T::bar; using baz = typename T::baz; // More of those... }; I would lik...
Naturalize asked 6/1, 2016 at 11:49

1

Solved

While experimenting with some template constraint constructs, I encountered a surprising behavior in Clang 3.7: struct constraint_success {}; struct constraint_failure {}; template<bool> st...
Citadel asked 10/1, 2016 at 13:31

2

Solved

The C++ std namespace contains the helper functions std::not1 and std::not2. They both take a unary or binary predicate functor, respectively, and return a std::unary_negate or std::binary_negate p...
Technology asked 17/12, 2015 at 8:54

3

Solved

The typeid allows to assign a unique std::type_index to each type at runtime. I would like to do the same, statically using two metafunctions : // Get a unique integral number associated with the ...
Boll asked 11/12, 2015 at 18:26

1

This is my first attempt at SFINAE: #include <type_traits> #include <iostream> struct C1 { using T = int; }; struct C2 { using T = void; }; // For classes that declare T = int tem...
Nicobarese asked 10/12, 2015 at 15:23

1

Solved

I would like to convert an std::array to another std::array, multiplying each of its elements by a specific number. What I have right now obviously doesn't work: #include <array> #include &...
Superstructure asked 1/12, 2015 at 22:14

4

Solved

This is a code snippet that I am going to use in order to check whether the variadic template types are unique: template <typename...> struct is_one_of; template <typename F> struct i...

2

Solved

In c++11 I have very neat and working code for extracting std::tuple item by type (As I know this feature even placed to c++14 stl) Now I'm facing with the task to select item by the inherited cla...
Candleberry asked 30/11, 2015 at 13:33

6

Solved

I need to check is some integer prime in compile time (to put the boolean value as template argument). I've write code that do it well: #include <type_traits> namespace impl { template &lt...
Nunciature asked 18/8, 2013 at 21:2

3

Solved

For simplicity, let's use std::tuple as our type list. What is the best (concise, least recursive, etc.) way to swap two types in a std::tuple? Illustration of the functionality through the use o...
Stent asked 22/11, 2015 at 20:3

2

Solved

In the following code, the compiler is requesting the base class X to be default constructible. However, if I remove the virtual keyword from the inheritance of the class Node, the access to the me...

2

Solved

I recently started to learn modern template metaprogramming and I wrote myself an index_of function for types. template<std::size_t Index, class C, class A> struct mp_index_of_impl{}; templa...
Oyster asked 29/10, 2015 at 12:14

2

Solved

I tried to code a basic, compile-time version of std::accumulate() by defining a class template that would recursively iterate through a given range and would add the elements at each iteration. W...
Decorous asked 15/10, 2015 at 20:16

1

Solved

I'm trying to come up with a robust way of determining whether a given symbol is a function template. The following: import std.traits: isSomeFunction; auto ref identity(T)(auto ref T t) { return...
Heilungkiang asked 9/10, 2015 at 17:16

2

Solved

I have a template function where an enum type is converted to its underlying type which works fine, but I wrote an overload which should take an integral number and return itself and it give me an ...
Brehm asked 8/9, 2015 at 14:31

1

Solved

In the answer to this post "(Partially) specializing a non-type template parameter of dependent type", it states: The type of a template parameter corresponding to a specialized non-type argume...
Pinna asked 19/8, 2015 at 20:17

2

Solved

I am watching the talk Modern Template Metaprogramming by Walter E. Brown. At 54:40 a code is given as below template<class T, T v> struct integral_constant{ static constexpr T value = v; ...
Pronty asked 3/9, 2015 at 2:30

2

Solved

I've been confused recently by a few code examples -- sometimes it seems that inheriting typedefs exposed by a base class works, and sometimes it seems that it doesn't. My questions are Wh...

3

Solved

I have some code that generates assembly for a JIT idea I'm working on. I use meta-programming to generate calls by analyzing the function type and then generating the correct assembly to call it. ...
Tripura asked 15/8, 2015 at 13:45

2

I'm learning SFINAE and this is my first attempt to print "YES" only for those types you can output with std::ostream (forget about std::operator<<(std::ostream &, T) for now...): templa...

1

Solved

While writing a small template metaprogramming library for personal use, I came across an interesting problem. Since I was reusing a few partial specializations for some metafunctions, I decided ...

1

Solved

I have come across a small (easily solvable though) problem while writing valid C++03 template code, which compiles normally, that will not compile when using the C++11 dialect. The problem arises...
Christy asked 16/7, 2015 at 6:44

1

Solved

I have been trying to write a trait which figures out whether some callable takes a rvalue reference as its first parameter. This lets some metaprogramming adjust whether move or copy semantics are...
Garratt asked 12/6, 2015 at 11:51

© 2022 - 2024 — McMap. All rights reserved.