noop

Does a no-op “do nothing” function object exist in C++(0x)?

那年仲夏 提交于 2019-11-30 17:07:54
I realize this is a ludicrous question for something that takes less than 2 seconds to implement. But I vaguely remember reading that one was introduced with the new standard. I grep'ed VC10's headers and came up with nothing. Can you help? It's bugging me! :) edit: On second thought, the new functor I was remembering was probably the unrelated std::default_deleter . tzaman You could always write a no-op lambda: []{} How about this? // Return a noop function template <typename T> struct noop { T return_val; noop (T retval = T ()) : return_val (retval) { } T operator (...) { return return_val;

Does a no-op “do nothing” function object exist in C++(0x)?

心已入冬 提交于 2019-11-30 16:26:40
问题 I realize this is a ludicrous question for something that takes less than 2 seconds to implement. But I vaguely remember reading that one was introduced with the new standard. I grep'ed VC10's headers and came up with nothing. Can you help? It's bugging me! :) edit: On second thought, the new functor I was remembering was probably the unrelated std::default_deleter . 回答1: You could always write a no-op lambda: []{} 回答2: How about this? // Return a noop function template <typename T> struct

What is the use case of noop [:] in bash?

怎甘沉沦 提交于 2019-11-28 15:41:17
I searched for noop in bash (:), but was not able to find any good information. What is the exact purpose or use case of this operator? I tried following and it's working like this for me: [mandy@root]$ a=11 [mandy@root]$ b=20 [mandy@root]$ c=30 [mandy@root]$ echo $a; : echo $b ; echo $c 10 30 Please let me know, any use case of this operator in real time or any place where it is mandatory to use it. Gilles It's there more for historical reasons. The colon builtin : is exactly equivalent to true . It's traditional to use true when the return value is important, for example in an infinite loop:

What's a portable way to implement no-op statement in C++?

眉间皱痕 提交于 2019-11-28 13:15:55
One in a while there's a need for a no-op statement in C++. For example when implementing assert() which is disabled in non-debug configuration (also see this question ): #ifdef _DEBUG #define assert(x) if( !x ) { \ ThrowExcepion(__FILE__, __LINE__);\ } else {\ //noop here \ } #else #define assert(x) //noop here #endif So far I'm under impression that the right way is to use (void)0; for a no-op: (void)0; however I suspect that it might trigger warnings on some compilers - something like C4555: expression has no effect; expected expression with side-effect Visual C++ warning that is not

What's a portable way to implement no-op statement in C++?

三世轮回 提交于 2019-11-27 07:34:08
问题 One in a while there's a need for a no-op statement in C++. For example when implementing assert() which is disabled in non-debug configuration (also see this question): #ifdef _DEBUG #define assert(x) if( !x ) { \ ThrowExcepion(__FILE__, __LINE__);\ } else {\ //noop here \ } #else #define assert(x) //noop here #endif So far I'm under impression that the right way is to use (void)0; for a no-op: (void)0; however I suspect that it might trigger warnings on some compilers - something like C4555