Templatized branchless int max/min function

后端 未结 5 661
故里飘歌
故里飘歌 2021-02-05 17:34

I\'m trying to write a branchless function to return the MAX or MIN of two integers without resorting to if (or ?:). Using the usual technique I can do this easily enough for a

5条回答
  •  耶瑟儿~
    2021-02-05 18:16

    You may want to look at the Boost.TypeTraits library. For detecting whether a type is signed you can use the is_signed trait. You can also look into enable_if/disable_if for removing overloads for certain types.

提交回复
热议问题