C++20 - reaching for the aims of C++
Categories: Cpp
Tags: C++
Overview
- C++์ ํ์
- โThe design and evolution of C++โ
- Will C++20 deliver on the dreams of D&E?
- The future
C++์ ํ์
c++๋ 1979๋ bell ์ฐ๊ตฌ์์์ ์์๋์๋ค
Itโs not enough to have an idea. You have to work hard to make them work
The earlist aims - Day@1
- ๋ถ์ฐ์์คํฌ์ ์ฐ๊ตฌํ๋ฉด์ ํ๋์จ์ด๋ฅผ ํจ์จ์ ์ผ๋ก ํ์ฉํ๊ณ , ๋ณต์ก์ฑ(class ์ strong static type checking์ ํตํ)์ ๊ด๋ฆฌํ ํ์๊ฐ ์๊ฒจ๋ฌ๋ค. ๊ธฐ์กด์ C์ธ์ด๊ฐ ์กด์ฌํ์์ผ๋, ์ด ๋ ๋ฌธ์ ๋ฅผ ๋์์ ํด๊ฒฐํ ์ ์์๋ค.
์ฒ์์ ์๋ฒฝํ ์ธ์ด๋ฅผ ๋ง๋๋ คํ์ง ์์์ต๋๋ค. ๊ฐ๋ฐ์๋ C์ class ๊ฐ๋ ์ ์ถ๊ฐํ๊ณ ์ถ์๊ธฐ ๋๋ฌธ์ ํ๋ก์ ํธ๋ฅผ ์์ํ์๊ณ , C++์ ์งํํ๊ธฐ์์ ๋์์ธ๋์์ต๋๋ค.
argument checking -1980
- C in 1979 aka โClassic Cโ ```C double sqrt(); dobule x = sqrt(2);
char * strchr(str, ch) char *str; { โฆ } strlen(str) char *str; { โฆ }
int y = foo(โhopeโ); /* might link, might crash */
- C with classes in 1980 (C and C++ today)
``` c++
double sqrt(double); //argument type required
double x = sqrt(2);
char* strchr(char* str, int ch) {...} // int not optional
int strlen(char* str) { ... }
int foo(char*) //declaration required
int y = foo("hope");
static cheching was first steps towards it
Argument type checking - 1983
๊ธฐ์กด c ์ฝ๋์ ํธํ๋์ง ์๋ c++ ์ฝ๋๋ค์ ๋ง์ ์ฌ๋๋ค์ ๋นํ์ ์์ต๋๋ค. ํ๋ฃจ์ 10000์ค์ ์ฝ๋๊ฐ c์์ c++๋ก convert๋์๊ณ type checking, overloading, adding user-defined types, consistent linking์ ๋ชจ๋ c++์ ์ค์ํ ๋ถ๋ถ์ด๋ฉฐ ํ๋์ ๋ถ๋ถ์ด๋ผ๋ ์๋ค๋ฉด c++์ ์์ํ ์ ์์ต๋๋ค.
ํ์ ์๋ ์กด์ฌํ๋ c++๋ฌธ์ ๋ค
-
implicit narrowing conversions - char x = 7.9 //truncation //โDonโt break the code - char y= 567; //probability truncation // Offer alternatives to โproblem featursโ - To compensate, use {} initialization: char x{7.9}; //error:narrowing conversion wonโt compile.
-
Linkage - global function is by default external - To compensate, use module
-
Some C/C++ incompatibilites came from C rather then C++ - Scope of consts - Implicit pointer conversion from void* to T* (never C++)
## Key idea: โRepresent concepts in codeโ
C++ ์ ์ ์์ฑํ๊ธฐ ์ํด์ ๊ฐ์ฅ ์ค์ํ๊ฒ์ ์ปจ์ ๋ค์ ์ฝ๋์์ ๋ณด์ฌ์ฃผ๋๊ฒ ์ ๋๋ค(์ฃผ๋ก ํด๋์ค๋ฅผ ์ฌ์ฉํด์).
- Direct Representation of ideas in code.
- Make code mroe declarative
- Make more information available to compilers Early example: Vector, String, file handle, concurrent task, message queue, hash table, grpahical shape, complex number, infinite integer
## RAII - 1979 In 1979: new function creates the run-time environment for member functions, A deleteโfunction is reverse that
Later(1983): โnew functionโ -> constructor โdelete functionโ -> destructor This is because new and elete were not just for new and delete functions
A Slightly later formulation(1980s) A Constructor establishes a class invariant(if any) for an object A destructor releases all resources owned by the object
1988: โResourece Acquisition is initialization
1981: Needed Control assignment - User defined operation=
- A recurring problem: avoid expensive copying
- always possible but tricky for users
- return value optimization from 1982
2011: - Need to control movement of object between scopes - move operation - โMove semanticโ completes the object model
2020: Improved an guaranteed copy elision
Leave a comment