C++ binary constant/literal

后端 未结 7 2156
-上瘾入骨i
-上瘾入骨i 2020-12-14 21:09

I\'m using a well known template to allow binary constants

template< unsigned long long N >
struct binary
{
  enum { value = (N % 10) + 2 * binary<          


        
7条回答
  •  臣服心动
    2020-12-14 21:47

    template struct BinaryDigit 
    {
      enum  { value = p*2+i };
      typedef BinaryDigit O;
      typedef BinaryDigit I;
    };
    struct Bin
    {
      typedef BinaryDigit<0,0> O;
      typedef BinaryDigit<0,1> I;
    };
    

    Allowing:

    Bin::O::I::I::O::O::value

    much more verbose, but no limits (until you hit the size of an unsigned int of course).

提交回复
热议问题