Skip to content

Instantly share code, notes, and snippets.

View nekko1119's full-sized avatar
🍙
nano!

nekko1119 nekko1119

🍙
nano!
View GitHub Profile
@nekko1119
nekko1119 / serializze_stdshared_ptr.cpp
Created November 24, 2013 07:40
std::shared_ptrをシリアライズしたり、intラッパーしたり、殴り書き。
#include <iostream>
#include <boost/serialization/serialization.hpp>
#include <boost/serialization/nvp.hpp>
#include <boost/serialization/shared_ptr.hpp>
#include <boost/archive/shared_ptr_helper.hpp>
#include <memory>
struct Integer
{
int held = 0;
@nekko1119
nekko1119 / tuple.cpp
Created November 25, 2013 20:11
tupleの簡易実装試してみた。テンプレートパラメータのintはstd::size_tの方が良いと思うけど面倒臭かったのでint。計算量はO(N)だけどtupleってO(logN)で実装可能なんですかね?
template <typename... Args>
class tuple;
template <int Index, typename Tuple>
struct tuple_element;
template <int N, typename... Args>
typename tuple_element<N, tuple<Args...>>::type& get(tuple<Args...>& t);
template <typename Head, typename... Tails>
@nekko1119
nekko1119 / debug.xml
Last active December 30, 2015 17:49
boost::property_tree::ptreeで、形式の定まっていないxmlファイル等の全ての要素を再帰的に得る方法。
<debug>
<filename>debug.log</filename>
<modules>
<module>Finance</module>
<module>Admin</module>
<module>HR</module>
</modules>
<level>2</level>
</debug>
@nekko1119
nekko1119 / gist:8132124
Last active January 1, 2016 10:29
boost::signal2でshared_ptrを用いたトラッキングの方法
#include <iostream>
void hello()
{
std::cout << "Hello ";
}
struct World
{
void operator()()
@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
#include <initializer_list>
#include <iostream>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <utility>
#include <vector>
template <typename F, typename... Args>