diff options
author | Mike Klein <mtklein@chromium.org> | 2017-09-28 09:47:45 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-09-29 13:49:04 +0000 |
commit | 37bbfe3ea4745170df3f5ef2f4c1e1332af49cea (patch) | |
tree | 3f2c0a6496cf023485578339ef0b32a29a9e7c09 /src/gpu/vk | |
parent | fdd2cb52b781dd68f515a1eb9fe6d054a0ebc226 (diff) |
Make SkASSERT and co. constexpr compatible.
One of the nice bits of constexpr is that an expression is constexpr if
there exists any set of argument values that make it constant. It
doesn't have to be constant for _all_ argument values.
This means that this expression is constexpr:
condition ? constexpr_value
: []{ arbitrary non-constexpr code; }();
... it's constant when condition is true.
We can use this to rewrite SkASSERT(condition) as
( (condition) ? (void)0
: []{ SK_ABORT(#condition); }() )
Both sides of the ?: are void, and when condition is true at compile
time the right hand side disappears completely. In C++11 constexpr
functions we just have to use the comma operator to jam SkASSERT()
into the order of evaluation:
constexpr uint32_t foo(int x, int y) {
return SkASSERT(x > y),
x - y;
}
Change-Id: I21878d14fb2af76d93591d2ae229460ee825cfde
Reviewed-on: https://skia-review.googlesource.com/52663
Reviewed-by: Ben Wagner <bungeman@google.com>
Reviewed-by: Trent Apted <tapted@chromium.org>
Commit-Queue: Mike Klein <mtklein@chromium.org>
Diffstat (limited to 'src/gpu/vk')
0 files changed, 0 insertions, 0 deletions