Skip to content

Instantly share code, notes, and snippets.

View utilForever's full-sized avatar

Chris Ohk utilForever

View GitHub Profile
@utilForever
utilForever / tolower.cpp
Last active August 29, 2015 14:27
tolower function comparison
#include <iostream>
#include <string>
#include <chrono>
void tolower1(std::string& s)
{
for (auto& c : s)
{
if (c <= 'Z' && c >= 'A')
c = c - ('Z' - 'z');
@utilForever
utilForever / SearchFile.cpp
Last active April 25, 2016 09:27
Search files that matches specific word in certain directory (C++17)
#include <experimental\filesystem>
#include <iostream>
#include <fstream>
using namespace std;
using namespace std::experimental::filesystem;
int main(int argc, char* argv[])
{
if (argc < 2)
@utilForever
utilForever / LeftJoin.cpp
Last active December 6, 2016 03:43
Left Join
#include <iostream>
#include <string>
#include <map>
#include <type_traits>
#include <typeinfo>
#ifndef _MSC_VER
# include <cxxabi.h>
#endif
#include <memory>
@utilForever
utilForever / JRPGCombat.cpp
Created December 29, 2016 09:55
JRPG-style combat system using std::thread, std::future, std::promise
#include <string>
#include <future>
#include <vector>
#include <sstream>
#include <iostream>
class Unit
{
public:
Unit() { }
@utilForever
utilForever / reverse_iterator_erase.cpp
Created February 9, 2017 09:58
Erase element in reverse_iterator (reverse_iterator unchanged method, and advanced method)
#include <iostream>
#include <vector>
int main(int argc, char* argv[])
{
std::vector<int> v = {1, 2, 3, 4, 5};
for (auto iter = v.rbegin(); iter != v.rend(); ++iter)
{
std::cout << *iter << '\n';
@utilForever
utilForever / is_constructible.cpp
Created February 14, 2017 01:03
std::is_constructible, std::is_trivially_constructible, std::is_nothrow_constructible
#include <iostream>
#include <type_traits>
class Foo {
int v1;
double v2;
public:
Foo(int n) : v1(n), v2() {}
Foo(int n, double f) noexcept : v1(n), v2(f) {}
};
@utilForever
utilForever / declval.cpp
Created February 14, 2017 01:04
std::declval
#include <utility>
#include <iostream>
struct Default { int foo() const { return 1; } };
struct NonDefault
{
NonDefault(const NonDefault&) { }
int foo() const { return 1; }
};
@utilForever
utilForever / insensitive_string_match.cpp
Last active March 22, 2017 09:53
Store std::string in std::map w/ and w/o lowercase process, and find arbitrary string using various methods (Insensitive case)
#include <algorithm>
#include <cctype>
#include <chrono>
#include <fstream>
#include <iostream>
#include <map>
#include <random>
#include <string>
#include <vector>
@utilForever
utilForever / ReplaceWCSWithPattern.cpp
Created June 14, 2017 09:10
Replace some pattern in std::wstring with another pattern
std::wstring ReplaceWCSWithPattern(__in const std::wstring &message, __in const std::wstring &pattern, __in const std::wstring &replace)
{
std::wstring result = message;
std::wstring::size_type pos = 0;
std::wstring::size_type offset = 0;
while ((pos = result.find(pattern, offset)) != std::wstring::npos)
{
result.replace(result.begin() + pos, result.begin() + pos + pattern.size(), replace);
offset = pos + replace.size();
@utilForever
utilForever / AbsMinMax.h
Last active June 15, 2017 03:54
Implement AbsMin(), AbsMax() function for std::array
//!
//! \brief Returns the absolute minimum value among the elements in std::array.
//!
//! \param[in] arr The array.
//!
//! \tparam T Value type.
//!
//! \return The absolute minimum.
//!
template <typename T, int N>