What are unevaluated operands in C++?
humanreadablemag.com
What are unevaluated operands in C++?
1–10 of 20 posts
Re: What are unevaluated operands in C++?
#2Re: What are unevaluated operands in C++?
#3Poor man's lazy evaluation. I'm sure they'll try to shoehorn monads in somehow with C++23
Re: What are unevaluated operands in C++?
#4Re: What are unevaluated operands in C++?
#5Poor man's lazy evaluation. I'm sure they'll try to shoehorn monads in somehow with C++23
This concept is operators that will never evaluate the expressions they operate on.
sizeof is the oldschool obvious one, sizeof(foo()) never runs the function foo. It's just a way of querying the static properties of an expression, asking specific things about its type in a way.
They're not new things in C++. sizeof has been around since the beginning.
Re: What are unevaluated operands in C++?
#6Re: What are unevaluated operands in C++?
#7Previous I have used this idiom:
#define MY_ASSERT(expr) do {} while (false && (expr))
Another possible alternative might be:
#define MY_ASSERT(expr) sizeof(expr)
Re: What are unevaluated operands in C++?
#8This seems like a potential solution to the problem of how to #define MY_ASSERT(x) in release mode such that it fails to compile if "x" is not a valid expression. Previous I have used this idiom: #define MY_ASSERT(expr) do {} while (false && (expr)) Another possible alternative might be: #define MY_ASSERT(expr) sizeof(expr)
sizeof accepts a type or an expression as its input, so it would compile successfully if expr were a type but not a valid expression (say, int).
Re: What are unevaluated operands in C++?
#9This seems like a potential solution to the problem of how to #define MY_ASSERT(x) in release mode such that it fails to compile if "x" is not a valid expression. Previous I have used this idiom: #define MY_ASSERT(expr) do {} while (false && (expr)) Another possible alternative might be: #define MY_ASSERT(expr) sizeof(expr)
> #define MY_ASSERT(expr) sizeof(expr) sizeof accepts a type or an expression as its input, so it would compile successfully if expr were a type but not a valid expression (say, int).
Re: What are unevaluated operands in C++?
#10Edit: I have probably seen it in concepts lite though, I just forgot about it.