프로그래밍
-
c++ 문자열 스플릿프로그래밍/코드 조각 2018. 5. 10. 19:59
#include #include #include std::vector SplitString(const std::string& source, const std::string& spliters){ const std::regex r{ spliters }; std::sregex_token_iterator begin{ source.begin(), source.end(), r, -1 }; std::sregex_token_iterator end{}; std::vector tokens; tokens.reserve(std::distance(begin, end)); for (auto i = begin; i != end; ++i) { tokens.push_back(*i); } return tokens;} 샘플 코드int m..
-
explicit specialization of 'function name' in class프로그래밍/의문 2018. 5. 1. 21:08
클래스 안에서 '함수 이름'의 명시적인 특수화를 했습니다. 윈도우 x64에선 발생하지 않았으나 닌텐도 플랫폼 설정으로 빌드 시 발생했다.템플릿 특수화 함수의 정의가 class 안에 있어서 발생하는 오류 메세지이다.예를 들면 다음과 같은 코드일 때 해당 에러가 발생할 수 있다. class Foo{ public: template Type GetValue() const { return Type{}; } template std::string GetValue() const { return std::string{}; }}; 다음 코드처럼 정의를 외부로 빼서 오류를 해결했다. class Foo{ public: template Type GetValue()..
-
boost 의존성 없이 사용하기. asio standalone프로그래밍/c++ - boost::asio 2018. 4. 7. 19:20
asio를 boost 의존성 없이 단독으로 사용할 수 있다. 0. https://think-async.com/Asio/Download에서 asio를 다운 받는다.1. asio 소스를 프로젝트 내에 포함한다.2. 전처리기를 정의한다. #define ASIO_STANDALONE 그러면 boost가 아예 없어도 asio를 사용할 수 있다. ASIO_STANDALONE이 정의가 없으면 boost 의존성이 있으므로 주의!! boost::system::error_code -> asio::error_code 등으로 바뀌는 것들도 있다.
-
DB RETURN을 명시적으로 지정하지 않아 임의로 값이 바뀐 경우프로그래밍/의문 2018. 4. 6. 12:22
ALTER PROCEDURE spGiveStageClearReward @AccountID BIGINT, @StageID INT, @RewardItemID INTAS BEGIN BEGIN TRY INSERT INTO GameLog.dbo.ClearRewardLog ( AccountUniqueID, -- NOT NULL StageID, -- NOT NULL RewardValue) -- NOT NULL VALUES (@AccountID, @StageID, @RewardItemID, GETDATE()) END TRY BEGIN CATCH -- IGNORE EXCEPTION END CATCHEND위 프로시저에 인자로 NULL이 넘어오면 INSERT 구문은 예외를 뿜지만, try~catch 구문이 걸려있으므로 예외..
-
const std::string& 대신 std::string_view프로그래밍/c++ 2018. 2. 20. 17:01
c++17에 추가된 std::string_view는 문자열을 소유하지 않고 참조만 한다.다음과 같은 선언을 가진 함수가 있다.void print(const std::string& str) print 함수의 호출을 다음과 같이 했다고 하자. print("hello world!"); 호출될 때, 내부적으로 std::string 클래스가 만들어지고, 내부적으로 할당된 메모리 배열에 hello world!를 의미하는 값들이 채울 것이다.1~2바이트의 텍스트만 담는데도 메모리 할당을 해버리면 매우 비효율적일 것이다. 컴파일러 중에선 얼마 안 되는 메모리의 경우는 스택의 메모리를 쓰고, 그 이상을 쓰려는 경우 그때서야 메모리 할당을 하는 기법을 쓰기도 한다.(비쥬얼 스튜디오의 경우 길이 15로 기억)위와 같은 상황..
-
멀티플레이어 게임 프로그래밍 - 코드 오류 수정프로그래밍/의문 2018. 2. 20. 12:13
178p LinkingContext 코드 개량 부분 오류 // @comment: 없을 때 0을 반환하기보단, std::optinal(c++14)을 활용해 값이 있고 없음을 구분하도록 하는 게 더 좋을 거 같다. uint32_t GetNetworkID(const GameObject* inGameObject, bool inShouldCreateIfNotFound = true) { auto it = mGameObjectToNetworkIdMap.find(inGameObject); if (it != mGameObjectToNetworkIdMap.end()) { return it->second; } else if (inShouldCreateIfNotFound) { uint32_t newNetworkId = All..