This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| int main(){ | |
| constexpr int add_one(int n){ | |
| // nがコンパイル時定数ならラムダ式をconstexprの文脈で使える | |
| return [n]{ return n + 1; }(); | |
| } | |
| static_assert( add_one(1) == 2 ); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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ベクトル実行を許可するオーバーロード |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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はランダムラクセスイテレータを持つコンテナなので | |
| // ランダムラクセスするアルゴリズムを記述できる |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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!" ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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) {} | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| enum class WeekDay { | |
| Mon, | |
| Tue, | |
| Wed, | |
| Thu, | |
| Fri, | |
| Sat, | |
| Sun, | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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 > |