Похожие чаты

Uint64_t combine_squares(Square square = 0) { return square; } template<typename

First, typename ... Squares>
uint64_t combine_squares(First first, Squares ... rest)
{
combine_squares(rest...);
}
Hi. In order to get my function work I had to implement that first function. But it looks ugly, because it doesn't make sense with a single variable. Also if I pass two variables but let them have default values still it will be ugly because it will serve no purpose other than allowing the second function to work. This is my first time with variadic templates. Are there any other ways to do this? Note that I've simplified the second function, it actually does something more I just emphasized the part that interests me.

4 ответов

12 просмотров

Ah refactoring variadic templates to something clean while still keeping it performant and the binary size in check is a pain, the no of recursions and the compile time can quickly go out of hand for more than 4-5 parameters with different type. There is a way to compress variadic templates but that uses returning as an initializer list. Also C++ 17 gives you four fold expressions which can be helpful. Please send your actual code, especially the implementation of what uint64_t combine_squares(Square square); does.

and the reason why first, and rest of the combine_squares need to be seperated

Hayk-Zneigras Автор вопроса
Manav | avoid unnecessary messaging me
Ah refactoring variadic templates to something cle...

Thanks. There I call a comvine_squares to combine first and combine_squares(rest...) that's why I considered the option of creating a function with two arguments each with default values. And finaly I return the result of combine_squares with two arguments. What it does is that it generates uint64_t values from each argument and return their bitwise or. Sorry that I'm not sharing the code now, I'm in university, but I think the other time I asked a question there was that code too. Let me check

Похожие вопросы

Обсуждают сегодня

Если у меня есть такой класс: Object = {} function Object:new(a_name, a_transform, a_color, a_mesh, a_material, a_shader, a_textures) local private = {} private.n...
Cuarno Vile
4
А кто-то пробовал, уезжая из Эстонии получить э-рез и продолжить вести предпринимательскую деятельность внутри Эстонии, используя свой OÜ?
Lalalashechki Lalala
62
Is Kadena onto something special? No one really knows. Good luck!
Bright Uncle Stephen EqualBet
40
At which price point will BCH, an ASIC mined coin, be succeptible to reorg attacks because of low hashrate? $10? $1? $0.1? $0.01?
Kishniev
18
я не магистр хаскеля, но разве не может лейзи тип конвертнуться в не-лейзи запросив вычисление содержимого прям при инициализации?
deadgnom32 λ madao
100
зачем же переименовывать ? чтобы кол-во участников возросло или вдруг IBM от этого снова на свифте начнет кодить ? Я не понимаю что страшного в том что свифт гавно, если это т...
Oleh Nerzh
10
Гайз, кто-нибудь пробовал запустить probe-rs под камень, которого нет в probe-rs? Мб есть какой-нибудь пример у кого... Через target-gen попробовал сгенерировать chip-descript...
Максим Смирнов
2
I hodl ocean for a long time. Is there new development that I should read?
A33
12
здравствуйте. совершаю вот такую вещь: strcpy(line, (char)current_number); где current number — неподписанный шорт, line — массив чаров. ругань следующая: main.c:29:30: error...
Roberto's Ширгозиев
13
How is any merchant expected to know where his customers' money comes from? Surely criminals may give cash to their wife to go to the grocery store
Maybe
10
Карта сайта