about summary refs log tree commit diff stats
path: root/001help.cc
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-11-17 01:21:00 -0800
committerKartik K. Agaram <vc@akkartik.com>2015-11-17 01:21:00 -0800
commit08cf048f2a8ed0fa096f2c82e147b61ffc480e2a (patch)
tree80493ca241c9172e21df76cedb98312af6de8113 /001help.cc
parent21c277062ef151ad86e2003ad0e2bfb09f3d4c2d (diff)
downloadmu-08cf048f2a8ed0fa096f2c82e147b61ffc480e2a.tar.gz
2454
Another gotcha uncovered in the process of sorting out the previous
commit: I keep using eof() but forgetting that there are two other
states an istream can get into. Just never use eof().
Diffstat (limited to '001help.cc')
-rw-r--r--001help.cc7
1 files changed, 7 insertions, 0 deletions
diff --git a/001help.cc b/001help.cc
index c193cf7d..4b7c3858 100644
--- a/001help.cc
+++ b/001help.cc
@@ -113,6 +113,13 @@ template<typename T> typename T::mapped_type& get_or_insert(T& map, typename T::
 }
 //: The contract: any container that relies on get_or_insert should never call
 //: contains_key.
+//:
+//: 7. istreams are a royal pain in the arse. You have to be careful about
+//: what subclass you try to putback into. You have to watch out for the pesky
+//: failbit and badbit. Just avoid eof() and use this helper instead.
+bool has_data(istream& in) {
+  return in && !in.eof();
+}
 
 :(before "End Includes")
 #include<assert.h>