如何称呼表达式"T (&some(...))[2]' 其中 T=字符
What to call the expression `T (&some(...)) [2]` where T=char
我在库实现中看到过这个表达式,我基本上理解它被用来培养 SFINAE,甚至拉动static_assert
触发器。
它基本上采用以下形式:
template <typename>
char (&checkValid(...))[2];
template <typename T>
char checkValid(e); where e is an expression(using type T) results in type X
如果e
格式正确,那么结果将是(假设使用sizeof
(1 其他 2,并且可以应用于:
static_assert(sizeof(checkValid<T>(0))==1,"") ;
前几天我一直在以不同的方式做类似的事情:
using namespace std;
template<typename...T>
using isValid = void;
template<typename>
false_type checkValid(...);
template<typename T>
true_type checkValid(isValid<typename T::type>*);
struct some{
using type = int;
};
int main(){
constexpr bool result = decltype(checkValid<some>(0))::value;
}
不管我做了什么,看到了什么,我更想知道:
这个表达式叫什么?
template <typename>
char (&checkValid(...))[2];
"变量模板"?"函数模板?"还是"引用...的数组"?(对不起,如果我的猜测很糟糕(
它是一个函数模板,返回对char[2]
的引用。
checkValid // `checkValid` is
checkValid(...) // a function with (...) parameter list, returning
&checkValid(...) // a reference to
(&checkValid(...)) // (discard parentheses)
(&checkValid(...))[2] // an array of 2
char (&checkValid(...))[2] // characters.
template <typename> char (&checkValid(...))[2]; // And it's a template.
相关文章:
- C++字符*缓冲区的大小
- HEX值到wchar_t字符(UTF-8)的转换
- 为什么 Serial.println(<char[]>);返回随机字符?
- 我的字符计数代码计算错误.为什么
- 字符串-C++后显示的随机字符
- 我已经建立了递归关系,它找到了两个字符串之间最长的连续公共字符串,我怎么能跳过其中一个字符串中的一个字符
- 如果我们在其中输入一个整数,则字符会给出整数作为输出,但是当分配给它一个整数时,这不会发生。为什么?
- 如何称呼表达式"T (&some(...))[2]' 其中 T=字符
- 如何打印一个字符阵列和其中的特定字符
- 除了字符串或宏调用之外,是否存在任何情况,其中"(<"是有效的字符流?
- 正则表达式:从模式字符串 1.string2'string3 中提取字符串,其中字符串 1 可以包含 '." 字符
- 可以一个#define一个文字字符串,其中包含用于资源文件的非ANSI字符的字符串
- UE4 -C :如何设计一个本地Coop游戏,其中字符具有不同的输入方案
- C++ 堆栈程序 指针问题的 Wsing 数组 新字符[len],其中 len 为 2 创建 16 个字符
- 检查输入值的第一个字符,如果其中一个条件为假,则再次要求输入
- 使用字符串流标记字符串,其中最后一个字符是分隔符
- 给定一个二维字符矩阵,我们必须检查给定的单词是否存在于其中
- 是否存在编解码场景,其中目标缓冲区需要多个内部字符的空间
- 如何访问矢量的元素,其中矢量与unordered_map中的字符'key'映射?
- 如何创建一个字符串数组来拆分字符,其中单词由" "分隔?C++