Skip to main content

Timeline for Writing a vector to a file

Current License: CC BY-SA 3.0

14 events
when toggle format what by license comment
Jun 10, 2020 at 13:24 history edited CommunityBot
Commonmark migration
Mar 9, 2017 at 9:04 history edited Toby Speight CC BY-SA 3.0
bool conversion is explicit, so return reference to stream
Mar 8, 2017 at 20:11 comment added Snowhawk @Ethan See this review as most of the discussion is applicable here.
Mar 8, 2017 at 1:38 comment added Ethan couldn't the delimiter be a template class as well?
Mar 7, 2017 at 20:02 comment added Snowhawk @TobySpeight: c++11 added explicit operator bool(). The use of explicit forbids implicit conversion, which is what would have taken place because the return type of your function is different from the object type you are returning. explicit has no effect on contextual conversions.
Mar 7, 2017 at 8:29 comment added Toby Speight @ShmuelH, you can certainly do that; I think it's less clear than the code in the question, but that's subjective of course. Try it, and see which you prefer.
Mar 7, 2017 at 8:28 comment added Toby Speight @Snowhawk: before operator bool() was added in C++11, operator void*() served that purpose. Do you get an error with the above? If so, which compiler and/or Standard Library implementation?
Mar 6, 2017 at 23:56 comment added Snowhawk May want to fix your return type as you are returning from std::ostream& to bool. No conversion exists.
Mar 6, 2017 at 22:18 comment added Ethan what if container is empty? I tend to think the foreach with if checks will accomplish it better
Mar 6, 2017 at 20:05 comment added Shmuel H. Maybe I didn't understand you correctly, but wouldn't it be better to avoid this in-loop if and just write the first element before the loop? (yes, foreach is far more fancy, but it is a code - not always as beautiful as we wanted it to be)
Mar 6, 2017 at 12:53 history edited Toby Speight CC BY-SA 3.0
Line got missed from markdown
Mar 6, 2017 at 12:47 comment added Ethan Thank you. That iftstream was a bug on my part. Meant it to be ofstream. I just learned templates two days ago, so I'm still learning how general you can be. Thank you very much, learned more than you can know from your answer.
Mar 6, 2017 at 12:46 vote accept Ethan
Mar 6, 2017 at 9:52 history answered Toby Speight CC BY-SA 3.0