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?
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
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.
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
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
yep makes it easier for template type deduction
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.
T<— type, l<- list, TL <— list of type T
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.
won't that be, T for type, [] for list, [T] for list of type T, 😜
lmao, that is true
Tanmay 👆, gists are usually for multiple files and is too verbose for such simple 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.
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
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
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
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; }
hmm, well you can just use the fold expressions, like this: https://hastebin.com/sawalonoku.cpp
Обсуждают сегодня