C++/Modern C++
스마트 포인터 문제 - 순환 참조
스마트 포인터 (Smart Pointer) 레퍼런스 카운팅 기반의 스마트 포인터 구현 Reference Counting #pragma once /*--------------------- *RefCountable ---------------------*/ class RefCountable { public: RefCountable() : m_refCount(1) {} virtual ~RefCountable() {} int32 GetRefCount() const { return m_refCount; } int32 AddRef() { return ++m_refCount; } int32 ReleaseRef() { int32 refCount = --m_refCount; if (refCount == 0) { dele..
[C++20] std::span
std::span C++ 20부터 추가된 연속된 메모리 공간을 추상화한 컨테이너다. 이러한 연속적인 공간을 갖는 컨테이너로는 vector, array, string 등이 있다. std::vector vecNums{ 1,2,3 }; std::array arrayNums{ 1,2,3,4 }; int cNums[6] = { 1,2,3,4,5,6 }; // c style 이와 같은 array들이 있다고할 때 하나씩 Print하기 위해서는 각 인터페이스에 맞는 함수를 만들어야한다. // vector 출력 void printVec(std::vector const& nums) { for (int num : nums) { cout
[C++] 문자열 정리
문자열 총정리 C- style의 char와 C++ style의 string이 있다. 하나씩 확인해보자. C - style char Array 사용 char a[6] = { 'a', 'b', '\n', 'c', 'd', 'e' }; cout
[C++17] string_view
string_view (C++17) C++17에서 string_view라는 기능이 추가되었다. void printString(const std::string& s) { std::cout