Skip to content

Instantly share code, notes, and snippets.

View marionette-of-u's full-sized avatar

arithmeticae marionette-of-u

View GitHub Profile
@marionette-of-u
marionette-of-u / str_wrapper.cpp
Created June 8, 2013 10:10
std::mapにstd::stringの実体を持つ、比較が軽量な文字列型。
// str_wrapper
class str_wrapper{
public:
inline str_wrapper() : ptr(nullptr){}
inline str_wrapper(const std::string &str) : ptr(get_ptr(str)){}
inline str_wrapper(const char *str) : ptr(get_ptr(str)){}
inline str_wrapper &operator =(const std::string &other){
ptr = get_ptr(other);
return *this;
struct str_wrapper_less : public std::binary_function<str_wrapper, str_wrapper, bool>{
inline bool operator ()(const str_wrapper &lhs, const str_wrapper &rhs) const{
return *lhs.ptr < *rhs.ptr;
}
};
// x_prime^(num / den) = a in N
// OR
// x_prime
#include <cmath>
#include <cstdint>
std::int64_t factorize_nd(std::int64_t x_prime, std::int64_t num, std::int64_t den){
std::int64_t x = x_prime;
std::int64_t t = 0, u = 1, tt = 0;
#include <typeindex>
template<class T>
constexpr std::size_t get(){
return std::type_index(typeid(T)).hash_code();
}
class a{};
class b{};
class c{};
#include <cstdint>
template<typename T>
constexpr std::uint64_t get(){
struct dummy_struct{
static void f(){}
};
return reinterpret_cast<std::uint64_t>(dummy_struct::f);
}
#include <cstdint>
template<typename T>
constexpr std::uint64_t get(){
return reinterpret_cast<std::uint64_t>(&get<T>);
}
class a{};
class b{};
class c{};
/*
main.cpp:15:26: error: constexpr variable 'id_a' must be initialized by a
constant expression
constexpr std::uint64_t id_a = get<a>(), id_b = get<b>(), id_c ...
^ ~~~~~~~~
main.cpp:5:9: note: reinterpret_cast is not allowed in a constant expression
return reinterpret_cast<std::uint64_t>(&get<T>);
^
main.cpp:15:33: note: in call to 'get()'
constexpr std::uint64_t id_a = get<a>(), id_b = get<b>(), id_c ...
au FileType cpp,cc,cxx,h,hpp,hxx call <SID>KatatsumuriCompleteInit()
autocmd FileType cpp,cc,cxx,h,hpp,hxx setlocal completefunc=KatatsumuriComplete
autocmd FileType cpp,cc,cxx,h,hpp,hxx setlocal omnifunc=KatatsumuriComplete
let s:katatsumuri_complete_list = []
function! s:KatatsumuriCompleteInit()
if !exists('g:katatsumuri_complete_binary')
let g:katatsumuri_complete_binary = 'katatsumuri_complete'
<token_desc> token{
<right>{ unary_minus; }
<left>{
ast, sla;
pls, mns;
}
l_paren, r_paren;
id<int>;
}
-- Valueの型はDSLに入力するファイルに記入されている
-- ここでは単純化のためにInt
type Value = Int
defaultValue = 0
-- DSLから自動生成されたデータコンストラクタ
data Token = End | UMns | Ast | Sla | Pls | Mns | LParen | RParen | Id
deriving (Enum, Eq, Ord)
data StackFrame = StackFrame {