This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iterator> | |
#include <vector> | |
template<typename RandomAccessIterator1,typename RandomAccessIterator2,typename Comparator> | |
int levenshtein_distance(RandomAccessIterator1 begin1,RandomAccessIterator1 end1, | |
RandomAccessIterator2 begin2,RandomAccessIterator2 end2, | |
Comparator cmp) | |
{ | |
std::vector<int> values; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <climits> | |
#include <future> | |
#include <vector> | |
#include <thread> | |
#include <chrono> | |
#include <iostream> | |
#include <numeric> | |
#include <cassert> | |
struct busy_increment { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstring> // memcpy | |
#include <type_traits> // is_trivially_copyable | |
// http://src.chromium.org/viewvc/chrome/trunk/src/base/basictypes.h?view=markup | |
// bit_cast<Dest,Source> is a template function that implements the | |
// equivalent of "*reinterpret_cast<Dest*>(&source)". We need this in | |
// very low-level functions like the protobuf library and fast math | |
// support. | |
// |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template<typename T> using ptr = T*; | |
template<typename T> using ref = T&; | |
template<typename T> using rref = T&&; | |
template<typename T> using constant = T const; | |
template<typename T> using volat = T volatile; | |
template<typename T, class C> using mem_ptr = T C::*; | |
template<std::intmax_t N, typename T> using raw_array = T[N]; | |
template<typename RetT, typename... Args> using func = RetT(Args...); | |
extern "C" template<typename T> using c_linkage = T; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template <class... Fs> struct overload_set; | |
template <class F> | |
struct overload_set<F> : F | |
{ | |
overload_set(F &&x) : F(std::forward<F>(x)) {} | |
using F::operator(); | |
}; | |
template <class F, class... Fs> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <utility> // std::forward | |
#include <memory> // std::unique_ptr | |
#include <type_traits> // std::remove_reference | |
#include <iostream> // std::cout | |
// The deleter types used with unique_ptr to do the cleanup | |
template<typename Handle, typename CleanupF> | |
struct Janitor : CleanupF { | |
using pointer = Handle; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# vi input mode (bash) | |
set -o vi | |
# Mac OS X 10.10.5 | |
export PS1='\n$(cat <<< $? > ~/.exit_code)$(/bin/date "+%l:%M:%S %p %z %A %d %B %Y" | awk "{ printf \"%*s\", $(tput cols),\$0}")\r{$(cat ~/.exit_code)} [\h \u \w] \n$ ' | |
# Windows, mintty | |
export PS1='\[\e[31;40m\]\n{$?} [\h \u \w]\[\e[0m\]\[\e[31;40m\]\n`/bin/date --utc --iso-8601=seconds`\[\e[0m\]\n$ ' | |
# Time with preexec/precmd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <string> | |
#include <iostream> // cout | |
#include <cstdint> // intmax_t | |
#include <typeinfo> | |
#include <memory> // unique_ptr | |
#include <cstdlib> // free | |
#include <cxxabi.h> // __cxa_demangle | |
extern "C" template<typename T> using c_linkage = T; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <future> | |
#include <vector> | |
#include <algorithm> | |
#include <iterator> | |
#include <numeric> | |
#include <array> | |
#include <chrono> | |
int fib(int n) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template<class InputIterator, class Function> | |
Function for_each_i(InputIterator first, InputIterator last, Function f) { | |
using index_type = std::iterator_traits<InputIterator>::difference_type i; | |
for (index_type i {}; first!=last; ++first, ++i) { | |
f(*first, i); | |
} | |
return std::move(f); | |
} | |
/* |
OlderNewer