Add Constant Type and Operators - #222
Open
MrBurmark wants to merge 3 commits into
Open
Conversation
MrBurmark
commented
Aug 15, 2026
Comment on lines
+200
to
+218
| /** | ||
| * @brief constant yielding logical and for constant values | ||
| */ | ||
| template < auto lhs_value, auto rhs_value > | ||
| CAMP_HOST_DEVICE | ||
| constexpr auto operator&&(constant<lhs_value>, constant<rhs_value>) | ||
| { | ||
| return constant<lhs_value&&rhs_value>{}; | ||
| } | ||
|
|
||
| /** | ||
| * @brief constant yielding logical or for constant values | ||
| */ | ||
| template < auto lhs_value, auto rhs_value > | ||
| CAMP_HOST_DEVICE | ||
| constexpr auto operator||(constant<lhs_value>, constant<rhs_value>) | ||
| { | ||
| return constant<lhs_value||rhs_value>{}; | ||
| } |
Member
Author
There was a problem hiding this comment.
This overloads logical and and or so operations between constants remain constants. However this does break short-circuiting if both operands are constants. I'm not sure if this is a big deal or not since presumably constants are generated in constant expressions. Though of course could always return constant from a function with side-effects. So I'm not sure if I'm going to keep these overloads.
Member
Author
There was a problem hiding this comment.
@trws Are there additional concerns related to template instantiations in constant expressions and things like that that short-circuiting also has a bearing on?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add a constant type that takes a compile-time value as a template parameter. Support arithmetic between constants that produces a constant.
Deprecate integral_constant in favor of constant.
The ultimate goal with this is use it as part of a
RAJA::transparent_rangeclass that I'm thinking about adding that stores the input begin, end, and stride exactly as they were given. My hope is to improve some cases in RAJAPerf and beyond where the BASE and RAJA differ by knowledge of such exact values. For example we often assume that ranges start at 0 but RAJA ranges always have a runtime begin value, knowledge of which does not cross the host device barrier. This is responsible for some differences between kernel which takes its ranges on the host and launch which takes ranges on the device.