struct 이름을 해시하는 구조체 멤버를 초기화하고 싶습니다.constexpr 생성자 초기화 자 목록에있는 Constexpr 함수
constexpr uint32_t myHash(const char* const data)
{ //Some code for hash
return myHash;
}
struct My_Struct{
constexpr Test() : ID(myHash("My_Struct"))
{
}
const uint32_t ID;
}
내가 가지고있는 경우 :
constexpr My_Struct my_constexpr_struct;
그런 다음 해시가 성공적으로 컴파일 타임에 계산됩니다. 내 주요 기능에있을 때,
My_Struct my_normal_struct;
는 단순히 컴파일 시간 상수와 구조체 멤버를 초기화하는 대신 코드에서
constexpr uint32_t myHash(const char* const data)
함수를 호출합니다.
이렇게하면 피할 수없는 상당한 성능 저하가 발생할 수 있습니다.
컴파일러에서 컴파일시 수행 방법에 대한 의견이나 제안이 있으십니까? 나는 정말로하고 싶지 않다 :
constexpr uint32_t MY_STRUCT_ID = myHash("My_Struct");
struct My_Struct{
constexpr Test() : ID(MY_STRUCT_ID)
{
}
const uint32_t ID;
고마워.
감사합니다,이 (또는이 일부 변화) 일 수있다. – Flip