Basically copying and pasting from Bjarne Stroustrup's "The C++ Programming Language 4th Edition":
List initialization does not allow narrowing (§iso.8.5.4). That is:
- An integer cannot be converted to another integer that cannot hold its value. For example, char to int is allowed, but not int to char.
- A floating-point value cannot be converted to another floating-point type that cannot hold its value. For example, float to double is allowed, but not double to float.
- A floating-point value cannot be converted to an integer type.
- An integer value cannot be converted to a floating-point type.
Example:
void fun(double val, int val2) { int x2 = val; // if val==7.9, x2 becomes 7 (bad) char c2 = val2; // if val2==1025, c2 becomes 1 (bad) int x3 {val}; // error: possible truncation (good) char c3 {val2}; // error: possible narrowing (good) char c4 {24}; // OK: 24 can be represented exactly as a char (good) char c5 {264}; // error (assuming 8-bit chars): 264 cannot be // represented as a char (good) int x4 {2.0}; // error: no double to int value conversion (good) }The only situation where = is preferred over {} is when using auto keyword to get the type determined by the initializer.
Example:
auto z1 {99}; // z1 is an initializer_list<int> auto z2 = 99; // z2 is an int이렇다고 한다~
type check을 좀더 엄격하게 한다고 보면 될듯.
아 참고로
type을 Widget이라고 가정하고
Widget func(args); 라고하면
이게 args라는 인자를 받아서 Widget type으로 리턴하는 함수를 호출하는 거를 선언해 놓은것인지
Widget type에 args를 인자로 주어서 새로운 인스턴스를 생성하는 것인지 헷갈릴 수 있는데
Widget func{args}; 라고 쓰면 정확하게 인스턴스 생성이라는 것을 알 수 있음 ㅇㅇ.
오 타입체크가 있구나
이정돈 걍 읽어야지
근데 이게 auto 에서는 또 다름 ㅋㅋㅋㅋㅋㅋ 좆병신 언어 ㅋㅋㅋㅋ
() {} 은 타입 체킹의 차이가 있는 만큼 () {} 를 구분하는 것으로 C++을 공부하는 사람의 타입을 체킹할 수 있는 것이다
마지막 줄에 auto로 type이 어떻게 되는지 확인해보면, 예제랑은 다르더라. visual c++에서만 다른가 싶긴하다만
오토라서, 에러난다는 소리네..
어우지저분
{} 의 auto 초기화 규칙이 또 병신 같은게, 함수 리턴 타입을 auto 로 지정하고 리스트 반환해도 initializer_list로 반환 안됨. 왜냐 함수 리턴타입 auto 는 템플릿 연역 규칙을 따르는데 템플릿 연역은 auto 연역이랑 다르거든 ㅋㅋㅋㅋㅋㅋㅋ