aboutsummaryrefslogtreecommitdiff
path: root/src/google/protobuf/stubs/casts.h
diff options
context:
space:
mode:
authorFeng Xiao <xfxyjwf@gmail.com>2015-06-17 13:12:11 -0700
committerFeng Xiao <xfxyjwf@gmail.com>2015-06-17 13:12:11 -0700
commite9a122eb19ec54dbca15da80355ed0c17cada9b1 (patch)
treefac37489873ccf47777b2e652db580f9315d7bc7 /src/google/protobuf/stubs/casts.h
parentb36395b2bac88f70070544c325bc09234cb1f1a6 (diff)
parent818c5eee08840355d70d2f3bdf1a2f17986a5e70 (diff)
downloadprotobuf-e9a122eb19ec54dbca15da80355ed0c17cada9b1.tar.gz
protobuf-e9a122eb19ec54dbca15da80355ed0c17cada9b1.tar.bz2
protobuf-e9a122eb19ec54dbca15da80355ed0c17cada9b1.zip
Merge pull request #501 from xfxyjwf/down
Down-integrate from internal code base.
Diffstat (limited to 'src/google/protobuf/stubs/casts.h')
-rw-r--r--src/google/protobuf/stubs/casts.h10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/google/protobuf/stubs/casts.h b/src/google/protobuf/stubs/casts.h
index cccf65a1..be652849 100644
--- a/src/google/protobuf/stubs/casts.h
+++ b/src/google/protobuf/stubs/casts.h
@@ -111,12 +111,22 @@ inline To down_cast(From& f) {
return *static_cast<ToAsPointer>(&f);
}
+template<typename To, typename From>
+inline To bit_cast(const From& from) {
+ GOOGLE_COMPILE_ASSERT(sizeof(From) == sizeof(To),
+ bit_cast_with_different_sizes);
+ To dest;
+ memcpy(&dest, &from, sizeof(dest));
+ return dest;
+}
+
} // namespace internal
// We made these internal so that they would show up as such in the docs,
// but we don't want to stick "internal::" in front of them everywhere.
using internal::implicit_cast;
using internal::down_cast;
+using internal::bit_cast;
} // namespace protobuf
} // namespace google