From a2ca77dc3004bc4f5a49f47353e3d1839c05e107 Mon Sep 17 00:00:00 2001 From: Nils Kohl <nils.kohl@fau.de> Date: Wed, 20 Mar 2019 17:07:23 +0100 Subject: [PATCH] Got rid of boost/integer.hpp. This mainly includes an implementation for boost::uint_t::least. --- src/core/DataTypes.h | 28 +++++++++++++++++++++++++ src/core/math/Uint.h | 1 - src/core/mpi/BufferDataTypeExtensions.h | 5 ++--- 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/core/DataTypes.h b/src/core/DataTypes.h index 4c348dfe7..e4c755d10 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 14dd3ed10..ac8802520 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 a86884997..145e1d3aa 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); -- GitLab