프로그래밍/c++
-
std::array<bool, N> 은 비트를 다루도록 특수화 되어있지 않음프로그래밍/c++ 2020. 12. 1. 12:33
std::vector은 내부적으로 bitset처럼 다뤄지도록 템플릿 특수화가 되어있다. std::vector - cppreference.com std::vector - cppreference.com template class vector ; std::vector is a possibly space-efficient specialization of std::vector for the type bool. The manner in which std::vector is made space efficient (as well as whether it is optimized at all) is implementation defined. One potential en.cppreference.com 그런데 std::ar..
-
Concepts프로그래밍/c++ 2020. 10. 20. 13:18
특정 함수 요구 샘플 #include #include #include template concept Serializable = requires(T v, std::ostream & is) { v.Serialize(is); }; template concept Deserializable = requires(T v, std::istream & is) { v.Deserialize(is); }; template concept Convertable = Serializable && Deserializable; template void Serialize(T& v) { } template < Deseriali..
-
[C++] 정규 프로젝트 구조(Canonical Project Structure)프로그래밍/c++ 2020. 8. 28. 12:57
OpenStd, Canonical Project Structure를 참고 함 http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p1204r0.html 헤더와 CPP는 같은 디렉토리에 헤더와 소스는 옆에 있음 Header and source files (or module interface and implementation files) are next to each other (no include/ and src/ split). 의외라고 생각한 부분. 헤더는 include/ 소스는 src/ 로 나누는 방식을 권할 줄 알았음. 프로젝트의 소스 코드는 프로젝트와 동일한 이름의 디렉토리 아래에 배치 name/ ├─ name/ │ ├─ foo.hpp │ ├─ foo..
-
c++ namespace 로 감싸진 클래스, 구조체 전방 선언프로그래밍/c++ 2020. 8. 26. 02:51
// Foo.h // // namespace 를 먼저 선언 여기선 예제를 위해 AnyNamespace로 함. namespace AnyNamespace { class AnyClass; } // 여러 뎁스의 경우(since C++17) namespace AnyNamespace::Depth1::Depth2 { class AnyClass2; } class Foo { public: void HandleAnyClass_0_mutable(class AnyNamespace::AnyClass&); void HandleAnyClass_0_const(const class AnyNamespace::AnyClass&); // 또는 class를 붙여서... void HandleAnyClass_1_mutable(AnyNamespa..
-
::operator new, ::operator delete프로그래밍/c++ 2018. 10. 3. 15:25
c++에서 생성자 호출 없는 new를 찾다가 알게되었다.(c의 malloc과 같은 기능이지만)::operator new, ::operator delete는 c의 malloc과 free 처럼 사용할 수 있다. #include struct foo{ foo(){} ~foo(){}}; int main(){ foo* p = static_cast(::operator new(sizeof foo)); // 메모리 할당 new (p)foo(); // replacement new p->~foo(); // 소멸자 호출 ::operator delete(p); // 메모리 해제 return 0;}