@@ -19,7 +19,40 @@ namespace boost {
1919namespace http_proto {
2020namespace zlib {
2121
22- template <bool isStrict>
22+ // ------------------------------------------------
23+
24+ #define SAME_FIELD (T1,T2,M ) \
25+ offsetof (T1 ,M)==offsetof(T2 ,M) && \
26+ sizeof (decltype (T1 ::M)) == sizeof (decltype (T2 ::M))
27+
28+ template <class T1 , class T2 >
29+ constexpr
30+ bool
31+ is_layout_identical ()
32+ {
33+ return
34+ sizeof (T1 ) == sizeof (T2 ) &&
35+ SAME_FIELD (T1 , T2 , next_in) &&
36+ SAME_FIELD (T1 , T2 , avail_in) &&
37+ SAME_FIELD (T1 , T2 , total_in) &&
38+ SAME_FIELD (T1 , T2 , next_out) &&
39+ SAME_FIELD (T1 , T2 , avail_out) &&
40+ SAME_FIELD (T1 , T2 , total_out) &&
41+ SAME_FIELD (T1 , T2 , msg) &&
42+ SAME_FIELD (T1 , T2 , state) &&
43+ SAME_FIELD (T1 , T2 , zalloc) &&
44+ SAME_FIELD (T1 , T2 , zfree) &&
45+ SAME_FIELD (T1 , T2 , opaque) &&
46+ SAME_FIELD (T1 , T2 , data_type) &&
47+ SAME_FIELD (T1 , T2 , adler) &&
48+ SAME_FIELD (T1 , T2 , reserved)
49+ ;
50+ }
51+
52+ // ------------------------------------------------
53+
54+ template <bool isLayoutIdentical =
55+ is_layout_identical<stream_t , z_stream_s>()>
2356struct stream_cast_impl
2457{
2558 explicit
@@ -82,6 +115,7 @@ struct stream_cast_impl<false>
82115 explicit
83116 stream_cast_impl (
84117 stream_t & st)
118+ // VFALCO A pinch of undefined behavior here
85119 : pzs_(reinterpret_cast <z_stream_s*>(&st))
86120 {
87121
@@ -99,42 +133,7 @@ struct stream_cast_impl<false>
99133
100134// ------------------------------------------------
101135
102- template <class T1 , class T2 >
103- constexpr
104- bool
105- is_layout_identical ()
106- {
107- #define SAME_FIELD (T1, T2, M )( \
108- (offsetof (T1 ,M)==offsetof (T2 ,M)) && \
109- (std::is_same<T1 ::M,T2 ::M>::value) && \
110- (sizeof (T1 ::M)==sizeof (T2 ::M)) )
111- return
112- sizeof (T1 ) == sizeof (T2 )
113- #if 0
114- SAME_FIELD(T1, T2, next_in)
115- &&
116- SAME_FIELD(T1, T2, avail_in) &&
117- SAME_FIELD(T1, T2, total_in) &&
118- SAME_FIELD(T1, T2, next_out) &&
119- SAME_FIELD(T1, T2, avail_out) &&
120- SAME_FIELD(T1, T2, total_out) &&
121- SAME_FIELD(T1, T2, msg) &&
122- SAME_FIELD(T1, T2, state) &&
123- SAME_FIELD(T1, T2, zalloc) &&
124- SAME_FIELD(T1, T2, zfree) &&
125- SAME_FIELD(T1, T2, opaque) &&
126- SAME_FIELD(T1, T2, data_type) &&
127- SAME_FIELD(T1, T2, adler) &&
128- SAME_FIELD(T1, T2, reserved)
129- #endif
130- ;
131- }
132-
133- // ------------------------------------------------
134-
135- // VFALCO A pinch of undefined behavior here
136- using stream_cast = stream_cast_impl<
137- is_layout_identical<stream_t , z_stream_s>()>;
136+ using stream_cast = stream_cast_impl<>;
138137
139138} // zlib
140139} // http_proto
0 commit comments