[J3] Simple functions in Constant Expressions
Brad Richardson
everythingfunctional at protonmail.com
Wed Aug 25 16:22:33 UTC 2021
Hi all,
There have been requests in a few places asking for something equivalent to C++'s `constexpr`. Looking at the recently added `simple` feature, I think the constraints are sufficient for `simple function`s to be effectively `constexpr`. Would it be possible to add `simple` functions to the section on Constant Expressions (Section 10.1.12). I.e. the first paragraph would read:
A constant expression is an expression with limitations that make it suitable for use as a kind type parameter,
initializer, or named constant. It is an expression in which each operation is intrinsic or simple, and each primary is
I believe the restrictions listed in that section combined with the constraints for simple would be sufficient. Am I missing something? Is there some constraint that could be added to `simple` procedures to enable this? If so I would be in favor of adding it. My biggest motivation would be declaring constants of derived types with private components. For example
interface operator(.unit.)
module procedure from_units
end interface
interface
simple module function from_units(value, unit) result(acceleration)
real, intent(in) :: value
type(acceleration_unit_t), intent(in) :: unit
type(acceleration_t) :: acceleration
end function
end interface
type(acceleration_unit_t), parameter :: METERS_PER_SQUARE_SECOND = ...
! In a different module
type(acceleration_t), parameter :: GRAVITY = 9.81 .unit. METERS_PER_SQUARE_SECOND
Regards,
Brad Richardson
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.j3-fortran.org/pipermail/j3/attachments/20210825/5a91740c/attachment.htm>
More information about the J3
mailing list