@@ -110,6 +110,7 @@ struct Reader {
110110 return error (
111111 " Could not cast to string. The type must be UTF8 or symbol." );
112112 }
113+
113114 } else if constexpr (std::is_same<std::remove_cvref_t <T>,
114115 rfl::Bytestring>()) {
115116 if (btype != BSON_TYPE_BINARY) {
@@ -123,17 +124,23 @@ struct Reader {
123124 const auto data =
124125 internal::ptr_cast<const std::byte*>(value.v_binary .data );
125126 return rfl::Bytestring (data, data + value.v_binary .data_len );
127+
126128 } else if constexpr (std::is_same<std::remove_cvref_t <T>, bool >()) {
127129 if (btype != BSON_TYPE_BOOL) {
128130 return error (" Could not cast to boolean." );
129131 }
130132 return value.v_bool ;
131- } else if constexpr (std::is_floating_point<std::remove_cvref_t <T>>() ||
132- std::is_integral<std::remove_cvref_t <T>>()) {
133- switch (btype) {
134- case BSON_TYPE_DOUBLE:
135- return static_cast <T>(value.v_double );
136133
134+ } else if constexpr (std::is_floating_point<std::remove_cvref_t <T>>()) {
135+ if (btype != BSON_TYPE_DOUBLE) {
136+ return error (
137+ " Could not cast to numeric value. The type must be double, "
138+ " int32, int64 or date_time." );
139+ }
140+ return static_cast <T>(value.v_double );
141+
142+ } else if constexpr (std::is_integral<std::remove_cvref_t <T>>()) {
143+ switch (btype) {
137144 case BSON_TYPE_INT32:
138145 return static_cast <T>(value.v_int32 );
139146
@@ -145,9 +152,10 @@ struct Reader {
145152
146153 default :
147154 return error (
148- " Could not cast to numeric value. The type must be double, "
155+ " Could not cast to numeric value. The type must be "
149156 " int32, int64 or date_time." );
150157 }
158+
151159 } else if constexpr (std::is_same<std::remove_cvref_t <T>, bson_oid_t >()) {
152160 if (btype != BSON_TYPE_OID) {
153161 return error (" Could not cast to OID." );
0 commit comments