0

Is there any way to define a const generic in the where clause, currently it doesn't seem to work. If there isn't, are there any plans of adding it in the future?

My Failed Attempts

fn foo<N>()
where
    const N:usize,
{}

fn foo<const N>()
where
    N:usize  
{}
CodeDude
  • 67
  • 5

1 Answers1

1

That's not possible. As described in the reference a const generic always follows the pattern

const IDENTIFIER : Type ( = Block | IDENTIFIER | -?LITERAL )?

Seing as they are a completly different kind of generic from both lifetime and type parameters and the : Type isn't a bound like with them it's unlikely to ever be supported with another syntax.

cafce25
  • 15,907
  • 4
  • 25
  • 31