Short Coding

    C++ std::string 메모리 관리 포함 거의 모든 멤버함수까지 직접 구현하기

    std 라이브러리의 클래스들을 직접 구현해보면 언어 기능에 대해 눈이 좀 더 뜨일 것이다. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 int main() { using string = my_string; string str[3] = {"Hello, ", "World!\n", "C++!\n"}; std::cout data()); } template my_string:: my_string(const CharT* str, std::size_t count) : sz{ count }, cap{ closest_bin(sz) }, dat{ _construct(_safe_cap(), CharT{}) } { std::copy(str, str + this->size(), this->data()); }..

    C++ Smart Pointer Type Traits 구현하기

    생 포인터인지 검사하는 것은 std 라이브러리에서 가능하다. 스마트 포인터인지도 검사 가능하게 만들어보자. 1 2 3 4 5 6 int main() { static_assert(woon2::is_unique_ptr_v); static_assert(woon2::is_shared_ptr_v); static_assert(woon2::is_smart_ptr_v); } Colored by Color Scripter cs 예제 코드 // ========================================================================== // Test Code // ==================================================================..