constexpr
constexpr ?
컴파일중 값으로 변경할 수 있으면 런타임이 아닌 바로 값으로 변경해 놓는다.
변경이 불가능하면 런타임시 함수 수행.
함수가 아닌 변수일 경우, 값으로 변경이 불가능하면 에러가 발생한다.
constexpr을 사용하지 않아도 자발적으로 값으로 변경해 놓는 컴파일러도 있다.
constexpr은 컴파일시 평가해 달라는 개발자의 의도를 보여주는 방법이다.
int value = 3;
int result = Factorial(3); // OK
int result = Factorial(value); // OK
constexpr int result = Factorial(value); // Compile Error !
constexpr int result = Factorial(3); // OK
constexpr int result = Factorial(300);
// Compile Error ! -> 너무 오래 걸리면 Compiler가 포기할 수도 있다.
Author And Source
이 문제에 관하여(constexpr), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@headkio/constexpr저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)