Skip to content

Instantly share code, notes, and snippets.

@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 / draft-text-encoding
Created August 23, 2013 12:53
Outline for introducing character and text encoding.
1.多语言字符集和编码相关的参考规范之中最重要的有两个,一个是ISO/IEC 10646,一个是 Unicode 。
前者是专家委员会起草的国际标准。(前身还有两个不同的草案,因为中国大陆等方面的反对而否决。)
后者是行业协会组织的规范。ISO/IEC 10646正式版采用Unicode方案,之后的版本也和 Unicode 有基本的对应关系(虽然不一一对应),对普通应用来说基本可以作为同一个方案。
2.Unicode 定义了通用字符集(Universal Character Set, UCS) ,其中以代码点(code point) 作为逻辑上区分字符的单位。
由于历史原因,各种同源字符可能有不同的代码点,这方面汉字( CJKV unified ideographs ,中日韩越统一表意文字)问题尤其突出(相关工作称为Han Unification)。代码点可以由 U+X 的方式表示,X是16进制的自然数。
3.现行 UCS 代码点范围 U+0~U+10FFFF ,划分为 17 个平面,编号 0~16 ,每个平面有 65536 个代码点。
其中最常用的代码点子集是 0 号平面(代码点 U+0~U+FFFF ):基本多文种平面(basic mutilingual plane, BMP) ,之后是第一辅助平面:多文种补充平面(supplementary multilingual plane, SMP) 和第二辅助平面:表意文字补充平面(supplementary ideographic plane, SIP) 。第三至十三辅助平面尚未使用。第十四辅助平面称为特别用途补充平面(supplementary special-purpose plane, SSP) ,其中是控制字符。剩下的两个平面是私人使用区(private use area) 。
一个平面内的代码点可以被两个八元组(octet) 表示,也就是 16 位二进制整数。一般 C/C++ 实现使用的一个字节正好有 8 位,但不总是保证。
4.以 UCS 为基础可以表示文本编码。
早期使用 UCS 限定于现在的一个平面内,可以用 16 位编码(两个八元组)表示任意的 Unicode 代码点,称为 UCS-2 。
@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);
};
@FrankHB
FrankHB / 何勤《 轻松学习C程序设计 》简评.txt
Created August 31, 2013 16:54
应作者要求,阅《轻松学习C程序设计——揭开计算机与程序设计的奥秘(修订版)》(资源通过网络找到),评论如下。
版权声明:本文使用 CC-BY-SA 3.0 发表。
  应作者要求,阅《轻松学习C程序设计——揭开计算机与程序设计的奥秘(修订版)》(资源通过网络找到),评论如下。
(此处找到的材料的节标号可能有错乱,按页面顺序评论。因此也不保证分节评论。)
1 计算机的重要性和基本工作原理
·作者使用“理想厨房系统”作为计算机系统的比喻。有以下一些问题:
  难以估计对于初学者来说这个比喻是否得当,有助于真正理解。
  厨房中突兀地出现了“地址传送带”“控制传送带”“IR”“PC”“R0”等和喻体不直接相关的生造抽象。这些抽象是否真容易理解?后面虽然有比较详细的说明,但细节并不十分直观且篇幅不小,可能对读者造成负担。
  语言风格问题。虽然总体比较清晰,但一些名词并不十分浅显易懂(相反容易觉得很“专业”——某种意义上事实的确如此)。如“取指周期”——具体什么意思,并没有在此直接解释。
·《理想厨房系统与计算机系统术语对照表》中“内存(又称为主存,包含很多大小相等的基本存储单元)”——错误。
//#include <ystdex/variadic.hpp> // uncommitted, see file attached;
//#include <ystdex/type_op.hpp> // see YSLib/YBase::YStandardEx;
//#include <ystdex/functional.hpp> // ditto;
//#include <YSLib/Core/yevt.hpp> // for test;
//#include <YSLib/UI/ywidget.h> // ditto;
#include <YSLib/UI/ypanel.h> // all above included;
namespace ystdex
{
@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
{