除非你能把它变成lambda表达式,否则编译器不会理解那个。 No. MY_MACRO would be expanded.In the case of strtoupper:#define strtoupper(x) ((x>''a'' && x<''z'')?x+(''A''-''a''):x)The line:transform(i.begin(),i.end(),i.begin(), strtoupper);would be generated by the pre-processor as:transform(i.begin(),i.end(),i.begin(), ((x>''a'' && x<''z'')?x+(''A''-''a''):x) );Unless you can make this a lambda expression, the compiler doesn''tunderstand that :). 嗯,是的,如果电话是 transform(i.begin(),alsond(), i.begin(),toupper(x)); 但是 转换(i.begin(),iend() ,i.begin(),toupper); 在语法上是可以的,因为toupper(没有任何括号) 没有命名函数式宏,但命名底层的 函数。问题是如果输入序列中除了EOF之外的值 可能是负的,那么它的运行时语义是错误的。 - Pete Roundhouse Consulting,Ltd。( www.versatilecoding.com )作者 标准C ++库扩展:教程和参考 www.petebecker.com/tr1book ) Well, yes, if the call is transform(i.begin(), i.end(), i.begin(), toupper(x)); But transform(i.begin(), i.end(), i.begin(), toupper); is okay syntactically, because toupper (without any parentheses)doesn''t name the function-like macro, but names the underlyingfunction. The problem is that its runtime semantics are wrong if valuesother than EOF in the input sequence might be negative. --PeteRoundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "TheStandard C++ Library Extensions: a Tutorial and Reference(www.petebecker.com/tr1book) 是。 Yes. 是 Yes 你错了。预处理阶段在编译之前发生,因此 宏名称绝不是类型推导的候选者。 You are wrong. The preprocessing phase happens before compilation so themacro name is never a candidate for type deduction. 忽略toupper可能实际上是一个宏的事实,我是什么表明变换调用会失败因为自动 类型扣除会失败(因为toupper被重载并模板化)。 这是在 http://lists.debian.org/debian-gcc/2.../msg00092.html 。 如果在C ++中允许使用C标准函数*的宏定义(参见下面我的评论,请参阅 ),看来你可能有*额外*问题 toupper是一个宏,所以使用toupper作为函数的输入, 期望函数指针可能会导致问题。 C ++标准是否指定 是否允许在 - < cnametype libraries ? 海报暗示宏定义在< name.h> 库中允许使用它,但不能在< cnamelibraries中使用。 Ignoring the fact that toupper might actually be a macro, what I wassuggesting that the call to transform would fail because automatictype deduction would fail (as toupper is overloaded AND templated).This is stated at http://lists.debian.org/debian-gcc/2.../msg00092.html.If macro definitions of C standard functions *are* allowed in C++ (seemy comment below), it seems that you may have the *extra* problem oftoupper being a macro, so using toupper as an input to a function thatexpects a function pointer may cause problems. Does the C++ standard specify whether the standard functions areallowed to be macro''ed in- <name.htype libraries?- <cnametype libraries? The poster suggests that macro definitions are allowed in <name.h>libraries, but not in <cnamelibraries. 如果是你的意思,C ++中允许使用宏。 Macro are allowed in C++ if it is what you mean. 我来自哪里是这句话: 我不确定符合C ++的实现是否可以有宏版本 的ctype.h头文件。我见过的大多数版本都有#ifdef __cpp__ 或类似版本,使用C ++版本的内联函数和 C的宏。 - http://bytes.com/forum/thread60652.html (当然这是 语句不一定正确)。如果它*是*正确的那么 toupper的宏扩展应该永远不会出现在符合标准的 实现中,因此你不必考虑问题 toupper实际上是一个宏,当它作为一个 函数指针传递给函数时(对于标准的符合实现) 谢谢 Taras Where I was coming from was this statement: "I''m not sure a conforming C++ implementation can have macro versionsof the ctype.h headers. Most versions I have seen have #ifdef __cpp__or similar, using inline functions for the C++ version and macros forthe C one." - http://bytes.com/forum/thread60652.html (of course thisstatement is not necessarily correct). If it *was* correct then themacro expansion of toupper should never occur in a conforming standardimplementation, and thus you wouldn''t have to consider the problem oftoupper actually being a macro when passing it into functions as afunction pointer (for a standard conforming implementation) Thanks Taras 这篇关于ctype&amp;变换中的cctype的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-22 02:22