Похожие чаты

Hi. I have two functions: U do_something(T a, T b) {

return U(something); }

template<typename First, typename ... Rest>
U do_something(First first, Rest ... rest)
{
return do_something(first, do_something(rest...));
}

But the compiler can't distinguish what function to call when I call do_something(a, b, c ,d); instead it thinks I'm calling the one with two arguments. What am I doing wrong?

21 ответов

15 просмотров

First of all send your actual code with actual types , U do_something(T a, T b) looks like template syntax, which is very confusing when you put template<typename> on one definition and not on the other. what is T, is it a symbol for you to denote int, bool, types or you forgot to add template<typename T, typename U> there? And share the error code, why won't you share the actual error message?

and this works, https://hastebin.com/efazukuxoq.cpp

Hayk-Zneigras Автор вопроса
Manav | avoid unnecessary messaging me
First of all send your actual code with actual typ...

oh sorry, you are right! I oversimplified the code leaving the actual problem out. I should revise the way I ask questions to avoid this. Here is the actual code including the complete error message: https://pastebin.com/tGt5PwT1 Edit: added a missing function to the pastebin page.

Hayk Zneigras
oh sorry, you are right! I oversimplified the code...

ah, just move callback to the first argument, that'll make it less ambiguous and template deduction will work properly :D https://hastebin.com/okabonowis.cpp

Hayk-Zneigras Автор вопроса
Manav | avoid unnecessary messaging me
ah, just move callback to the first argument, that...

Idk why but I was quite sure it was common practice to place the rest of the arguments after the variadic arguments. I just checked the definition of printf and the variadic arguments come after the rest of the arguments, so yep I'll do so. Thanks! :D

Hayk-Zneigras Автор вопроса
Manav | avoid unnecessary messaging me
ah, just move callback to the first argument, that...

Btw what does TL mean as a name? I know it's just the typename in the template function, but I wonder if it's a common way to name variadic templates, it can be useful.

Hayk Zneigras
Oh got it, thanks again

the way of naming comes from functional programming languages imo, you can easily get the first and the last element using pattern matching in those languages.

Manav | avoid unnecessary messaging me
the way of naming comes from functional programmin...

won't that be, T for type, [] for list, [T] for list of type T, 😜

Manav | avoid unnecessary messaging me
ah, just move callback to the first argument, that...

Tanmay 👆, gists are usually for multiple files and is too verbose for such simple code.

Hayk Zneigras
oh sorry, you are right! I oversimplified the code...

I think this could be compressed into just one function with variadic template, I'll try a few things wait a bit. But still I'd suggest you test extensively the compile times so it's under reasonable parameters. I have seen compile times increasing from a few minutes to few hours because of variadic templates and the binary inflating to very big sizes so be careful.

Hayk-Zneigras Автор вопроса
Manav | avoid unnecessary messaging me
I think this could be compressed into just one fun...

It would make sense to use this function for up to 64 arguments. Is this a significant number? If so I could replace it with a vector and as this is c++11 one will just need to pass the values using an initializer list

Hayk Zneigras
It would make sense to use this function for up to...

64 arguments will create 64 recursions, that's 64 different function implementations. You can see them if you export the symbol table. Ah by initializer_list i meant folding it, i'll give you an example. Btw your previous code didn't have the uint64_t combine_squares(Square square); only the templated version

Hayk-Zneigras Автор вопроса
Manav | avoid unnecessary messaging me
64 arguments will create 64 recursions, that's 64 ...

Right, I remember I had forgotten to add that too to the pastebin, but then updated the link. Probably I missclicked somewhere when editing the message. I'll send that as soon as possibile

Hayk-Zneigras Автор вопроса
Manav | avoid unnecessary messaging me
👍

Ok I'm here. uint64_t combine_squares(Square first, Squade second) { return square_bb(first) | square_bb(second); } uint64_t square_bb(Square square) { return uint64_t(1) << square; }

Hayk Zneigras
Ok I'm here. uint64_t combine_squares(Square firs...

hmm, well you can just use the fold expressions, like this: https://hastebin.com/sawalonoku.cpp

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

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

А кто-то пробовал, уезжая из Эстонии получить э-рез и продолжить вести предпринимательскую деятельность внутри Эстонии, используя свой OÜ?
Lalalashechki Lalala
62
зачем же переименовывать ? чтобы кол-во участников возросло или вдруг IBM от этого снова на свифте начнет кодить ? Я не понимаю что страшного в том что свифт гавно, если это т...
Oleh Nerzh
10
Is Kadena onto something special? No one really knows. Good luck!
Bright Uncle Stephen EqualBet
40
Гайз, кто-нибудь пробовал запустить probe-rs под камень, которого нет в probe-rs? Мб есть какой-нибудь пример у кого... Через target-gen попробовал сгенерировать chip-descript...
Максим Смирнов
2
здравствуйте. совершаю вот такую вещь: strcpy(line, (char)current_number); где current number — неподписанный шорт, line — массив чаров. ругань следующая: main.c:29:30: error...
Roberto's Ширгозиев
13
я не магистр хаскеля, но разве не может лейзи тип конвертнуться в не-лейзи запросив вычисление содержимого прям при инициализации?
deadgnom32 λ madao
100
@MrMiscipitlick А можешь макрос написать, который будет вычислять смещение относительно переданных меток? Просто .label1-.label2, и вернуть значение.
КТ315
35
isn't utxo commitements pretty close though if someone wanted to get it over the finish line? my understanding is that most of the ground work was already down by verde
Luke High - Rabbi Of Bcash High Rabbi Of Bcash
23
Можно попросить небольшое ревью кода? Тут немнога, я ничего интереснее не придумал, чем написать аналог tree в качестве практики с cmake. https://github.com/hrimov/tree-unix/...
Andrew Hrimov
11
Всем привет. Ребят подскажите пожалуйста. Вопрос по дизасемблировани. Начну с начала. У меня есть скомпилированная программа на ГО (я разработчик) - в ней есть защита лицензии...
Zloy
11
Карта сайта