Похожие чаты

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 ответов

47 просмотров

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

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

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

Господа, а что сейчас вообще с рынком труда на делфи происходит? Какова ситуация?
Rꙮman Yankꙮvsky
29
А вообще, что может смущать в самой Julia - бы сказал, что нет единого стандартного подхода по многим моментам, поэтому многое выглядит как "хаки" и произвол. Короче говоря, с...
Viktor G.
2
@Benzenoid can you tell me the easiest, and safest way to bu.y HEX now?
Živa Žena
20
This is a question from my wife who make a fortune with memes 😂😂 About the Migration and Tokens: 1. How will the old tokens be migrated to the new $LGCYX network? What is th...
🍿 °anton°
2
30500 за редактор? )
Владимир
47
а через ESC-код ?
Alexey Kulakov
29
What is the Dex situation? Agora team started with the Pnetwork for their dex which helped them both with integration. It’s completed but as you can see from the Pnetwork ann...
Ben
1
Гайс, вопрос для разносторонее развитых: читаю стрим с юарта, нада выделять с него фреймы с определенной структурой, если ли чо готовое, или долбаться с ринг буффером? нада у...
Vitaly
9
Anyone knows where there are some instructions or discort about failed bridge transactions ?
Jochem
21
@lozuk how do I get my phex copies of my ehex from a atomic wallet, to move to my rabby?
Justfrontin 👀
11
Карта сайта