C++/모두의코드

9장

twoweeks-within 2025. 2. 12. 10:15

 

1.  template 

template <typename T>

 

원하는 타입을 넣어주면 알아서 변형

>

Vector<int> int_vec;
Vector<std::string>

 

:  활용

 

2. C++ 기본처리단위 : 1byte

<> bool : 1bit

>

Vector<bool> 따로 처리

>>

템플릿 특수화 (template specialization)

template <>
class Vector<bool>
data(new unsigned int[n / 32 + 1]), capacity(n / 32 + 1), length(0)

 

int 형으로 생성한 공간에 bool 로 채우면

4byte = 32bit 즉, 32개의 bool

 

3.

bool operator[](int i) { return (data[i / 32] & (1 << (i % 32))) != 0; }

 

 비트 and 연산 후 0이 아니라면 return 1

                  "             "               return 0

 

// AND 연산 : 값 보존     > 1 

                   : 초기화 (0) > 0

 

함수 템플릿 (Function template)

 

함수 객체 (Functor): 함수인척 하는 객체 

  > 함수 인자로도 넘길수있음

 

폴드형식

return (... + nums);

 

// 9.3장

'C++ > 모두의코드' 카테고리의 다른 글

8-1 장  (0) 2025.02.09
7장  (0) 2025.02.04
6장  (0) 2025.02.02
5장 // 5.3 뒷부분은 복습때  (0) 2025.02.01
4장 이어서..  (0) 2025.01.31