Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View nekko1119's full-sized avatar
🍙
nano!

nekko1119 nekko1119

🍙
nano!
View GitHub Profile
@nekko1119
nekko1119 / delln.cpp
Last active August 29, 2015 14:02
ファイルの空行を消して上書きするプログラム
#include <algorithm>
#include <iostream>
#include <iterator>
#include <fstream>
#include <regex>
#include <string>
#include <vector>
#include <boost/optional.hpp>
using namespace std;
@nekko1119
nekko1119 / gist:e30c24aa655026f9cd52
Created January 27, 2015 17:05
C++時間計測用コード
#include <chrono>
#include <utility>
template <class F, class ...Args>
std::chrono::system_clock::duration take_time(F&& f, Args&&... args) {
namespace chrono = std::chrono;
auto const begin = chrono::system_clock::now();
f(std::forward<Args>(args)...);
auto const end = chrono::system_clock::now();
#include <iostream>
#include <iterator>
#include <vector>
#include <algorithm>
void merge_sort(std::vector<int>& arr) {
if (arr.size() <= 1) return;
auto left = std::vector<int>(arr.begin(), arr.begin() + arr.size() / 2);
auto right = std::vector<int>(arr.begin() + arr.size() / 2, arr.end());
merge_sort(left);
#include <array>
#include <algorithm>
#include <iostream>
#include <tuple>
#include <utility>
template <typename ...Args, std::size_t N = sizeof...(Args)>
std::array<std::common_type_t<Args...>, N> make_array(Args&&... args)
{
return {{std::forward<Args>(args)...}};
#include <iterator>
#include <type_traits>
template <class Container>
auto to_index(const Container& container, typename Container::const_iterator it)
-> decltype(std::distance(std::begin(container), it))
{
static_assert(std::is_same<
typename std::iterator_traits<
typename Container::const_iterator
constexpr int f() { return 0; }
constexpr int g();
static_assert(noexcept(f()), "");
static_assert(!noexcept(g()), "");
constexpr int h(bool b) { return b ? 0 : throw 42; }
static_assert(noexcept(h(true)), "");
static_assert(!noexcept(h(false)), "");
#include <initializer_list>
#include <iostream>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <utility>
#include <vector>
template <typename F, typename... Args>
@nekko1119
nekko1119 / group_by.cpp
Last active December 1, 2015 19:09
rubyのgroup_byをC++で書いてみた
#include <vector>
#include <numeric>
#include <unordered_map>
#include <iterator>
#include <functional>
#include <type_traits>
#include <utility>
template <typename T, typename A>
std::string to_string(std::vector<T, A> const& v);
@nekko1119
nekko1119 / ando11.cpp
Last active December 12, 2015 04:51
パターンと完全一致する左上のピクセルの座標を半角スペース区切りで出力してください。パターンと完全一致する箇所は必ず1つだけ存在します。
/*
入力
4
0 0 1 0
0 1 1 0
0 1 0 1
1 1 1 0
3
0 1 1
0 1 0
@nekko1119
nekko1119 / vtbl.cpp
Created December 17, 2015 15:53
仮想関数テーブルシミュレーション
#include <iostream>
class drawable
{
struct vtable
{
void(*draw)(void*);
};
template <typename T>