CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
bit_cast.h
Go to the documentation of this file.
1 #ifndef FWCore_Utilities_bit_cast_h
2 #define FWCore_Utilities_bit_cast_h
3 // -*- C++ -*-
4 //
5 // Package: FWCore/Utilities
6 // Class : bit_cast
7 //
16 //
17 // Original Author: Christopher Jones
18 // Created: Wed, 01 Sep 2021 19:11:41 GMT
19 //
20 
21 // system include files
22 #include <cstring>
23 
24 // user include files
25 
26 namespace edm {
27  //in C++20 we can use std::bit_cast which is constexpr
28  template <class To, class From>
29  inline To bit_cast(const From &src) noexcept {
30  static_assert(sizeof(To) == sizeof(From), "incompatible types");
31  To dst;
32  std::memcpy(&dst, &src, sizeof(To));
33  return dst;
34  }
35 } // namespace edm
36 #endif
To bit_cast(const From &src) noexcept
Definition: bit_cast.h:29
constexpr void M2 & dst