[llvm-commits] [llvm] r116247 - in /llvm/trunk: include/llvm/Support/MathExtras.h include/llvm/System/SwapByteOrder.h unittests/CMakeLists.txt unittests/Support/SwapByteOrderTest.cpp

Chris Lattner clattner at apple.com
Wed Nov 17 19:25:40 PST 2010


On Oct 11, 2010, at 2:56 PM, Michael J. Spencer wrote:

> Author: mspencer
> Date: Mon Oct 11 16:56:16 2010
> New Revision: 116247
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=116247&view=rev
> Log:
> System: Add SwapByteOrder and update Support/MathExtras.h to use it.

Hi Michael,

Catching up on back patches here:

> +
> +template<typename value_type>
> +inline
> +typename enable_if_c<sizeof(value_type) == 1
> +                     && std::numeric_limits<value_type>::is_integer,
> +                     value_type>::type
> +SwapByteOrder(value_type Value) {
> +  // No swapping needed.
> +  return Value;
> +}
> +
> +template<typename value_type>
> +inline
> +typename enable_if_c<sizeof(value_type) == 2
> +                     && std::numeric_limits<value_type>::is_integer,
> +                     value_type>::type
> +SwapByteOrder(value_type Value) {

This seems like *massive* overkill.  All the template metaprogramming isn't making the code easier to read and follow, it is making it more verbose and difficult to understand.  Instead of defining SwapByteOrder like this, why not just define overloads for signed/unsigned char/short/int/long/long long  ?

-Chris



More information about the llvm-commits mailing list