atoi #include <cstdlib> #include <iostream> #include <string> #include <typeinfo> int main() { const std::string str("123"); auto num = std::atoi(str.c_str()); std::cout << typeid(num).name() << " : " << num << std::endl; } strtol #include <cstdlib> #include <iostream> #include <string> #include <typeinfo>...
더 읽기
원문 attribute(속성) 라는 것은 attribute(속성)는 컴파일러에 추가 정보를 전달하는 구문으로 [[attributes]] 이라고 쓴다. 최적화나 경고 추가나 제어 등을 할 수 있다. C++11 noreturn 속성 함수 함수가 결코 반환 하지 않는 것을 표시하는 속성 예외 송출이나 std::exit, std::abort 의 랩퍼 함수에...
더 읽기
chan의 공간이 다 찰 때까지 보내기를 하면 빈 공간이 생길 때까지 블럭킹 상태가 된다. 블럭킹 상태에 빠지지 않게 하는 방법 중의 하나의 select와 조합해서 사용한다. ch1 chan []byte ch1 = make(chan []byte, config.MaxChannelSize) func sendData(data []byte) { select { case...
더 읽기
의사 코드 class Player { Player(const int index) {} }; class UserManager { public: void NewUser(); void DeleteUser(const int playerIndex); private: list<shared_ptr<Player>> m_PlayerList; // 실제 사용 중인 플레이어들 vector<shared_ptr<Player>> m_PlyerPool; // Player 객체 pool deque<int> m_EmptyPoolIndex; }; void UserManager::Init(const int...
더 읽기
3,4년 전쯤에 번역했던 것을 공유한다
더 읽기
출처 this 포인터를 std::shared_ptr로 얻을 수 있는 기능으로 std::enable_shared_from_this 기본 클래스와 멤버 함수 shared_from_this()가 있다. std::enable_shared_from_this에서 파생된 클래스의 개체를 new 하고 shared_ptr의 생성자에 전달하면 이 개체의 this를 shared_ptr로 취득 할 수 있다. 그러나 아래와 같은 포인터에서 복수의 shared_ptr 개체를 만든...
더 읽기
출처 병행 프로그래밍으로 문제가 될 수 있는 캐시 무효화 문제를 제어 할 수 있다. false sharing 제어 struct keep_apart { atomic<int> cat; atomic<int> dog; }; 이런 구조가 있으면 cat와 dog가 같은 캐시 라인에 탈 수 있다. 스레드 1은 cat 변수,...
더 읽기
std::sample()이 <algorithm>에 추가 되었다. #include <iostream> #include <string> #include <iterator> #include <random> #include <algorithm> int main() { const std::string input = "abcdef"; // input에서 3개 요소를 무작위로 추출한다 // 기본 난수 생성기를 사용한다 { std::string result; std::sample(input.begin(), input.end(), std::back_inserter(result), 3);...
더 읽기
4,5년 전쯤에 번역했던 것을 공유한다
더 읽기
try_emplace() 멤버 함수: 삽입 실패 시에 주어진 파라미터 args…를 변경하지 않는다. insert_or_assign() 멤버 함수: 삽입에 실패하면 덮어 쓴다. std::map<std::string, std::unique_ptr<Foo>> m; m["foo"] = nullptr; std::unique_ptr<Foo> p(new Foo); auto res = m.try_emplace("foo", std::move(p)); assert(p); // p는 유효 std::map<std::string, int> m; auto...
더 읽기