この記事はKMCアドベントカレンダー19日目の記事です。
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
#!/bin/bash | |
_cd_history_show() { | |
local i=0 dir list=() | |
for ((i=0; ; i++)); do | |
dir=$(dirs "$@" +$i 2>/dev/null) || break | |
list+=("$dir") | |
done | |
printf '%s\0' "${list[@]}" | |
} |
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
#!/bin/bash | |
# USAGE: _alias_complete_reuse REF CMD | |
# use the same completion function as REF for CMD | |
_alias_complete_reuse() { | |
(($# == 2)) || return | |
complete -p "$1" &>/dev/null || __load_completion "$1" | |
$(complete -p "$1" 2>/dev/null || echo false) "$2" | |
} |
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
#ifndef INCLUDE_GUARD_AB644267_F64D_4246_AF44_EA40B259E804 | |
#define INCLUDE_GUARD_AB644267_F64D_4246_AF44_EA40B259E804 | |
#include <functional> | |
#include <utility> | |
#include <variant> | |
namespace hatsusato { | |
namespace detail { | |
namespace tag { |
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 <cstdint> | |
using u64 = std::uint64_t; | |
// a + b | |
constexpr u64 mod_add(u64 a, u64 b, u64 m) { | |
if (~a < b) { | |
return (a + b) % m + ~m + 1; | |
} else { | |
return a + b; |
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 <functional> | |
#include <iostream> | |
using Manip = std::function<void(std::ostream&)>; | |
std::ostream& operator<<(std::ostream& os, Manip m) { | |
m(os); | |
return os; | |
} | |
template <typename T> | |
Manip paren(T&& x) { | |
return [x = std::forward<T>(x)](std::ostream& os) { |
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> | |
struct Unmovable { | |
protected: | |
Unmovable() = default; | |
~Unmovable() = default; | |
Unmovable(const Unmovable&) = default; | |
Unmovable& operator=(const Unmovable&) = default; | |
Unmovable(Unmovable&&) = delete; | |
Unmovable& operator=(Unmovable&&) = delete; | |
}; |
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> | |
struct Uncopyable { | |
protected: | |
Uncopyable() = default; | |
~Uncopyable() = default; | |
Uncopyable(const Uncopyable&) = delete; | |
Uncopyable& operator=(const Uncopyable&) = delete; | |
Uncopyable(Uncopyable&&) = default; | |
Uncopyable& operator=(Uncopyable&&) = default; | |
}; |
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 <boost/type_index.hpp> | |
#include <iostream> | |
#define SHOW_TYPE(x) boost::typeindex::type_id_with_cvr<decltype(x)>().pretty_name() | |
int main() { | |
std::cout << SHOW_TYPE(main) << std::endl; | |
} |
NewerOlder