« first day (2024 days earlier)      last day (811 days later) » 

4:52 AM
hello, I am unable to understand parameter packs, can anyone help me ?
Why does this work :-
void print(const auto& ... args)
{
(std::cout << ... << args) << std::endl;
}
I am able to use it like :-
print(2, ':', " Hello ", 45.69, " World!");
 
in short op (in this case <<) will be repeated: en.cppreference.com/w/cpp/language/fold
your case is #2
... op pack
where op is << and pack is args
@nwp In general, when you have a bunch consumers waiting on the same mutex for a notify_all(). The consumers might want to have separate static buffers?
 
5:13 AM
I have read cpprefrence page already but didn't get it, so I asked here
What exactly does it expand to ?
And why do I need ( ) around std::cout << ... << args
 
 
2 hours later…
7:31 AM
Has anyone ever used the Google Test unit testing library? If so, what is your take on it and how do you compare it to other testing frameworks (e.g. Catch2) that you may have used?
 
 
4 hours later…
11:38 AM
14 messages moved from Lounge<C++>
 
nwp
@Tanishq-Banyal Because the language says so. It probably is otherwise ambiguous in some cases or something. It's a bit annoying, but you get used to it.
Also it's already the simplified case. People had to do the C array trick before which is even worse.
(See for example this answer, specifically the int t_[].)
 
 
2 hours later…
1:38 PM
Could someone explain what the easiest way is to find answers to questions like "how do I convert A to B"?
 
the easiest way is to google "how do I convert A to B"?
 
nwp
Type it into your browser's search bar. Maybe add "C++" or "boost" or other relevant phrases to it.
 
yhea you dont say...
urgh cant find any more what I am looking for
either way
For instance, I now want to somehow convert a std::basic_ostream (I think that s what it is called....) to a boost::asio::buffer. I had a quick look through boost's documentation to see whether that would easily be possible. But didnt find anything quickly. I guess if I keep on digging I might maybe find something
Google didnt give me a off the shelf answer/solution
and I very often want to convert stuff somehow...
how do you deal with such situations usually? Or what would be the best way to deal with this?
 
then understand the underlying data of what you're trying to convert
 
1:43 PM
yhea guesses so. So I need to go down the rabbitrole
urgh...
 
if you understand both the source format and the target format, you'll know how to reasonably convert it
 
nwp
I searched for "std::ostream to boost::asio::buffer" and the first result is stackoverflow.com/questions/5675358 of which the first answer looks very promising.
 
I must have missed that link
 
 
4 hours later…
5:19 PM
@Mikhail This is an interesting one. I was wondering if this would not have a performance cost if the print function occurs many times with many different arguments. This must be using a template under the hood (because of auto parameter), so it should create a version of the print function for each distinct usage, isn't that right? Would this not be inneficient?
 
 
4 hours later…
9:41 PM
@MangaD Yes it can, every distinct signature tells the compiler to make a new function.
 
Thanks :)
 
@MangaD btw std::visit has a known template explosion when using visitor on multiple types deduced with auto for example, void compare(auto a, auto b) over a std::variant with 30 types will generate 30 x 30 function signatures :-/
anyways std::variant and std::visit is an anti pattern :-)
 
I may check it later, thanks! :)
 

« first day (2024 days earlier)      last day (811 days later) »