It is not ignored, but a string before _ 以前 is passed as a parameter pack of char.
For example, 14142_ <
is the same as calling operator"_ _<'1', '4', '4', '2'>()
.
The following sample restores integer values from the parameter pack.
#include<iostream>
# include <cmath>
template<typename T>
double decimal (T value) {
return value - '0';
}
template<typename T, typename...Targs>
double decimal (T value, Targs...Fargs) {
return(value-'0')*power(10,sizeof...(Fargs))+decimal(Fargs...);
}
template<char...T>double operator"_ ((){
return decimal (T...);
}
int main() {
std::cout<<14142_ ;;
}
http://melpon.org/wandbox/permlink/Z0SiejoGSos13ooN
As @h2so5 replied, the 2
part is passed to the parameter pack of the template one character at a time (type char
).At this time, the argument part must be empty.( 13 13.5.8/parograph 5)
5 The declaration of a literal operator template shall have an empty parameter-declaration-clause and its template-parameter-listshall have a single template-parameter that is a non-type template parameter(14/packet. Or what is the difference between constexpr and _ なら? The purpose of this piece of code is to show that UCN (universal-character-name) can be used for the identifier of User-defined literals, so it's no use pursuing more semantics.
Why is it a parameter pack?
© 2024 OneMinuteCode. All rights reserved.