매겨변수로 사용할 때에는 stirng& 혹은 char* 를 대신해서 사용.

string_view getText(){};

 

string a = getText() 와 같이 사용못함. //error

string a = getText().data(); 

string a = string(getText()); 와 같이 사용.

 

auto text = "Hello string_view"sv;  //와 같이 리터럴로 사용할 수있다.

 

int stoi(const string& str, size_t *idx=0, int base=10);
long stol(const string& str, size_t *idx=0, int base=10);
unsigned long stoul(const string& str, size_t *idx=0, int base=10);
long long stoll(const string& str, size_t *idx=0, int base=10);
unsigned long long stoull(const string& str, size_t *idx=0, int base=10);
float stof(const string& str, size_t *idx=0);
double stod(const string& str, size_t *idx=0);
long double stold(const string& str, size_t *idx=0);

#include <iostream>


template<typename T1,typename T2, typename RT>
RT GetValue(T1 nValue, T2 nValue2)
{
	return RT(nValue + nValue2);
}

template<typename RT,typename T1, typename T2>
RT GetValue2(T1 nValue, T2 nValue2)
{
	return RT(nValue + nValue2);
}

//C++ 14 
template<typename T1, typename T2>
auto GetValue3(T1 nValue, T2 nValue2)
{
	return (nValue + nValue2);
}

template<typename T1, typename T2>
auto GetValue4(T1 a, T2 b)->decltype((a < b) ? a : b) //faily elaborate
{
	return a + b;
}

int main()
{
	GetValue<int,int,int>(10, 20.1); // 리턴값을 위해, 템플릿 파라미터 3개를 명시했다.
	GetValue2<double>(20, 20.2); // 리턴값을 먼저 선언해서, 간결해졌다.
	auto nRet = GetValue3(20, 20.2); //리턴타입을 auto로 선언.
	auto nRet2 = GetValue4(10, 10.1); // 리턴타입을 decltype으로 선언하여, 명시했다.


	return 0;
}

+ Recent posts