Skip to content

Reduce boilerplate + avoid warning when overriding context for the current scope #521

@eyalroz

Description

@eyalroz

There are several dozen places in our code where need to set a context for the scope (typically, the function body). We do so by defining a local CADRe variable :

cuda::context::current::detail_::scoped_override_t set_context_for_this_scope(expr);

with expr being some expression yielding a context handle. This is fine, but - it would not be a bad idea to mark this variable as const (various IDEs are all for it). Also, it's a lot of typing. Let's use a macro, then:

#define CAW_SET_SCOPE_CONTEXT(context_handle_expr_) \
const cuda::context::current::detail_::scoped_override_t caw_context_for_this_scope_(context_handle_expr_)

this might look a little ugly (WHO LIKES ALL CAPS?), but it conveys the intention even more clearly when reading the code, and it's 24 characters + the length of expr, vs. 78 characters + the length of expr, which is not just less typing, but less cognitive load when reading the code.

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions