Skip to content

Instantly share code, notes, and snippets.

@FrankHB
FrankHB / seq_curry.cc
Last active August 29, 2015 14:00
C++14 Currying test
// clang++ -std=c++1y a.cc -o a.exe
#include <cstdio>
void seq(){}
template<class T, class... P> void seq(T arg, P... args){ static_cast<void>(arg()); seq(args...); }
auto curry = [](auto f){return [f](auto... x){return [=](auto y){return f(x..., y); }; }; };
auto make_seq = [](auto f){return [f](auto... x){seq([=]{return f(x);}...); }; };
auto seq_curry = [](auto f){return curry(make_seq(f)); };
template<size_t N>
@FrankHB
FrankHB / 李煌排序测试.cc
Created May 29, 2014 05:02
李煌排序测试
#include <ytest/timing.hpp> // https://github.com/FrankHB/YSLib/blob/master/YBase/include/ytest/timing.hpp
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using namespace ytest::timing;
struct tr
{
@FrankHB
FrankHB / C++吧城门纪略20140530.txt
Last active August 29, 2015 14:02
C++吧城门纪略20140530
缘起:
http://tieba.baidu.com/p/3063141987
首先是羊驼受不鸟了:
http://tieba.baidu.com/p/3073589768
城门本体:
http://tieba.baidu.com/p/3074520245
混战:
@FrankHB
FrankHB / daze_player.cc
Created July 26, 2014 10:50
daze_player
// http://tieba.baidu.com/p/3172996151
struct daze_player : player
{
state s;
virtual state play( std::size_t milisecond_left, const std::vector< state > & self_history, const std::vector< state > & opponent_history )
{
s = (((millisecond_left + std::size_t('d')) * self_history.size() / (opponent_history.size() + std::size_t('a')) + std::size_t('z')) + std::size_t('e') * (self_history.size() ^ opponent_history.size())) % 3;
return s;
}
};
@FrankHB
FrankHB / 150422.cc
Last active October 19, 2015 00:43
UTF-8 decoding/encoding performance test
// LICENSE: MIT
// Based on: https://github.com/9chu/minicodecvt/blob/master/TestCpp/main.cpp
// Depends on:
// rapidjson: https://github.com/miloyip/rapidjson .
// minicodecvt: https://github.com/9chu/minicodecvt
// YSLib: https://github.com/FrankHB/YSLib
// MCF: https://github.com/lhmouse/MCF
// Prerequisite:
// *-w64-mingw32-g++ supports '-std=c++14'.
// Run Tool/install-sysroot.sh in YSLib repo dir to install Sysroot
@FrankHB
FrankHB / max_xx.hh
Last active December 17, 2015 03:49
A set of "max" templates using parameter pack.
#include <string>
#include <iostream>
using namespace std;
template<typename T>
inline const T&
max_xx(const T& x, const T& y)
{
return y < x ? x : y;
}
@FrankHB
FrankHB / tmp-win32-shell.cc
Last active December 18, 2015 02:29
Windows shell temp code.
#include <iostream>
#include <shlobj.h>
#include <shlwapi.h>
#include <objbase.h>
//#include <Windows.Foundation.h>
using namespace std;
class COM
{
@FrankHB
FrankHB / string-multicat.cc
Last active December 18, 2015 12:09
g++ -std=c++11 -O3 a.cc
#include <string>
#include <algorithm>
#include <cstring>
#include <utility>
#include <cassert>
#include <iostream>
using namespace std;
#if 1
@FrankHB
FrankHB / base.cc
Last active December 20, 2015 07:59
YFramework base test.
#define YB_T_NO_MATH 1
//#define YB_T_NO_IOSTREAM 1
//#define YB_T_NO_TIMING 1
#define YTEST_B 4
#include "../../Temp/test.h"
#include <ysbuild.h>
#include <Helper/HostWindow.h>
#include <windows.h>
#include "../HelperEx/Shells.h"
#include <NPL/SContext.h>
@FrankHB
FrankHB / alpha-composite.hpp
Created August 26, 2013 04:41
Alpha Compositing
template<typename _type, std::uintmax_t _vNum = 1, std::uintmax_t _vDen = 1,
bool _bIsFloat = std::is_floating_point<_type>::value>
struct normalized_max;
template<typename _type, std::uintmax_t _vNum, std::uintmax_t _vDen>
struct normalized_max<_type, _vNum, _vDen, true>
{
static yconstexpr _type value = double(_vNum / _vDen);
};