相关疑难解决方法(0)

C++二进制常量/文字

我使用一个众所周知的模板来允许二进制常量

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

template<>
struct binary< 0 >
{
  enum { value = 0 } ;
};
Run Code Online (Sandbox Code Playgroud)

所以你可以做二进制<101011011> :: value.不幸的是,对于无符号长整数,它有20位数的限制.

有没有人有更好的解决方案?

c++ binary templates constants

13
推荐指数
2
解决办法
8820
查看次数

标签 统计

binary ×1

c++ ×1

constants ×1

templates ×1