From c450600097d152f5f0f977350ce20b3f536786c4 Mon Sep 17 00:00:00 2001 From: q66 Date: Tue, 15 Nov 2016 22:50:49 +0100 Subject: [PATCH] add type trait to check type size in bits --- ostd/limits.hh | 10 +++++----- ostd/type_traits.hh | 6 ++++++ 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/ostd/limits.hh b/ostd/limits.hh index f11481b..cdf148f 100644 --- a/ostd/limits.hh +++ b/ostd/limits.hh @@ -84,19 +84,19 @@ namespace detail { } template -static constexpr T NumericLimitMin = detail::NumericLimitsBase::minv; +constexpr T NumericLimitMin = detail::NumericLimitsBase::minv; template -static constexpr T NumericLimitMax = detail::NumericLimitsBase::maxv; +constexpr T NumericLimitMax = detail::NumericLimitsBase::maxv; template -static constexpr T NumericLimitLowest = detail::NumericLimitsBase::lowv; +constexpr T NumericLimitLowest = detail::NumericLimitsBase::lowv; template -static constexpr bool NumericLimitIsSigned = detail::NumericLimitsBase::is_signed; +constexpr bool NumericLimitIsSigned = detail::NumericLimitsBase::is_signed; template -static constexpr bool NumericLimitIsInteger = detail::NumericLimitsBase::is_integer; +constexpr bool NumericLimitIsInteger = detail::NumericLimitsBase::is_integer; } diff --git a/ostd/type_traits.hh b/ostd/type_traits.hh index 34d135c..4623b8a 100644 --- a/ostd/type_traits.hh +++ b/ostd/type_traits.hh @@ -7,6 +7,7 @@ #ifndef OSTD_TYPE_TRAITS_HH #define OSTD_TYPE_TRAITS_HH +#include #include #include "ostd/types.hh" @@ -55,6 +56,11 @@ namespace detail { AddRvalueReference declval_in() noexcept; } +/* size in bits */ + +template +constexpr Size SizeInBits = sizeof(T) * CHAR_BIT; + /* integral constant */ template