Last active
January 28, 2018 07:18
-
-
Save fortheday/55d0924741f313a6787777fdeba6ec80 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int x = 2; | |
constexpr int GetDays() { return 2018 * 365; } | |
constexpr int todayDays1 = GetDays() * 1; // OK | |
constexpr int todayDays2 = GetDays() * x; // CompileTime Error | |
const int todayDays = GetDays() * x; // OK, Runtime initialize | |
class CVector2 | |
{ | |
private: | |
float m_x; | |
float m_y; | |
constexpr static float square(float x) { return x * x; } | |
public: | |
constexpr CVector2(float x, float y) | |
: m_x(x), m_y(y) | |
{} | |
constexpr float GetLengthSquare() const | |
{ | |
return square(m_x) + square(m_y); | |
} | |
}; | |
void ConstExprTest() | |
{ | |
constexpr CVector2 vec2(5.0f, 6.0f); | |
// asm lea, call, fstp (런타임 처리) | |
const float vec2LengthSquare1 = vec2.GetLengthSquare(); | |
// asm 2 moves (컴파일타임에 계산된 것 이용) | |
constexpr float vec2LengthSquare2 = vec2.GetLengthSquare(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment