Questions tagged [template-meta-programming]
Template meta-programming is a meta-programming technique in which templates are used by a compiler to generate temporary source code, which is merged by the compiler with the rest of the source code and then compiled.
2,363
questions
-1
votes
0
answers
26
views
How to send Url using Whatsapp Meta API?
I'm trying to send a message which opens a given URL when we click on the button.
I've made a template as well on the meta official developers page, but its taking too long to send, approximately 50-...
2
votes
1
answer
38
views
How to forward constructor parameters to a contained tuple when one of the tuple elements has a default constructor and another one doesn't [duplicate]
I am trying to write a class that uses a std::tuple to store a bunch of objects with potentially different types. If the elements all have ctors that take some parameter, I can initialize the tuple ...
1
vote
1
answer
73
views
Overloading Functions with Dummy Structs vs Template Specialisation
I'm refactoring some C++ and came across some dummy structs being used to differentiate between overloaded functions. I'm considering replacing this with template specialization but want to fully ...
2
votes
4
answers
84
views
Extract container template for storing a different type
Given a container of a certain type as input, is it possible to "extract" the container template and instantiate it for a different type? For example:
void f ( auto& x ) {
...
3
votes
3
answers
120
views
Generic Perfect Forwarding of Function’s Result
I encountered an issue when trying to perfect forward a function’s result in a generic way.
Here two functions that provide a result:
Foo provideFooAsTemporary()
{
return Foo{};
}
Foo& ...
0
votes
1
answer
161
views
How to parameter pack pairs of types?
Here's an example usage of a parameter pack:
template <typename... T>
bool foo(A x) {
return (baz<T>(x) || ...);
}
I'd like to do something similar, but with pairs of types. Here's an ...
0
votes
0
answers
43
views
C++ Function Parameters Guiding CTAD
I am trying to do something involving CTAD within function calls and it's best to first explain the desired behavior with an example, before asking my questions. NB: the below is a bit of a ...
0
votes
1
answer
84
views
Union over variadic template parameters
Given a variadic list of types Ts..., can we create a union object that holds exactly a union of these types (and no extra data)?
Certainly this is possible with std::variant. However, the critical ...
0
votes
2
answers
125
views
Template type deduction include the const?
What I have:
template<typename T>
class Holder
{
T& held;
public:
Holder(T& h)
: held(h)
{}
friend std::ostream& operator<<(std::...
0
votes
2
answers
100
views
How to make tag_invoke CPO deal uniformly with types matching a meta-predicate/concept and with those types wrapped in reference_wrapper?
(I'm mostly interested in a c++17 solution, even though you see me using std::unwrap_ref_decay; just imagine I've copied and pasted the possible implementation in my C++17 code. On the other hand, I'm ...
0
votes
1
answer
51
views
Count the number of arguments in generic lambda
I want to create a function that counts the number of arguments in generic lambda functions. SO user "yuri kilochek" has a great solution Count the number of arguments in a lambda but it ...
2
votes
1
answer
118
views
How to Ensure Type Correctness When Implementing Partial Application
As someone who isn't too familiar with the ins and outs of template metaprogramming yet, I wanted to take a shot at implementing a (naive) basic partial-application helper that binds arguments to the ...
1
vote
3
answers
71
views
Merging two tuples according to a given criteria
Suppose that we have two tuples a and b.
I want to implement a function merge_tuples that creates a new tuple c that is a merge of a and b according to a provided binary mask: if a bit is set, we take ...
0
votes
1
answer
72
views
Can folding expressions for variadic templates be binned, and conversion of argument list to vector used instead?
When folding expressions were introduced in C++ 17 I learnt how to write code for variadic templates using the form:
args OP ...
etc.
Now, generally in programming, when we have a long list of ...
1
vote
1
answer
101
views
Obtaining a type from a base class
Suppose we have
class Derived : public Base1, public Base2, ..., public Base<Ts...>> {};
How to write a class that obtains the type std::tuple<Ts...> from Derived? Perhaps Base needs ...