C,C++ 3

std::tie, std::tuple

python에서 함수의 리턴 결과로 2개 이상의 리턴값을 줄 수 있다. c++에서도 std::tie, std::tuple을 사용하여 2개 이상의 리턴값을 받을 수 있다. #include #include std::tuple sum_min(int a, int b) { return std::make_tuple(a + b, a - b); } void sume_func() { int sum; int min; std::tie(sum, min) = request_parse(1,1); auto ret = request_parse(2,2); // in c++17 // auto [sum, min] = request_parse(3,3); }; 여러 return 값이 필요할 때 struct를 리턴값으로 넘기거나 paramet..

C,C++ 2019.08.04

[c++] namespace detail

test.md namespace detail opensource library를 보다 보면 namespace detail, impl 이라는 namespace를 정의한다. 이는 라이브러리에서 사용자에게 library의 API 로서 젝공될 부분만 공개하고 제공될 필요가 없는 부분을 의미한다. 그 외 실제 구현 부분은 internal namespace 로서 감추기 위해 사용되는 부분이다. 비슷한 의미로 internal, impl, implementaion, detail 등등 여러 단어로 사용되어진다. 예를 들어 아래와 같이 openssl wrapping 라이브러리를 만들고자 한다. 여기서 사용자에게 공개되는 라이브러리 인터페이스는 namespace crypt까지이며 그 내부 구현인 detail은 라이브러리를 ..

C,C++ 2018.11.28

[C/C++] 함수 포인터

[C/C++] 함수 포인터 C와 C++에서 함수 포인터를 한번 살펴보겠습니다. 함수 포인터란 함수를 저장할 수 있는 포인터를 뜻합니다. 우선 다음과 같은 세가지를 예제로 살펴보겠습니다.1.일반 함수 포인터에 멤버함수의 주소를 담기2.일반 함수 포인터에 static 멤버변수를 만들기3.멤버 함수를 함수 포인터에 담기 #includeusing namespace std;typedef class _Point{int x;int y;public://static int s;public:_Point(int x = 0, int y = 0, int s = 0){this->x = x;this->y = y;//this->s = s;}void Print(){cout

C,C++ 2015.09.16