diff --git a/src/core/DataTypes.h b/src/core/DataTypes.h index 4c348dfe7f6e934fb9fb5403abfd5761e256a9ae..e4c755d104988335a71158aaf2f9955e12d523a9 100644 --- a/src/core/DataTypes.h +++ b/src/core/DataTypes.h @@ -120,6 +120,34 @@ inline void static_assert_uint_t() { !std::numeric_limits<UINT>::is_signed, "Unsigned integer type required/expected!" ); } +template< uint_t size > struct uintFromBitWidth; +template<> struct uintFromBitWidth< 8 > { typedef uint8_t type; }; +template<> struct uintFromBitWidth< 16 > { typedef uint16_t type; }; +template<> struct uintFromBitWidth< 32 > { typedef uint32_t type; }; +template<> struct uintFromBitWidth< 64 > { typedef uint64_t type; }; + +constexpr uint_t leastUnsignedIntegerBitWidth( uint_t width ) +{ + if ( width <= 8 ) return 8; + if ( width <= 16 ) return 16; + if ( width <= 32 ) return 32; + if ( width <= 64 ) return 64; + return width; +} + +/// \brief Provides the smallest unsigned integer type that has at least minSize bits. +/// +/// Example: +/// +/// leastUnsignedInteger< 5 >::type a; // a is an 8-bit unsigned integer +/// leastUnsignedInteger< 9 >::type b; // b is a 16-bit unsigned integer +/// +template< uint_t minSize > +struct leastUnsignedInteger +{ + typedef typename uintFromBitWidth< leastUnsignedIntegerBitWidth( minSize ) >::type type; +}; + /// \cond internal static const uint_t UINT_BITS = static_cast< uint_t >( std::numeric_limits< uint_t >::digits ); static const uint_t UINT_BYTES = static_cast< uint_t >( std::numeric_limits< uint_t >::digits ) >> 3; diff --git a/src/core/math/Uint.h b/src/core/math/Uint.h index 14dd3ed100a7dfbdd82726c4945b63f1fe2c7326..ac880252073d3a58f8e4ed20e10acab59e55a4c6 100644 --- a/src/core/math/Uint.h +++ b/src/core/math/Uint.h @@ -26,7 +26,6 @@ #include "core/debug/Debug.h" #include <boost/type_traits/is_unsigned.hpp> -#include <boost/integer.hpp> namespace walberla { diff --git a/src/core/mpi/BufferDataTypeExtensions.h b/src/core/mpi/BufferDataTypeExtensions.h index a86884997f3db77ca2e55ce38e88330a6a28ab68..145e1d3aa2a0238cde5b3cf205ede98e4daf75f9 100644 --- a/src/core/mpi/BufferDataTypeExtensions.h +++ b/src/core/mpi/BufferDataTypeExtensions.h @@ -29,7 +29,6 @@ #include "core/DataTypes.h" #include "core/Optional.h" -#include <boost/integer.hpp> #include <boost/uuid/uuid.hpp> #include <array> @@ -276,7 +275,7 @@ template< typename T, // Element type of SendBuffer GenericSendBuffer<T,G>& packBoolVectorWithoutSize(GenericSendBuffer<T,G> & buf, const std::vector<bool> & bools ) { // Use an unsigned type at least as large as the SendBuffer base type as container for the bools - typedef typename boost::uint_t<std::numeric_limits<T>::digits>::least ContainerType; + typedef typename leastUnsignedInteger< std::numeric_limits<T>::digits >::type ContainerType; static const size_t NUM_BITS = std::numeric_limits<ContainerType>::digits; auto it = bools.begin(); @@ -297,7 +296,7 @@ template< typename T > // Element type of RecvBuffer GenericRecvBuffer<T>& unpackBoolVectorWithoutSize(GenericRecvBuffer<T> & buf, std::vector<bool> & bools, size_t size ) { // Use an unsigned type at least as large as the RecvBuffer base type as container for the bools - typedef typename boost::uint_t<std::numeric_limits<T>::digits>::least ContainerType; + typedef typename leastUnsignedInteger<std::numeric_limits<T>::digits>::type ContainerType; static const size_t NUM_BITS = std::numeric_limits<ContainerType>::digits; bools.resize(size);