Boost logo

Boost :

Subject: [boost] boost::integer library request
From: Jorge Lodos Vigil (lodos_at_[hidden])
Date: 2008-11-04 13:46:33


Hi
Is there any chance the code below could be added to the integer library? More specifically, to the integer_mask.hpp header? If there is, I would be happy to provide tests and documentation. We use it to get significant parts of unsigned integer values, it is a superset of LOBYTE, HIBYTE, LOWORD and HIWORD windows macros and generates no binary code in optimized compilations.
Thanks in advance.

template < std::size_t Bits, typename Unsigned >
inline typename uint_t<Bits>::least lobits(Unsigned n)
{
  n &= low_bits_mask_t<Bits>::sig_bits;
  return (uint_t<Bits>::least)n;
}

template < std::size_t Bits, typename Unsigned >
inline typename uint_t<Bits>::least hibits(Unsigned n)
{
  n >>= (std::numeric_limits<Unsigned>::digits - low_bits_mask_t<Bits>::bit_count);
  return (uint_t<Bits>::least)n;
}

template <typename Unsigned>
inline uint8_t lobyte(Unsigned n)
{
  return lobits<8, Unsigned>(n);
}

template <typename Unsigned>
inline uint8_t hibyte(Unsigned n)
{
  return hibits<8, Unsigned>(n);
}

template <typename Unsigned>
inline uint16_t loword16(Unsigned n)
{
  return lobits<16, Unsigned>(n);
}

template <typename Unsigned>
inline uint16_t hiword16(Unsigned n)
{
  return hibits<16, Unsigned>(n);
}

template <typename Unsigned>
inline uint32_t loword32(Unsigned n)
{
  return lobits<32, Unsigned>(n);
}

template <typename Unsigned>
inline uint32_t hiword32(Unsigned n)
{
  return hibits<32, Unsigned>(n);
}

Best regards
Jorge


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk