这行 stl 源代码integral_constant 部分是干什么用的?

问题描述

  /// integral_constant
  template<typename _Tp,_Tp __v>
    struct integral_constant
    {
      static constexpr _Tp                  value = __v;
      typedef _Tp                           value_type;
      typedef integral_constant<_Tp,__v>   type;
      constexpr operator value_type() const noexcept { return value; }
#if __cplusplus > 201103L

#define __cpp_lib_integral_constant_callable 201304

      constexpr value_type operator()() const noexcept { return value; }
#endif
    };

  template<typename _Tp,_Tp __v>
    constexpr _Tp integral_constant<_Tp,__v>::value;

我看不懂这条线有什么作用

constexpr _Tp integral_constant<_Tp,__v>::value;

为什么在global中声明时没有错误如下:

struct test
{
  static const int a = 1;
};
const int test::a;

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)