Skip to content

Instantly share code, notes, and snippets.

@yumetodo
yumetodo / unique_factorization.hpp
Created December 24, 2018 10:40
素因数分解
#include <iostream>
#include <cstdint>
#include <vector>
#include <cmath>
struct unique_factorization_element {
std::uint32_t prime;
std::uint8_t pow;
};
std::ostream& operator<< (std::ostream& os, const unique_factorization_element& e)
{
@yumetodo
yumetodo / contiguous_iterator.hpp
Last active December 17, 2018 11:11
inferior vector util
#ifndef INFERIOR_ITERATOR_CONTIGUOUS_ITERATOR_HPP_
#define INFERIOR_ITERATOR_CONTIGUOUS_ITERATOR_HPP_
#include <inferior/no_min_max.h>
#include <cstddef>
#include <iterator>
#include <inferior/type_traits.hpp>
namespace inferior {
template<typename Container>
class contiguous_iterator {
@yumetodo
yumetodo / hatena_blog_katex_loader.js
Last active December 14, 2018 11:10
improve message
document.addEventListener("DOMContentLoaded", () => {
"use strict";
Array.from(document.getElementsByClassName("math-render"))
.filter(e => !e.mathRendered)
.forEach(e => {
try {
katex.render(e.textContent, e, {displayMode: true });
} catch (ex) {
e.textContent = ex.message;
}
@yumetodo
yumetodo / iterator_wrapper.hpp
Last active June 6, 2018 12:34
イテレーターをラップしてイテレータを作る練習
#include <iterator>
#include <vector>
#include <iostream>
#include <utility>
struct Vec2f{
float x; float y;
};
struct Circle {
Vec2f pos;
float size;
@yumetodo
yumetodo / pgm_p2_reformater.cpp
Created May 21, 2018 04:57
pgm(P2) image reformatter
#include <iostream>
#include <sstream>
#include <string>
int proc_main(std::istream& is, std::ostream& os)
{
std::string pn;
if(!std::getline(is, pn)) return 1;
if("P2" != pn) return 2;
std::string tmp;
if(!std::getline(is, tmp)) return 3;
@yumetodo
yumetodo / netdata.conf
Created April 1, 2018 10:25
For Apache 2.4.
<VirtualHost *:80>
ServerName netdata.irregular-at-tus.work
ServerAdmin https://qiitadon.com/@yumetodo
DocumentRoot /usr/share/netdata/web/
Redirect permanent "/" "https://netdata.irregular-at-tus.work/"
ErrorLog /home/for_netdata/logs/netdata-error.log
@yumetodo
yumetodo / codepoint_count_from_template_param_packed_chars.hpp
Created March 30, 2018 23:20
literal operator templateを文字列リテラルに適用できると勘違いして作った産物
inline constexpr int get_u8_byte_count(char ch) {
if (0 <= uint8_t(ch) && uint8_t(ch) < 0x80) {
return 1;
}
if (0xC2 <= uint8_t(ch) && uint8_t(ch) < 0xE0) {
return 2;
}
if (0xE0 <= uint8_t(ch) && uint8_t(ch) < 0xF0) {
return 3;
}
digraph G {
"_M_realloc_insert" -> "_M_check_len"
"_M_fill_insert" -> "_M_check_len"
"_M_default_append" -> "_M_check_len"
"_M_range_insert" -> "_M_check_len"
"emplace_back" -> "_M_realloc_insert"
"insert" -> "_M_realloc_insert"
"_M_insert_rval" -> "_M_realloc_insert"
"_M_emplace_aux" -> "_M_realloc_insert"
"push_back" -> "_M_realloc_insert"
私は長い間nullptrの型はvoid*と思い込んで居たのですが、実は違います。
nullptrの型はstd::nullptr_tとおなじになります。
std::nullptr_tは、cstddefヘッダでtypedefされている型で、decltype(nullptr)の別名となっています。内部的な型名は決まっていません。
decltypeは(後日解説予定ですが)C++11で追加された重要機能で引数の「型」を返します。つまり、decltype(nullptr)はnullptrの「型」です。そのまんまですね。(笑)