Skip to content

Instantly share code, notes, and snippets.

View evanzillians's full-sized avatar

Evan Lin evanzillians

View GitHub Profile
@evanzillians
evanzillians / min-max-add.js
Created December 25, 2012 07:06
Multiple return value usecase
// illustrate that user could add functionality on origin functions easily
function min_max<T>(v1: T, v2: T ): (T, T);
function min_max<T>(v1: T, v2: T, v3: T ): (T, T);
function min_max<T>(v1: T, v2: T, v3: T, v4: T): (T, T);
function min_max_add<T>(v1: T, v2: T ) { return min_max(v1, v2 ), v1 + v2 ;}
function min_max_add<T>(v1: T, v2: T, v3: T ) { return min_max(v1, v2, v3 ), v1 + v2 + v3 ;}
function min_max_add<T>(v1: T, v2: T, v3: T, v4: T) { return min_max(v1, v2, v3, v4), v1 + v2 + v3 + v4;}
@evanzillians
evanzillians / iterator.hpp
Last active December 10, 2015 04:08 — forked from anonymous/main.cpp
Parser using Spirit.Qi which generate additional information as token.
#ifndef ITERATOR_HPP
#define ITERATOR_HPP
#include <boost/spirit/include/classic_position_iterator.hpp>
typedef boost::spirit::classic::position_iterator<std::wstring::const_iterator> iterator_type;
#endif /* ITERATOR_HPP */
@evanzillians
evanzillians / main.cpp
Created January 8, 2013 17:33
Dispatcher draft
#include <iostream>
#include <tuple>
#include <type_traits>
#include <vector>
class node_base;
template<typename C>
std::false_type has_begin_end_eval(...);
@evanzillians
evanzillians / comprehense.cpp
Last active December 14, 2015 15:28
comprehense
#include <iostream>
#include <iterator>
#include <list>
#include <string>
#include <type_traits>
#include <utility>
#include <vector>
template<typename container_type, typename transformer_type>
auto comprehense(container_type&& c, transformer_type&& t) -> typename std::remove_cv<typename std::remove_reference<container_type>::type>::type
@evanzillians
evanzillians / haha.cpp
Created April 1, 2013 09:56
get destructors at compile time
#include <functional>
#include <vector>
template<typename T>
std::function<void(void *)> get_dtor()
{
return [](void *p)
{
return static_cast<T *>(p)->~T();
};
@evanzillians
evanzillians / test.cpp
Last active December 17, 2015 07:39
ADL fails on boost::integer_range
#include <vector>
#include <boost/range/iterator_range.hpp>
#include <boost/range/irange.hpp>
int main() {
std::vector<int> v;
auto range_1 = boost::make_iterator_range(v);
auto range_2 = boost::irange(0, 1);
@evanzillians
evanzillians / set_iterators.hpp
Last active December 20, 2015 06:49
set union helper: iterator, range
#ifndef SET_UNION_ITERATOR_RANGE_HPP
#define SET_UNION_ITERATOR_RANGE_HPP
#include <type_traits>
#include <utility>
#include <boost/blank.hpp>
#include <boost/iterator/iterator_adaptor.hpp>
#include <boost/iterator/iterator_categories.hpp>
#include <boost/logic/tribool.hpp>
@evanzillians
evanzillians / draft.txt
Last active August 29, 2015 13:56
Draft of repo
thor
├── contrib
│   ├── bar
│   └── foo
├── include
│   ├── dir-1
│   │   └── hdr-1.h
│   └── dir-2
│   └── hdr-2.h
├── src
@evanzillians
evanzillians / async.t
Last active August 29, 2015 13:59
Proposal of new design of async
task do_a(n: int32): int32 { ... }
task do_b(n: int32): int32 { ... }
task test(target: Domain): void
{
do_a(1); // call do_a
do_b(2); // call do_b
16: do_a(1); // call do_a with 16 times
16: do_b(2); // call do_b with 16 times