Skip to content

Instantly share code, notes, and snippets.

@hatsusato
hatsusato / tuple_print.cpp
Last active May 22, 2016 17:53
Sample of manipulator in C++11 era
#include <functional>
#include <iostream>
#include <tuple>
class Manipulator {
public:
using FuncType = std::function<void(std::ostream&)>;
Manipulator(const FuncType& f) : f_(f) {}
void exec(std::ostream& os) const { f_(os); }
private:
@hatsusato
hatsusato / manipulator.cpp
Created May 22, 2016 13:11
Manipulator in C++11 era
#include <functional>
#include <iostream>
class Manipulator {
public:
using FuncType = std::function<void(std::ostream&)>;
Manipulator(const FuncType& f) : f_(f) {}
void exec(std::ostream& os) const { f_(os); }
private:
FuncType f_;
[user]
name =
email =
[core]
editor = emacs -nw --color=auto
pager = lv -c
excludesfile = ~/.gitignore-global
[color]
ui = auto
[fetch]
;; load-path追加。
(add-to-list 'load-path "~/.emacs.d/site-lisp/")
;; C-hをバックスペースにする。
(global-set-key (kbd "C-h") 'backward-delete-char-untabify)
;; C-tの挙動をC-b C-tの感じにする。
(defun my-transpose-chars()
(interactive)
(forward-char -1)
#include <iterator>
#include <tuple>
template <typename>
class IntegerRange;
namespace iota {
template <typename INT>
class IntegerIterator : public std::iterator<std::input_iterator_tag, INT> {
template <typename> friend class IntegerRange;
@hatsusato
hatsusato / prime_sequence.cpp
Last active February 8, 2016 07:42
generate compile-time prime table
#include <array>
#include <iostream>
#include <type_traits>
#define ENABLER(cond) \
typename std::enable_if<(cond), std::nullptr_t>::type = nullptr
template <typename T, T... N>
struct IntegerSequence;
#include <type_traits>
// Usage: template <enabler_type<condition> = nullptr>
template <bool B>
using enabler_type = typename std::enable_if<B, std::nullptr_t>::type;
@hatsusato
hatsusato / apply.hpp
Created June 21, 2015 17:08
unpack tuple and apply them to a function
#include <tuple>
#include <type_traits>
#include "integer_sequence.hpp"
template <typename T>
using resultof = typename std::result_of<T>::type;
template <typename F, typename... Args, size_t... I>
auto apply_(F&& f, std::tuple<Args...>&& args, IntegerSeq<I...>)
-> resultof<F(Args...)> {
// template <class T, T... Ints> class integer_sequence; // in <utility> since C++14
template <size_t... N>
struct IntegerSeq {
using type = IntegerSeq;
static constexpr size_t size() { return sizeof...(N); }
};
template <typename S, typename T>
struct ConcatSeq_;
@hatsusato
hatsusato / make_unique.hpp
Last active January 26, 2016 14:31
make_unique
#include <memory>
#include <type_traits>
template <class T, class... Args>
typename std::enable_if<std::is_constructible<T, Args...>::value,
std::unique_ptr<T> >::type
make_unique(Args&&... args) {
return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
}
template <class T, class... Args>