Arithmetic on `isbits` type parameters

Viewed 59

I want a type-stable version of the following (this isn't):

foo(::Val{k}) where k = Val{k+1}()

Is this possible?

1 Answers

Does this count?

@generated bar(::Val{k}) where k = :(Val{$(k+1)}())

For example:

julia> bar(Val{2}())
Val{3}()

julia> @code_warntype bar(Val{2}())
Variables:
  #self# <optimized out>
  #unused# <optimized out>

Body:
  begin  # line 1:
      return $(QuoteNode(Val{3}()))
  end::Val{3}
Related