기술 노트

[C++] Item 1: Understand template type deduction

By  | 2017년 9월 17일 | 
Item 1: Understand template type deduction---------------------------------------------------------- auto는 template에 대한 type deduction (형식 연역)에 근간을 둠단, auto는 template에 비해 덜 직관적 임auto를 잘 활용하려면 template type deduction의 모습을 잘 이해 해야함 template의 형태 template<typename T>void f(ParamType param); f(expr); 의 형태로 호출 T에 대한 형식과 ParamType에 대해 연역(추론)하게 됨ParamType은 const와 같은 adornments (꾸밈)을 추가하는 경우가

[C++] Item 2: Understand auto type deduction

By  | 2017년 9월 20일 | 
auto type deduction이 곧 template type deduction임 template<typename T>void f(ParamType param); f(expr); // compiler는 expr에서 T의 형식과 ParamType을 추론(deduction)함 auto와 template의 T는 동일한 역할을 수행변수의 형식 지정자는 ParamType과 동일한 역할 수행 auto x = 27; // x의 형식 지정자는 그냥 auto 자체 const auto cx = x; // 형식 지정자(type specifier)는 const auto const auto& rx = x; // const auto&가 type specifier templat

[C++] Item 36: Specify std::launch::async if asynchronicity is essential

By  | 2018년 2월 28일 | 
std::launch::async 다른 thread에서 비동기로 시작함std::launch::deferred future의 get, wait 호출 시에 동기적으로 실행됨 이전까지는 지연됨 future 객체는 future 객체가 지칭하는 공유 상태 std::shared_future는 복사를 지원하기에 std::async가 리턴하는 객체와 다를 수도 있음 기본 launch policy async | deferred 임 auto fut1 = std::async(f); // run f using default launch policy auto fut2 = std::async(std::launch::async | // run f ei

ERROR: Enable multithreading to use std::thread

By  | 2017년 12월 5일 | 
terminate called after throwing an instance of 'std::system_error' what(): Enable multithreading to use std::thread: Operation not permitted --> add '-pthread' (not -lpthread)

[C++] Item 35

By  | 2018년 2월 24일 | 
Item 35: Prefer task-based programming to thread-base 비동기로 어떤 함수를 수행하고 동작시키고 싶다면, 2가지 선택이 있음 1) std::thread2) std::async std::threadint doAsyncWork();std::thread t(doAsyncWork); std::asyncauto fut = std::async(DoAsyncWork); // “fut” for “future” async로 넘어간 함수 객체는 “task”로 간주됨thread-based 보다, 이러한 task-based가 보통 좋음코드량이 적고, return 처리가 가능함thread-base의 경우 return에 access할 수 있는 직접적인 방법이 없음 task