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 / SimpleReflection.cpp
Created August 25, 2016 01:54
Simple reflection on C++17 [Very simple approach to convert any struct (up to N members) to a tuple using C++17 structured bindings and the idea from Boost.DI]
#include <tuple>
#include <type_traits>
#include <cassert>
template <class T, class... TArgs> decltype(void(T{std::declval<TArgs>()...}), std::true_type{}) test_is_braces_constructible(int);
template <class, class...> std::false_type test_is_braces_constructible(...);
template <class T, class... TArgs> using is_braces_constructible = decltype(test_is_braces_constructible<T, TArgs...>(0));
struct any_type {
template<class T>
@utilForever
utilForever / FSM.cpp
Created September 2, 2016 11:34
Finite State Machine Example
#include <iostream>
#include <string>
enum States { IDLE, MOVE, YUMYUM, EAT, DIE, CLEAR, FINISH };
void RunLogic(States);
int main()
{
// FSM : Finite State Machine (유한 상태 기계)
@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 / CallMemberFunction.cpp
Created February 3, 2017 01:04
Call member function pointed by instantiated object (using variadic template and std::bind)
#include <iostream>
#include <functional>
class AAA
{
public:
bool A(int a, int b, int c)
{
return a + b + c > 10;
}
@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; }
};