Skip to content

Commit a86a698

Browse files
committed
Use 'if constexpr' as @TreeHunter9 suggested.
Also, avoid hardcoded constants when possible.
1 parent 31a3bdc commit a86a698

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/common/utils_proto.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,6 @@ namespace fb_utils
275275
static_assert(std::is_integral_v<T>, "Integral type expected");
276276

277277
constexpr auto len = sizeof(T);
278-
static_assert(len == 1 || len == 2 || len == 4 || len == 8, "unknown data type");
279278

280279
if (ptr + len + 1 + 2 > end)
281280
{
@@ -292,14 +291,16 @@ namespace fb_utils
292291
*ptr++ = len;
293292
*ptr++ = 0;
294293

295-
if (len == 8)
294+
if constexpr (len == sizeof(SINT64))
296295
put_vax_int64(ptr, value);
297-
else if (len == 4)
296+
else if constexpr (len == sizeof(SLONG))
298297
put_vax_long(ptr, value);
299-
else if (len == 2)
298+
else if constexpr (len == sizeof(SSHORT))
300299
put_vax_short(ptr, value);
301-
else if (len == 1)
300+
else if constexpr (len == sizeof(char))
302301
*ptr = value;
302+
else
303+
static_assert(false, "unknown data type");
303304

304305
ptr += len;
305306
return ptr;

0 commit comments

Comments
 (0)