tuple
```cpp #include
```cpp #include
```cpp #include
함수 인자의 개수는 다양하다. 가변인자 템플릿으로 만들자 ```cpp #include
```cpp #include
인자, 리턴값 등은 무조건 사용하지 말고 값이 유효한지 확인하는것이 좋다. assert
문자열 에서 \ 를 쓰고 싶을때: “\\“<p> \ 를 한번만 적을 수 있는 표현식 ```cpp #include
```cpp class Base { public: virtual void foo(int) {} virtual void goo() const {} void hoo() {} };
```cpp #include
auto 추론: 템플릿과 동일 auto 표현식의 참조, const, volatile 제거 auto& 표현식의 참조만 제거 ```cpp int main() { const int c = 10; const int&...
일관된 초기화: Uniform initialize 변수의 종류에 상관없이 동일한 방법으로 초기화 할 수 있게 하자 ```cpp struct Point { int x, y; }; class Complex { int re, im; public: Complex(int a, i...
위임 생성자: Deligating constructor 본인의 다른 생성자를 호출하는 생성자 ```cpp #include
```cpp #include
사용자 정의 상수: 상수 값으로 사용자 정의 타입을 만들 수 있다. c++ 기본 상수 1.0f 2l “string”s: stl 사용자 정의 상수 1_m 2.0_dd “my st...
```cpp #include #include
```cpp #include #include #include
```cpp #include #include #include // find() 와 같은 함수가 여기에 있다.
싱글 리스트를 생각해 보자 ```cpp #include
setp1. c 의 strchr() 함수 ```cpp #include
간접층의 원리: Level of Indirection 아무리 어려운 문제점도 중간층(기존 요소 사이에 새로운요소) 를 도입하면 해결 할 수 있다. 기존 요소를 대신한다는 의미로 Proxy Pattern 이라고도 불리는 디자인 기법 ```cpp struct VectorSiz...
타입 추론: Type Deduction<p> 규칙1. ParamType 이 포인터나 참조가 아닐때, expr 의 const, volatile, reference 속성을 제거하고 전달된다. ```cpp template void goo(const T& a) { ...
완변한 전달자: perfect forwarding ```cpp #include
Checked delete boost 팀이 최초로 만든 개념 ```cpp #include
복사금지: 요즘 뜨고 있는 방식<p> 단지 자원 관리 목적으로만 사용된다면, 참조계수 방식 보다는 복사 금지 방식의 스마트 포인터가 더 좋다. 모든 함수가 inline 치환 된다. 참조계수를 위한 어떠한 메모리도 필요없다. 스마트 포인터 도입에 따른 오버헤드...
const 위치: 아래 2개는 완전히 동일한 표현이다. const int c1 = 10; int const c2 = 10; 상수와 비상수를 가르키는 포인터 ```cpp int main() { int n = 10; const ...
스마트 포인터 임의의 객체가 다른 타입의 포인터 처럼 사용되는 것 * 연산자와 -> 연산자를 재정의 해서 포인터 처럼 보이게 한다 * 연산자는 참조 리턴을 해야 한다.
변환 연산자 객체(Point) => 다른 타입(int) 변환 생성자 다른 타입(int) => 객체(Point) ```cpp class Point { int x, y; public: Point() : x(0...
포인터 멤버를 가진 클래스가 있다면 반드시 복사 생성자를 만들어야 한다.<p> 그렇지 않다면 컴파일러가 만드는 디폴트 생성자가 얕은 복사를 한다. ```cpp #include
lvalue = 의 양쪽에 모두 올 수 있다. 변수, 이름이 있다. 참조를 리턴하는 함수 블럭을 벗어날 때 까지 생존 rvalue = 의 오른쪽에만 올 수 있다. 상수, 이름이...
Point p; 이름있는 객체 p 블럭을 벗어나기 전 까지 생존 Point(); 이름 없는 임시 객체 현재 문장에서만 유효 하다. ```cpp #include
c 캐스팅의 문제점 대부분 성공한다 너무 위험하고 버그가 많다 ```cpp #include
CRTP: Curiously Recurring Template Pattern 부모가 템플릿 인데, 자식을 만들때 자신의 이름을 부모에게 인자로 전달해 주는 기술 미래에 만들어질 자식의 이름을 사용 할 수 있다. ```cpp #include
단위 전략(policy base) 디자인 기술 클래스 설계 시 정책을 담을 정책 클래스를 템플릿 인자로 교체 할 수 있게 디자인 하는 기술 성능 저하 없이 정책을 변경 할 수 있다. 모든 정책 클래스는 지켜야 하는 규칙이 있다. lock() ...
```cpp template class vector { T buffer[100]; int _size; public: void push_front(T a) {} T front() { return buffer[0]; } int size() { ret...
가변인자 템플릿 ```cpp #include
템플릿 인자 타입 정수형 상수(변수 안됨, 실수 안됨) ```cpp template<typename T = int, int N = 10> struct stack { T buff[N]; };
자명한 생성자(trivial constructor): 아무 일도 하지 않는 생성자 가상함수가 없다 부모가 없거나 부모의 생성자가 trivial 하다 객체형 멤버가 없거나 객체현 멤버의 생성자가 trivial 하다 사용자가 만든 생성자가 없다 생성자는 “trivial...
```cpp #include
템플릿 부분 전문화 ```cpp #include
```cpp class AAA { public: // static int DWORD; typedef int DWORD; };
템플릿을 만들때 값(T) 으로 전달 받으면 argument decay 되어 형 변환되어 전달된다. 배열: 포인터 함수: 함수 포인터 참조(&T) 로 전달 받으면 정확히 전달 된다. 배열: 배열 ...
함수 오버로딩 함수 사용자: 하나의 함수 처럼 보인다. 함수 제작자: 2개의 함수를 만들어야 한다. int square(int a) { return a * a; } double square(double a) { return a * a; } 유사한...
new 의 동작 방식 operator new() 함수를 사용해서 메모리 할당 메모리 할당이 성공하고 객체라면 생성자 호출 메모리 주소를 해당 타입으로 캐스팅 해서 리턴
인라인 함수와 포인터 관계 인라인 치환은 컴파일 시간 문법 이다. 인라인 함수라도 함수포인터에 담아서 사용하면 인라인 치환 되지 않는다. ```cpp int add1(int a, int b) { return a + b; }
auto 키워드 ```cpp int x = 10;
```cpp #include
```cpp #include
멤버함수의 호출 원리 객체가 함수의 1번째 인자(this) 로 추가 된다. - this call 정확히는 exc 레지스터로 전달 static 멤버 함수는 this 가 추가되지 않는다. ```cpp class Point { in...
1754. Largest Merge Of Two Strings class Solution { public: string largestMerge(string word1, string word2) { if (word1.size() == 0 || word2.size...
950. Reveal Cards In Increasing Order class Solution { public: vector<int> deckRevealedIncreasing(vector<int>& deck) { deque<i...
1443. Minimum Time to Collect All Apples in a Tree ```cpp class Solution { vector<vector> map; vector visit, has; public: int minTime(int n...
1447. Simplified Fractions class Solution { public: vector<string> simplifiedFractions(int n) { vector<string> result; for (i...
907. Sum of Subarray Minimumse ```cpp class Solution { public: int sumSubarrayMins(vector& arr) { int len = arr.size(); stack<pair...
1139. Largest 1-Bordered Square ```cpp class Solution { public: int largest1BorderedSquare(vector<vector>& grid) { int h = grid.size(),...
1738. Find Kth Largest XOR Coordinate Value ```cpp class Solution { public: int kthLargestValue(vector<vector>& matrix, int k) { int h ...
1043. Partition Array for Maximum Sum class Solution { public: int maxSumAfterPartitioning(vector<int>& arr, int k) { int len = arr.siz...
858. Mirror Reflection ```cpp class Solution { int gcd(int a,int b) { while(true) { int r = a%b; if (r == 0) { return b; ...
738. Monotone Increasing Digits class Solution { public: int monotoneIncreasingDigits(int n) { int result = 0; while (n) { in...
1054. Distant Barcodes ```cpp class Solution { struct cmp{ bool operator()(int a, int b){ return (a & 0xffff) < (b & 0xfff...
1654. Minimum Jumps to Reach Home class Solution { public: int minimumJumps(vector<int>& forbidden, int a, int b, int x) { if (x == 0) ...
1195. Fizz Buzz Multithreaded ```cpp class FizzBuzz { private: int n; int c = 1; mutex m; condition_variable cv;
529. Minesweeper ```cpp class Solution { int xx[8]{-1, 0, 1, 1, 1, 0, -1, -1}; int yy[8]{-1, -1, -1, 0, 1, 1, 1, 0}; public: vector<vector>...
838. Push Dominoes ```cpp class Solution { public: string pushDominoes(string dominoes) { queue q; int len = dominoes.size(); for...
1828. Queries on Number of Points Inside a Circle class Solution { public: vector<int> countPoints(vector<vector<int>>& points, vec...
2013. Detect Squares class DetectSquares { map<int, int> mp; public: DetectSquares() { } void add(vector<int> point...
1306. Jump Game III class Solution { public: bool canReach(vector<int>& arr, int start) { if (arr[start] == 0) { return tru...
869. Reordered Power of 2 ```cpp class Solution { class Dec { int cnt[10] {0}; int len = 0; public: Dec(int n) { ...
930. Binary Subarrays With Sum class Solution { public: int numSubarraysWithSum(vector<int>& nums, int goal) { int l = 0, r = 0, len = ...
Common Header: CommHdr.h #ifdef _WIN32 #pragma comment(lib, "ws2_32") #define _WINSOCK_DEPRECATED_NO_WARNINGS #include <stdio.h> #include <stdlib.h&...
다음 순열 구하기 (Next permutation)