cast_util.h 869 B

123456789101112131415161718192021
  1. // Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
  2. // This source code is licensed under both the GPLv2 (found in the
  3. // COPYING file in the root directory) and Apache 2.0 License
  4. // (found in the LICENSE.Apache file in the root directory).
  5. #pragma once
  6. namespace ROCKSDB_NAMESPACE {
  7. // The helper function to assert the move from dynamic_cast<> to
  8. // static_cast<> is correct. This function is to deal with legacy code.
  9. // It is not recommanded to add new code to issue class casting. The preferred
  10. // solution is to implement the functionality without a need of casting.
  11. template <class DestClass, class SrcClass>
  12. inline DestClass* static_cast_with_check(SrcClass* x) {
  13. DestClass* ret = static_cast<DestClass*>(x);
  14. #ifdef ROCKSDB_USE_RTTI
  15. assert(ret == dynamic_cast<DestClass*>(x));
  16. #endif
  17. return ret;
  18. }
  19. } // namespace ROCKSDB_NAMESPACE