##何これ なんとなく使えそうなコードのまとめ
##一覧
integral_sequence.hpp VS2015のmake_integer_sequenceがファッキンだったので作った
memoization.hppメモ化してくれるアレを作った
plasma.ADTC++でも代数データ型ができる
##何これ なんとなく使えそうなコードのまとめ
##一覧
integral_sequence.hpp VS2015のmake_integer_sequenceがファッキンだったので作った
memoization.hppメモ化してくれるアレを作った
plasma.ADTC++でも代数データ型ができる
#pragma once | |
// Copyright plasma-effect 2015 | |
// Distributed under the Boost Software License, Version 1.0. | |
// (See http://www.boost.org/LICENSE_1_0.txt) | |
#include<type_traits> | |
#include<utility> | |
namespace plasma |
ブログにソースコード貼っつけるよりgistにマークダウンで書いたほうが圧倒的に楽なことに気づいた。
2015年7月20日にVisual Studio 2015がリリースされた。当然VC++も新しくなったわけだがそのうち新しく追加された機能を出来る限り毎日記事にしようと思う。 本日はそのpart01、constexprだ。
constexprはC++11で追加された機能で、現在のC++14では更にパワーアップしているのだが、Microsoftの脳みそが2011年から進んでないのでC++11版のconstexprを紹介する。
コンパイル時において定数式はその場で計算される。定数式とは例えば以下の様なもの。
int main(){
#pragma once | |
#include<type_traits> | |
// Copyright plasma-effect 2015 | |
// Distributed under the Boost Software License, Version 1.0. | |
// (See http://www.boost.org/LICENSE_1_0.txt) | |
namespace plasma | |
{ |
#pragma once | |
// Copyright plasma-effect 2015 | |
// Distributed under the Boost Software License, Version 1.0. | |
// (See http://www.boost.org/LICENSE_1_0.txt) | |
namespace plasma | |
{ | |
namespace polynomial_types | |
{ |
//The MIT License(MIT) | |
// | |
//Copyright(c) 2015 plasma-effect | |
// | |
//Permission is hereby granted, free of charge, to any person obtaining a copy | |
//of this software and associated documentation files(the "Software"), to deal | |
//in the Software without restriction, including without limitation the rights | |
//to use, copy, modify, merge, publish, distribute, sublicense, and / or sell | |
//copies of the Software, and to permit persons to whom the Software is | |
//furnished to do so, subject to the following conditions : |
//problem 1 | |
let rec problem1 n = | |
match n with | |
| 0 -> 0 | |
| i -> if (i%3 = 0)||(i%5 = 0) then i + problem1(n-1) else problem1(i-1) | |
//problem 2 | |
let rec problem2 first second = | |
if first > 4000000 | |
then 0 |
#define CAT(a,b) CAT2(a,b) | |
#define CAT2(a,b) a ## b | |
#define A(a) B a | |
#define B(a) a | |
CAT(x,A((y))) |
template<class,class,class>struct torio; | |
template<class T>struct test; | |
template<class T1,class T2,class T3>struct test<torio<T1,T2,T3>> | |
{ | |
typedef T2 type; | |
}; | |
typedef torio<int,double,char> value_type; |
#include<iostream> | |
template<class T>struct test | |
{ | |
typedef test<T> this_type; | |
T v_; | |
this_type(T v):v_(v){} | |
this_type():v_(T()){} | |
}; |