diff --git a/include/fc/bloom_filter.hpp b/include/fc/bloom_filter.hpp index a52f2da..940dfbd 100644 --- a/include/fc/bloom_filter.hpp +++ b/include/fc/bloom_filter.hpp @@ -31,7 +31,7 @@ namespace fc { -static const std::size_t bits_per_char = 0x08; // 8 bits in 1 char(unsigned) +static constexpr std::size_t bits_per_char = 0x08; // 8 bits in 1 char(unsigned) static const unsigned char bit_mask[bits_per_char] = { 0x01, //00000001 0x02, //00000010 diff --git a/include/fc/crypto/ripemd160.hpp b/include/fc/crypto/ripemd160.hpp index 58d8b18..faea983 100644 --- a/include/fc/crypto/ripemd160.hpp +++ b/include/fc/crypto/ripemd160.hpp @@ -18,7 +18,7 @@ class ripemd160 explicit operator string()const; char* data()const; - size_t data_size()const { return 160/8; } + constexpr size_t data_size()const { return 160/8; } static ripemd160 hash( const fc::sha512& h ); static ripemd160 hash( const fc::sha256& h ); diff --git a/include/fc/crypto/sha1.hpp b/include/fc/crypto/sha1.hpp index 737eecf..68fe77d 100644 --- a/include/fc/crypto/sha1.hpp +++ b/include/fc/crypto/sha1.hpp @@ -17,7 +17,7 @@ class sha1 operator std::string()const; char* data()const; - size_t data_size()const { return 20; } + constexpr size_t data_size()const { return 20; } static sha1 hash( const char* d, uint32_t dlen ); static sha1 hash( const std::string& ); diff --git a/include/fc/crypto/sha224.hpp b/include/fc/crypto/sha224.hpp index 772e9f6..923c623 100644 --- a/include/fc/crypto/sha224.hpp +++ b/include/fc/crypto/sha224.hpp @@ -16,7 +16,7 @@ class sha224 operator string()const; char* data()const; - size_t data_size()const { return 224 / 8; } + constexpr size_t data_size()const { return 224 / 8; } static sha224 hash( const char* d, uint32_t dlen ); static sha224 hash( const string& ); diff --git a/include/fc/crypto/sha256.hpp b/include/fc/crypto/sha256.hpp index a382ad0..dcc6159 100644 --- a/include/fc/crypto/sha256.hpp +++ b/include/fc/crypto/sha256.hpp @@ -18,7 +18,7 @@ class sha256 operator string()const; char* data()const; - size_t data_size()const { return 256 / 8; } + constexpr size_t data_size()const { return 256 / 8; } static sha256 hash( const char* d, uint32_t dlen ); static sha256 hash( const string& ); diff --git a/include/fc/crypto/sha512.hpp b/include/fc/crypto/sha512.hpp index adb078c..0eb5715 100644 --- a/include/fc/crypto/sha512.hpp +++ b/include/fc/crypto/sha512.hpp @@ -16,7 +16,7 @@ class sha512 operator std::string()const; char* data()const; - size_t data_size()const { return 512 / 8; } + constexpr size_t data_size()const { return 512 / 8; } static sha512 hash( const char* d, uint32_t dlen ); static sha512 hash( const std::string& ); diff --git a/include/fc/safe.hpp b/include/fc/safe.hpp index d7c8514..42ab676 100644 --- a/include/fc/safe.hpp +++ b/include/fc/safe.hpp @@ -26,11 +26,11 @@ namespace fc { safe(){} safe( const safe& o ):value(o.value){} - static safe min() + static constexpr safe min() { return std::numeric_limits::min(); } - static safe max() + static constexpr safe max() { return std::numeric_limits::max(); } @@ -91,7 +91,7 @@ namespace fc { safe operator - ()const { - if( value == std::numeric_limits::min() ) FC_CAPTURE_AND_THROW( overflow_exception, (*this) ); + if( value == min() ) FC_CAPTURE_AND_THROW( overflow_exception, (*this) ); return safe( -value ); } diff --git a/include/fc/static_variant.hpp b/include/fc/static_variant.hpp index 5451168..59e6213 100644 --- a/include/fc/static_variant.hpp +++ b/include/fc/static_variant.hpp @@ -141,58 +141,53 @@ struct storage_ops { template struct position { - static const int pos = -1; + static constexpr int pos = -1; }; template struct position { - static const int pos = 0; + static constexpr int pos = 0; }; template struct position { - static const int pos = position::pos != -1 ? position::pos + 1 : -1; + static constexpr int pos = position::pos != -1 ? position::pos + 1 : -1; }; template struct type_info { - static const bool no_reference_types = false; - static const bool no_duplicates = position::pos == -1 && type_info::no_duplicates; - static const size_t size = type_info::size > sizeof(T&) ? type_info::size : sizeof(T&); - static const size_t count = 1 + type_info::count; + static constexpr bool no_reference_types = false; + static constexpr bool no_duplicates = position::pos == -1 && type_info::no_duplicates; + static constexpr size_t size = type_info::size > sizeof(T&) ? type_info::size : sizeof(T&); + static constexpr size_t count = 1 + type_info::count; }; template struct type_info { - static const bool no_reference_types = type_info::no_reference_types; - static const bool no_duplicates = position::pos == -1 && type_info::no_duplicates; - static const size_t size = type_info::size > sizeof(T) ? type_info::size : sizeof(T&); - static const size_t count = 1 + type_info::count; + static constexpr bool no_reference_types = type_info::no_reference_types; + static constexpr bool no_duplicates = position::pos == -1 && type_info::no_duplicates; + static constexpr size_t size = type_info::size > sizeof(T) ? type_info::size : sizeof(T&); + static constexpr size_t count = 1 + type_info::count; }; template<> struct type_info<> { - static const bool no_reference_types = true; - static const bool no_duplicates = true; - static const size_t count = 0; - static const size_t size = 0; + static constexpr bool no_reference_types = true; + static constexpr bool no_duplicates = true; + static constexpr size_t count = 0; + static constexpr size_t size = 0; }; template -size_t size( TTag ) +constexpr size_t size( TTag ) { return 0; } template -size_t size( TTag tag ) +constexpr size_t size( TTag tag ) { - if (tag <= 0) - { - return sizeof(A); - } - - return size( --tag ); + return tag <= 0 ? sizeof(A) : size( --tag ); } @@ -304,7 +299,7 @@ public: template> struct tag { - static const int value = impl::position::pos; + static constexpr int value = impl::position::pos; }; static_variant() @@ -434,7 +429,7 @@ public: return wrappers[tag]( v, data ); } - static int count() { return impl::type_info::count; } + static constexpr int count() { return impl::type_info::count; } void set_which( tag_type w ) { FC_ASSERT( w >= 0 ); FC_ASSERT( w < count() );