Skip to content

Instantly share code, notes, and snippets.

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

Mitama loliGothicK

:octocat:
may the --force-with-lease be with you!
View GitHub Profile
int main(){
constexpr int add_one(int n){
// nがコンパイル時定数ならラムダ式をconstexprの文脈で使える
return [n]{ return n + 1; }();
}
static_assert( add_one(1) == 2 );
}
using namespace std::execution; // 実行ポリシーが定義された名前空間
std::vector<int> v = { /* ... */ };
std::sort(v.begin(), v.end()); // これまでと同じ
std::sort(seq, v.begin(), v.end()); // 明示的にシーケンシャルを指定
std::sort(par, v.begin(), v.end()); // 並列実行を許可するオーバーロード
std::sort(par_unseq, v.begin(), v.end()); // 並列and/orベクトル実行を許可するオーバーロード
#include <type_traits>
#include <utility>
#include <iterator>
template < class Range >
func(Range&& range)
-> std::enable_if<decltype(std::begin(std::declval<typename std::decay<Range>::type>()) + 2, std::true_type{})>
{
// Rangeはランダムラクセスイテレータを持つコンテナなので
// ランダムラクセスするアルゴリズムを記述できる
#include <type_traits>
#include <utility>
#include <iterator>
template < class Range >
typename std::enable_if<
std::is_same<
typename std::iterator_traits<typename std::decay<Range>::type>::iterator_category,
std::random_access_iterator_tag
>::value
#include <type_traits>
#include <utility>
template < class T >
using always_false_type = std::false_type;
template < class T, class = void >
class Hoge
{
static_assert( always_false_type<T>::value, "T must be integral type!" );
#include <type_trits>
#include <utility>
template < class T >
typename std::enable_if< std::is_integral<T>::value, T >::type
twice(T&& t){
return t + t;
}
// for C++03 scoped enum emulation
class WeekDay
{
typedef enum { Mon_, Tue_, Wed_, Thu_, Fri_, Sat_, Sun_ } WeekDay_;
WeekDay_ value_;
public:
static const WeekDay Mon, Tue, Wed, Thu, Fri, Sat, Sun;
explicit config(const config_& value) : value_(value) {}
};
enum class WeekDay {
Mon,
Tue,
Wed,
Thu,
Fri,
Sat,
Sun,
};
# From http://apt.llvm.org/
sudo apt upgrade -y
sudo apt update -y
# Install Build Dependency:
apt install software-properties-common -y
# Add GPG Key
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
# For Ubuntu 17.10 Artful Aardvark
# Please replace own Ubuntu code name
#include <iostream>
#include <functional>
template < class T >
struct Class {
T value ;
void func(T t) { std::cout << value << ":" << t << " => " << __PRETTY_FUNCTION__ << std::endl; }
};
template < class T >