fold expressions, since C++17, are used to reduce the parameter packs of variadic templates over a binary operator.
Questions tagged [fold-expression]
144 questions
0
votes
0 answers
MSVC templated lambda functions parameter pack failure
I stumbled upon an error, and I am unsure what is causing it. You can find the code here: https://godbolt.org/z/F9zdHg
#include
#define USE_PACK 1
#if USE_PACK == 1
template
auto…

lightxbulb
- 1,251
- 12
- 29
0
votes
2 answers
How to fold and static_assert all parameters?
The following doesn't compile:
template
void check_format(Args&&... args)
{
static_assert((true && std::is_fundamental::value)...);
}

darune
- 10,480
- 2
- 24
- 62
0
votes
1 answer
Fold Expressions, parameter pack expansion, recursion in class member function
I'm trying to create a Finite State Machine hierarchy type structure. What I'm trying to do is check to see if the current state exist if it doesn't return, then check to see if all of the next states exist. As soon as one of them fails it will…

Francis Cugler
- 7,788
- 2
- 28
- 59
0
votes
1 answer
Unpack a Variadic Templated Class when the constructor takes itself?
This is a follow up of my last post. I have successfully been able to set and get values of the classes. However, now I am trying to take this a step further and have the constructor take itself as the parameter. However, I am not sure how to…

Sailanarmo
- 1,139
- 15
- 41
0
votes
1 answer
c++17 fold expression dot product simpfily
I want replace old meta recursive function with fold expression, the below meta function is the dot product
How do I replace this following code to fold expression?
constexpr static auto result = Head1 * Head2 + DotProduct
- ,…

user3770234
- 55
- 6
0
votes
1 answer
Widest possible type similar to a given one - C++
Is there any "tool" in standard, that for such template function:
template
auto average(FirstArg &&firstArg_, Args&&... args_)
{
// example:
std::widest_type_t sum;
sum +=…

Poeta Kodu
- 1,120
- 8
- 16
0
votes
2 answers
fold expression: right shift initialization behavior
I am having fun with the fold expressions to understand better where I will be able to use them in my projects. So I choose to initialize them with a simple
(datas = ... = 1);
So far everything work as expected, every value is at 1. Then I tryed to…

Gabrielle de Grimouard
- 1,917
- 15
- 22
0
votes
1 answer
C++17: integer_sequence usage with compilation error
I wish to use a integer_sequence to judge if a range of numbers are all under a certain value: is_range() will return true, else return false, like below:
#include
#include
using namespace std;
template

Troskyvs
- 7,537
- 7
- 47
- 115
-1
votes
0 answers
C2679: binary '=': no operator found... error when using fold expression
Hello I have a class like std::vector and I want to be able to do this:
MyVec vec(2, 5, 91, 27);
this is the code:
template
explicit MyVec(const args&... _args)
{
// some code...
size_t i = 0;
…

Tornike Kacadze
- 13
- 5