template-meta-programming Questions
2
Solved
Context
Firstly, some context: I'm using an empty struct called nothing to emulate something similar to "regular void" in order to prettify some interfaces that rely on chaining multiple function ...
Carnet asked 17/9, 2017 at 17:18
5
Solved
I have the following function which can take N arguments of different types, and forwards them to N functions templated on each individual type, in this manner (example with two arguments):
templa...
Escent asked 18/9, 2017 at 12:12
3
Solved
Why I have strange output for this code? How to test for a type in the right way?
#include <iostream>
#include <tuple>
#include <type_traits>
template<typename T> struct i...
Gluck asked 7/9, 2017 at 10:2
1
#include <iostream>
#include <tuple>
#include <type_traits>
template<typename TupleType, typename T, std::size_t index = 0> constexpr std::size_t find_from(){
if constexpr...
Arabinose asked 7/9, 2017 at 8:36
2
Solved
I am reading about template metaprogramming. I could not understand what these lines mean; the following code concerns about doing metaprogramming on a linked list.
struct NIL {
typedef NIL Head;
...
Hull asked 3/9, 2017 at 23:57
1
Solved
Consider this program:
#include <iostream>
#include <type_traits>
using namespace std;
struct russell {
template <typename barber,
typename = typename enable_if<!is_co...
Aloud asked 27/8, 2017 at 16:45
1
Solved
Trying to learn how to use Eric Niebler's ranges-v3 library, and reading the source code, I saw that macro definition:
#define CONCEPT_PP_CAT_(X, Y) X ## Y
#define CONCEPT_PP_CAT(X, Y) CONCEPT_PP_...
Rah asked 25/8, 2017 at 18:19
1
Solved
Recently I designed meta-types and the possible operations that would allow compile-time type concatenations:
#include <tuple>
template<template<typename...> typename T>
struct ...
Diandre asked 21/8, 2017 at 16:51
2
Starting from this question (Is it possible to figure out the parameter type and return type of a lambda?) I used the proposed function_traits a lot. However, with C++14 polymorphic lambdas have ar...
Anglian asked 23/1, 2015 at 7:57
2
Solved
Suppose I have a class
enum CallbackType
{
SYNC,
ASYNC
}
template<CallbackType CB = SYNC, typename... Args>
class Callback
{
}
I would like to be able to optionally specificy the callb...
Self asked 4/8, 2017 at 11:1
2
Solved
I'd like to parse c++ containers into another object using their ::iterator member type. Containers who's iterator member type points to an object of a single type (vectors, queues, etc.) will turn...
Bannon asked 11/7, 2017 at 18:37
4
Solved
Assume the following situation:
Type A and type B, B can be implicitly converted to A but the opposite is untrue.
I have a function
template<class T>
void do_stuff(T a, T b);
I want to c...
Rodrique asked 29/6, 2017 at 20:27
2
Solved
template<typename T> struct S {};
template<typename T> struct R {};
int main() {
typedef S<double> s1;
typedef S<int> s2;
typedef R<int> s3;
static_assert(xxx<...
Mastin asked 28/5, 2017 at 19:47
1
Solved
The following code works with GCC and Clang, but not with Visual C++:
#include <type_traits>
struct MyType {
static constexpr std::size_t it = 10;
};
struct MyType2 {
};
template<type...
Culbertson asked 25/5, 2017 at 7:14
1
Solved
Is it possible to pass pointers-to-member as variadic template arguments. I can't seem to figure out the syntax.
for a function call it works like this:
struct A
{
int a;
float b;
}
template &...
Hominoid asked 19/5, 2017 at 18:57
2
Given a list of types, names, and default values, I could easily write a tool that generates valid c++ code that declares a class with a member variable of each type, name and default value. For ex...
Intentional asked 18/5, 2017 at 14:17
4
Solved
Jörg's answer to this question nicely delineates between "normal" templates (what the question refers to, perhaps erroneously, as generics) which operate on data and meta templates which operate on...
Cock asked 8/4, 2017 at 4:12
3
Solved
Making use of Scott Schurr's str_const I have a constexpr string.
class StrConst
{
public:
template<size_t N>
constexpr StrConst(const char (&str)[N])
: str_(str)
, len_(N - 1)
{
s...
Catalan asked 9/4, 2017 at 22:16
1
Solved
The titular question refers to the design decisions in the C++ standard that introduced templates around 1990.
Why did the designers use <> (angle brackets) instead of, say, () (round brack...
Mouldy asked 6/4, 2017 at 11:34
2
Solved
In C++17, it is trivial to implement an overload(fs...) function that, given any number of arguments fs... satisfying FunctionObject, returns a new function object that behaves like an overload of ...
Maravedi asked 23/3, 2017 at 21:16
2
Solved
Consider the following code:
// -------------------------------------------------------------------------- //
// Preprocessor
#include <array>
#include <vector>
#include <utility>...
Chancemedley asked 26/3, 2017 at 21:26
9
Solved
How can one check if one parameter pack (interpreted as a set) is a subset of another one?
So far I only have the frame (using std::tuple), but no functionality.
#include <tuple>
#include &...
Parch asked 3/3, 2017 at 14:6
5
Solved
I'm trying to get the sum of a const int array as a constexpr so that I can use sum as the size of another array
constexpr int arr[] = {1, 2, 3};
constexpr int sum1 = std::accumulate(arr, arr + 3,...
Codd asked 14/2, 2017 at 6:19
1
It is better not to bind std::clamp return value to const ref, if one of its min or max parameters are rvalues.
Typical realization of std::clamp (very simplified):
template <class T>
const...
Hawking asked 26/1, 2017 at 9:0
4
I try to write a IsLast type traits to check if a given type is the last one in a std::tuple, but the code below does not compile. I know how to get around it but I am curious why the compiler does...
Privily asked 4/2, 2017 at 16:28
© 2022 - 2024 — McMap. All rights reserved.