Home > Back-end >  Excuse me, what is this grammar?
Excuse me, what is this grammar?

Time:11-06

 
The template & lt; The class _Ty, _Ty _Val & gt;//-???
Struct integral_constant {
The static constexpr _Ty value=https://bbs.csdn.net/topics/_Val;

Using value_type=_Ty;
Using type=integral_constant;

Constexpr operator value_type () const noexcept {
return value;
}

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


Class _Ty I understand is a type, a lot of template examples with typename, but follow behind a _Ty _Val what meaning be?
I know the template parameter can be a type, also can be specified type, such as
 
Template

But there are a lot of restrictions, such as MaxLen can't be a floating point number, can't be a class type
But like
 
The template & lt; The class _Ty, _Ty _Val & gt;

What is the mean?

CodePudding user response:

Parameters of the template, the second type is _Ty template parameters, such as use int instantiation integral_constant, is equivalent to integral_constant & lt; Int, int _Val & gt; , and use it every time you pass a compile time value, such as integral_constant & lt; Int, 10 & gt; , integral_constant & lt; Double, 3.14 & gt; such

CodePudding user response:

Mark, have never seen

CodePudding user response:

As literally no what mean

CodePudding user response:

Class template _Ty, not only can use the type parameters can also do with variable parameters such as _Val, variable parameter is mainly used to define some initial value or function parameters default value, see chapter 13, "the essence of c + + programming tutorial"
  • Related