fold-expression Questions

2

Solved

I am playing around with fold expression in c++17 with the latest clang++. I tried to implement the less operator for an array using this which I want to use for fixed size strings. Here is where ...
Luminescence asked 7/7, 2015 at 16:29

2

Solved

I am learning the new c++17 fold expression and I saw this code from c++17 fold expression. I would like to know why this code work : template<typename ...Args> void printer(Args&&.....
Dye asked 29/8, 2016 at 10:22

4

Solved

I was expecting this code to create 10 elements vector each constructed as A{1, 2, 3.0}, but in reality the output is 1 #include <iostream> #include <vector> struct A { int a{0}; int...
Borne asked 14/7, 2023 at 17:10

2

Solved

I want to design a compile-time-string class CTString that can e.g. be constructed from a parameter pack of string literals. This works using a comma-fold-expression (for this toy example, I tried ...

5

Solved

I am using a fold expression to print elements in a variadic pack, but how do I get a space in between each element? Currently the output is "1 234", the desired output is "1 2 3 4" template<t...
Trotskyism asked 11/7, 2018 at 9:23

2

How do you restrict the allowed types in variadic templates and fold expression using C++20 concepts? For example suppose I'd like to restrict the following fold expression to only support integral...

3

Solved

I've got a template function taking a parameter pack. I want to expand it into calls to a second function while also supplying the index of the item in the pack. I probably can work out how to do i...
Keil asked 2/9, 2021 at 0:21

1

Solved

None of the compilers I tried accept such code: template <int ...a> bool foo() { return (a<=> ... <=>0); } But for any other <=,>=,==,!=,<,> it compiles. cppreference ...

1

Consider the following snippet: #include <iostream> template <typename... types> void writeall(const types & ... items) { (std :: cout << ... << items); } temp...
Compensate asked 11/2, 2018 at 9:47

2

Solved

I've been hoping to use new C++17 features like fold expressions and std::apply() to simplify some C++11 code I have that uses tools like std::index_sequence and std::initializer_list for some oper...
Aesthetics asked 24/2, 2021 at 18:47

3

Solved

I have a function taking a variadic parameter pack and at the beginning I want to check that all elements compare equal. Can I somehow use the new C++17 fold-expressions to write that succinctly as...
Contrapositive asked 18/10, 2017 at 8:53

9

Solved

While trying to play around with C++17 fold expressions, I tried to implement max sizeof where result is maximum of the sizeof of types. I have an ugly fold version that uses variable and a lambda,...
Dyslogia asked 25/9, 2017 at 11:47

3

Solved

Background We know that the concept std::same_as is agnostic to order (in other words, symmetric): std::same_as<T, U> is equivalent to std::same_as<U, T> (related question). In this qu...
Karren asked 6/11, 2019 at 6:44

1

Solved

I just started learning C++17 fold expressions. I understand that it is possible to apply a fold expression to a tuple, like in the following example (inspired by replies to this question): #includ...
Kanchenjunga asked 10/7, 2020 at 20:8

5

Solved

template<class Msg, class... Args> std::wstring descf(Msg, Args&&... args) { std::wostringstream woss; owss << Msg << ". " << ... << " " << args <&...
Centralize asked 4/12, 2019 at 11:30

1

Solved

In C++11 we have variadic templates, in which we can std::forward the arguments like in the following code #include <utility> #include <iostream> #include <string> void printVar...
Pentyl asked 30/10, 2019 at 9:44

3

Solved

I'm trying to figure out how to fold only part of the variadic template pack with C++17 fold expressions. Suppose I'd like to create a compile time "separated string" like "str1_str2_str3_....." I...
Deluxe asked 24/9, 2019 at 20:22

1

Solved

On cppreference, I saw that there are four types of fold expressions, unary right, unary left, binary right, and binary left. What is the type of this fold expression here? I'm having a hard time u...
Loopy asked 3/9, 2019 at 18:47

1

Solved

I was experimenting with using arbitrary functions in fold expressions, when I found the following code that compiles with gcc but does not compile with clang. enum Enum { A = 3, B = 8, C = 5 }...
Sisk asked 5/7, 2019 at 7:2

1

Solved

Is there any specific cases you cannot correctly do with std::conjunction/std::disjunction and not using the more "fundamental" (i.e. language feature instead of library feature) fold expression ov...
Lamelliform asked 14/3, 2019 at 11:21

2

Solved

I would like to write a sum function with variable number of argument with the condition that it should ignore argument that are not std::is_arithmetic I have figured out a recursive version that ...

6

Solved

What is the easiest way to print a parameter pack, separated by commas, using std::ostream? Example: template<typename... Args> void doPrint(std::ostream& out, Args... args){ out <&...
Onomatopoeia asked 9/12, 2014 at 9:11

3

Solved

In C++17, fold expression is available, so to print arguments, we could use #define EOL '\n' template<typename ...Args> void output_argus(Args&&... args) { (cout << ... <...
Jackstraw asked 8/11, 2018 at 22:16

7

Solved

I don't understand why this doesn't work. Could someone who understands templates and variadic expression folding explain what is going on and give a solution that does work? #include <iostream...
Lipoprotein asked 1/5, 2017 at 13:22

3

Solved

The following definition has proven to be very useful for me: template<class Func, class... Args> void apply_on_each_args(Func f, Args... args) { (f(args), ...); } Basically, the argument...

© 2022 - 2025 — McMap. All rights reserved.