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
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 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 / 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)))
{
@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) ;
@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){
// ...
// 何らかの処理
// ...
@loliGothicK
loliGothicK / FizzBuzz.java
Last active March 1, 2017 19:25
一般的なセミコロンレスJavaのFizzBuzzです
public class FizzBuzz {
public static void main(String[] args){
for(int i : new int[] { 1 }) // define counter
for(int dummy : new int[100])
if( (
(i%15==0) ?
System.out.printf("FIZZBUZZ\n") == null
: (i%3==0) ?
System.out.printf("FIZZ\n") == null
: (i%5==0) ?
@loliGothicK
loliGothicK / strict_week_ordering.hpp
Last active March 13, 2017 16:57
tupleの比較の実装について
bool operator<(const Person& x, const Person& y)
{
return (x.last_name < y.last_name) || !(y.last_name < x.last_name)
&& ( (x.first_name < y.first_name) || !(y.first_name < x.first_name)
&& (x.age < y.age ));
}
@loliGothicK
loliGothicK / tie.hpp
Last active March 13, 2017 17:12
std::tieによる比較
#include <tuple>
#include <string>
struct Person {
std::string first_name;
std::string last_name;
int age;
};
bool operator<(const Person& x, const Person& y)
#include <tuple>
#include <string>
#include <iostream>
#include <iomanip>
class Person {
std::string first_name_;
std::string last_name_;
int age_;
public: