diff options
author | Chris Dyer <cdyer@cs.cmu.edu> | 2011-01-18 15:55:40 -0500 |
---|---|---|
committer | Chris Dyer <cdyer@cs.cmu.edu> | 2011-01-18 15:55:40 -0500 |
commit | d04c0ca2d9df0e147239b18e90650ca8bd51d594 (patch) | |
tree | 1e728067b0606870df89961d10922b4226e614bb /klm/util/string_piece.hh | |
parent | b49944ee0e5f347a936df244a7c354a867c79c93 (diff) |
new version of klm
Diffstat (limited to 'klm/util/string_piece.hh')
-rw-r--r-- | klm/util/string_piece.hh | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/klm/util/string_piece.hh b/klm/util/string_piece.hh index 3ac2f8a7..2583db5e 100644 --- a/klm/util/string_piece.hh +++ b/klm/util/string_piece.hh @@ -53,8 +53,13 @@ //Uncomment this line if you want boost hashing for your StringPieces. //#define HAVE_BOOST +#ifdef HAVE_BOOST +#include <boost/functional/hash/hash.hpp> +#endif // HAVE_BOOST + #include <cstring> #include <iosfwd> +#include <ostream> #ifdef HAVE_ICU #include <unicode/stringpiece.h> @@ -62,7 +67,6 @@ U_NAMESPACE_BEGIN #else #include <algorithm> -#include <ostream> #include <string> #include <string.h> @@ -228,10 +232,14 @@ inline bool operator>=(const StringPiece& x, const StringPiece& y) { } // allow StringPiece to be logged (needed for unit testing). -extern std::ostream& operator<<(std::ostream& o, const StringPiece& piece); +inline std::ostream& operator<<(std::ostream& o, const StringPiece& piece) { + return o.write(piece.data(), static_cast<std::streamsize>(piece.size())); +} #ifdef HAVE_BOOST -size_t hash_value(const StringPiece &str); +inline size_t hash_value(const StringPiece &str) { + return boost::hash_range(str.data(), str.data() + str.length()); +} /* Support for lookup of StringPiece in boost::unordered_map<std::string> */ struct StringPieceCompatibleHash : public std::unary_function<const StringPiece &, size_t> { |