Skip to content

Instantly share code, notes, and snippets.

View loliGothicK's full-sized avatar
:octocat:
may the --force be with you!

Mitama loliGothicK

:octocat:
may the --force be with you!
View GitHub Profile
@loliGothicK
loliGothicK / file0.cpp
Last active August 2, 2016 07:41
C++関数テンプレートと半順序とオーバーロード ref: http://qiita.com/_EnumHack/items/cd904d383588ddb2189f
template < typename T >
T max(T a, T b) ;
namespace A
{
void f(){std::cout << "A" << std::endl;};
void hoge(){
f(); // 名前空間の中では修飾しなくても呼び出せる
}
}
namespace B
{
@loliGothicK
loliGothicK / file0.cpp
Created December 24, 2015 16:26
テンプレートが手招きしているよ ref: http://qiita.com/_EnumHack/items/d29eaf2013f753bf8e99
int max( int a, int b ) // #1
{
return a < b ? b : a ;
}
double max( double a, double b ) // #2
{
return a < b ? b : a ;
}
@loliGothicK
loliGothicK / file0.cpp
Created December 29, 2015 09:50
Cranberries Interval Library Ver. 3.0.0 Release Note ref: http://qiita.com/_EnumHack/items/821c4bc9031a1e9a82b3
template < typename T >
constexpr T interval<T>::rad() const
{
return pimpl->upper() - pimpl->lower() / static_cast<T>(2.0L);
}
template < typename T >
constexpr T interval<T>::norm() const
{
using std::abs;
@loliGothicK
loliGothicK / file0.cpp
Last active February 11, 2016 12:13
decltypeとSFINAEによるオーバーロード条件分岐 ref: http://qiita.com/_EnumHack/items/e831a359338e5f134325
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
template < typename Container >
auto my_find(Container& c, typename Container::key_type key)
->decltype((c.find(key)))
{
std::is_same<T,U>::value
@loliGothicK
loliGothicK / file0.cpp
Last active January 28, 2016 20:05
テンプレートの推論された型をお手軽確認 ref: http://qiita.com/_EnumHack/items/7c8556ab6ddba3a785f8
template < typename T >
void f(T&&){}
void g(int const&){};
int main(){
f(g);
}
@loliGothicK
loliGothicK / variadic_arg_bind.cpp
Created November 7, 2016 07:26
可変長引数を関数オブジェクトにバインドして後から指定した関数に渡す感じのやーつ
#include <iostream>
#include <functional>
#include <vector>
#include <initializer_list>
#include <utility>
#include <tuple>
#include <memory>
namespace cranberries {
@loliGothicK
loliGothicK / file0.txt
Last active September 8, 2017 20:49
C++の乱数ライブラリが使いにくい話 ref: http://qiita.com/_EnumHack/items/25fc998873d1bc7d2276
std::random_device rd{};
std::cout << rd() << std::endl;
@loliGothicK
loliGothicK / file0.cpp
Last active February 18, 2017 18:07
C++の間違った知識に振り回されないために ref: http://qiita.com/_EnumHack/items/ced694a5629d1b2210b7
// 変数がいっぱいある
int a{}, b{}, c{};
double d{}, e{}, f{};
std::string too_long_name_variable{};
// ラムダ式
auto result = [&a,&b,&c,&d,&e,&f,&too_long_name_variable](auto&& ...args){
// ...
// 何らかの処理
// ...