In my code, I use variadic template functions for the logging purpose. But when I use std::endl as parameter, I get the following compiler error:
Error: no matching function for call to 'LOG_ERROR(const char [14], int&, )' LOG_ERROR("Sum of x+y = ", z, std::endl);
note: candidate: 'void LOG_ERROR()' inline void LOG_ERROR() {
note: candidate expects 0 arguments, 3 provided
My Code:
#include <iostream> inline void LOG_ERROR() { std::cout << std::endl; } template<typename First, typename ...Rest> void LOG_ERROR(First && first, Rest && ...rest){ std::cout << std::forward<First>(first); LOG_ERROR(std::forward<Rest>(rest)...); } int main() { int foo=40; LOG_ERROR("My foo = ", foo, std::endl); } The code works fine with "\n" but I would love to learn why it fails with std::endl and how I can fix it
std::endlin parameter pack to be expanded?!std::endlis a function template, not just a function. You're passing it without deduction (either specific or deduced). If you populated the template to an actual function instantiation (such asstd::endl<char, std::char_traits<char>>, it should work.LOG_ERRORfunction but I would like the user to be able to use the function withstd::endl.std::endlis used in a deducible context, which it isn't in your case.