template-meta-programming Questions

4

Solved

The problem is the following, in C++14: Let's have two functions FV&& valid_f, FI&& invalid_f, and arguments Args&&... args The function apply_on_validity should apply val...

2

Solved

In a type like the unspecialized template struct pointer_traits (i.e. template <class Ptr> struct pointer_traits), there exists a member alias template rebind that is defined to be Ptr::rebin...
Afterburning asked 18/1, 2017 at 16:9

3

Solved

I'm currently playing around with template metaprogramming. I'm trying to make a finite state machine by using tmp. I know that there are several implementations in the web but I want to implement ...

1

Solved

Is it possible to create (possibly const) std::set that would be filled with elements at compile time? I am wondering about std::set/std::unordered_set specifically, not a set of templated functio...
Bayly asked 10/1, 2017 at 11:45

5

I have a bunch of types that have a name. (They have more features, but for the sake of this discussion only the name is relevant.) These types and their names are setup at compile-time using a mac...
Assemblage asked 23/10, 2013 at 7:20

4

Solved

I need to compute the product of a bunch of numbers at compile time passed to a templated struct. I succeeded to make an ugly solution : template<std::size_t n1, std::size_t ...args> struct ...
Grillwork asked 31/12, 2016 at 13:30

4

How is template metaprogramming working here (static const int value = 1 + StarCounter<\U>::value;) to print out 3 ? #include <iostream> template <typename T> struct StarCounter...
Minesweeper asked 18/12, 2016 at 7:45

1

Solved

I like to do some check when one of my ctors are called with compile time known value. Is there a way to detect it? So when someone call this: A a (10); since 10 is a compile time known constan...
Reorganize asked 15/12, 2016 at 15:40

0

Considering the following code: #include <unordered_set> #include <type_traits> #include <cstring> constexpr auto cstring_hash(const char* istring) -> size_t { return (*istr...
Ganges asked 7/12, 2016 at 8:37

2

I'd need a template which can be called like this: int x = type_exists< std::vector<int> >::value; This should set x to 1 if #include <vector> was present (either explici...
Drivein asked 15/12, 2013 at 11:3

3

Solved

I am trying to implement a C++ template meta function that determines if a type is callable from the method input arguments. i.e. for a function void foo(double, double) the meta function would re...
Ease asked 29/11, 2016 at 13:52

2

Solved

I just read the book "Practical C++ Metaprogramming" and it has the following example that I cannot compile. Can you help sort this out for me. template <typename F> struct make_tuple_of_par...
Poaceous asked 29/11, 2016 at 14:21

1

Solved

Assume I have a wrapper type template <typename T> struct X {/*..*/}; and I cannot just X(X&&) = default because I have to do non-trivial stuff there. However, I want it to be noe...
Multiped asked 24/11, 2016 at 12:35

1

Solved

In n4502 the authors describe an early implementation of the detect idiom that encapsulates the void_t trick. Here's its definition along with usage for defining a trait for is_assignable (really i...
Filippo asked 15/11, 2016 at 13:6

1

Solved

I'm following the How to implement a constant-expression counter in C++ tutorial and I'm trying to fix the C++14 Reflections Without Macros, Markup nor External Tooling talk limitations. The basic ...
Galway asked 12/10, 2016 at 21:21

1

Solved

Any idea about how to implement this function? template <class ... Ts> auto unzip(const list<tuple<Ts...>> & l) { ... } This function would receive a list of tuples and w...
Centralism asked 20/10, 2016 at 10:18

2

Solved

I am confused about how CRTP is compiled. If we have something like this: template<class T> class Base { }; class Derived : public Base<Derived> { }; Why doesn't something akin to ...
Breda asked 3/10, 2016 at 3:11

1

Solved

Is there a way to ensure a template parameter is an enum-class type? I know type_traits has std::is_enum, but I don't want it to match regular enums, just enum_classes. Example of the wante...
Reganregard asked 1/10, 2016 at 14:12

1

Solved

The desired behaviour can be illustrated as follows: void foo(int x, int y) { std::cout << x << " " << y << std::endl; } int main() { all_combinations<2>(foo, std:...
Bathysphere asked 25/9, 2016 at 14:23

1

Solved

Disclaimer: This is never meant to be used in production code. It's an exploration at the edges of C++ :) My question is a follow up, based on a discussion with @Johannes Schaub here: calling pri...
Romy asked 22/9, 2016 at 20:35

1

Solved

Given 2 types T and U I want to detect whether it's possible to call operator * between those to objects (i.e is it possible to write t * u where t is of type T and u is of type U) I'm using c++ d...
Colorblind asked 11/9, 2016 at 17:6

2

Solved

Assume that I have a nested boost::variant-type TNested containing some types and some other boost::variant types (that itself cannot contain again boost::variant types, so that there will be no re...

2

Solved

So I'm designing a sort of my_numeric_cast function to limit the types of conversions available when using a framework I'm writing. It was pretty straight forward to do something like template&lt...
Haircloth asked 31/8, 2016 at 13:8

4

Solved

I have a family of classes with methods with the following signature: double compute(list<T> pars) This method performs a calculation with the parameters received through pars. For each co...
Jurado asked 26/8, 2016 at 12:35

2

Solved

Built with this online compiler, the following code: #include <iostream> #include <type_traits> #include <tuple> int main() { std::cout << std::is_trivially_copyable<s...
Scabble asked 5/8, 2016 at 2:0

© 2022 - 2024 — McMap. All rights reserved.