C++
-
[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..
-
boost/asio deprecated 1.69.0프로그래밍/c++ - boost::asio 2019. 3. 11. 04:44
boost::asio가 c++ 표준에 들어가게 되서 그런지 변경 사항들이 많다.호환성을 위해 더이상 더이상 사용되지 않는 코드들이 여전히 남아있지만,전처리기에 BOOST_ASIO_NO_DEPRECATED를 지정하면 더이상 사용되지 않는 코드들이 비활성화 된다. io_service가 io_context로 이름 변경io_context::dispatch가 dispatch 로 대체 됨io_context::post가 post 로 대체 됨io_context::strand::wrap이 bind_execuator 로 대체 됨io_context::get_io_context(), io_context::get_io_service()가 context() 함수로 이름 변경.io_context::strand::get_io_con..
-
boost/asio simple periodic timer프로그래밍/코드 조각 2019. 3. 4. 12:28
#include #include #include class PeriodicTimerExample{public: PeriodicTimerExample() : timer{ctx} { } void run() { tick(); ctx.run(); } private: void tick() { using namespace std; timer.expires_after(3s); timer.async_wait([this](const auto & err) { cout
-
c++, istream으로 읽은 개수 반환 gcount프로그래밍/코드 조각 2019. 1. 19. 12:21
readsome이 아니다. auto MakeHash(std::istream& is){ std::array fileHash; SHA256_CTX ctx; SHA256_Init(&ctx); char buf[512]{ 0, }; while (is.good()) { is.read(buf, sizeof(buf)); const int cnt = is.gcount(); SHA256_Update(&ctx, buf, cnt); } SHA256_Final(fileHash.data(), &ctx); return fileHash;}gcount는 마지막으로 읽어난 엘리먼트의 개수를 반환한다.
-
error_code 정의 참고 코드 조각프로그래밍/코드 조각 2018. 10. 28. 00:59
enum class VerificationErrc{ //Algorithms provided does not match with header InvalidAlgorithm = 1, //Token is expired at the time of decoding TokenExpired, //The issuer specified does not match with payload InvalidIssuer, //The subject specified does not match with payload InvalidSubject, //The field IAT is not present or is of invalid type InvalidIAT, //Checks for the existence of JTI //if val..
-
c++에서의 패킷 핸들러 바인딩프로그래밍/코드 조각 2018. 10. 21. 23:43
#include #include #include using namespace std; namespace packet{ enum class Type : unsigned short { None = 0, Login = 1, Logout = 2, }; struct Header { std::uint16_t size; Type type; }; struct Login { char id[20]; std::uint8_t len; };} std::map handlers; template void bind(packet::Type type, void(*handler)(int, const PayloadType&)){ handlers[type] = [handler](int network..
-
::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;}