Skip to content

Instantly share code, notes, and snippets.


jitpaul/consexpr Secret

Last active Nov 24, 2019
What would you like to do?
template <int val>
class Something{
int member_a;
constexpr int func(int x, int y){
return x*y;
int main(){
int n1 = 5; // 'n1' is neither
// const or constexpr
int array1[n1]; // ERROR.
Something <n1> s1; // ERROR.
const int n2 = 6; // 'n2' is a
// const object.
int array2[n2]; // OK.
Something <n2> s2; // OK
constexpr int n3 = 7; // 'n3' is
// a constexpr object
int array3[n3]; // OK.
Something <n3> s3; // OK
int array4[func(5,6)]; // OK. 'func' is
// constexpr object
Something <func(5,6)> s4; // OK. 'func' is
// constexpr object
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment