[c++ korea] effective modern c++ study item 2 understanding auto type deduction +손건

Post on 07-Aug-2015

101 Views

Category:

Software

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Effective Modern C++ StudyC++ Korea

Effective Modern C++ StudyC++ Korea3

Effective Modern C++ StudyC++ Korea5

Effective Modern C++ StudyC++ Korea6

auto templatedirect mapping

type deducing type deducing

Effective Modern C++ StudyC++ Korea7

template : expr을이용해 ParamType과 T를타입추론한다.

auto : auto가템플릿에서 T의역할을 , 형식지정자(type specifier)가ParamType의역할을한다.같은방식으로 타입추론한다.

auto param = expr;

Effective Modern C++ StudyC++ Korea8

conceptional templatetemplate<typename T>

void func_for_x(T param);

func_for_x(27);

template<typename T>

void func_for_cx(const T param);

func_for_cx(27);

template<typename T>

void func_for_rx(const T& param);

func_for_rx(27);

auto로변수 선언auto x = 27;

const auto cx = x;

const auto & rx = x;

Effective Modern C++ StudyC++ Korea9

conceptional templatetemplate<typename T>

void func_for_x(T param);

func_for_x(27);

auto로변수 선언auto x = 27;

컴파일러가하는 일auto로변수를선언 -> 각각맞는템플릿을호출 ->

템플릿타입추론 -> 추론한 형식에맞는 initializing expression 호출

Effective Modern C++ StudyC++ Korea10

Effective Modern C++ StudyC++ Korea11

Effective Modern C++ StudyC++ Korea12

Effective Modern C++ StudyC++ Korea13

Effective Modern C++ StudyC++ Korea14

Effective Modern C++ StudyC++ Korea15

Effective Modern C++ StudyC++ Korea16

Effective Modern C++ StudyC++ Korea17

Effective Modern C++ StudyC++ Korea18

top related