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 <cstring> | |
| #include <stack> | |
| uint8_t precedence[256]; | |
| bool HasHigherPrecedence(char a, char b) { | |
| return precedence[(uint8_t)a] < precedence[(uint8_t)b]; | |
| } |
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 <utility> | |
| #include <tuple> | |
| namespace detail { | |
| template<class... Args> | |
| struct stream_bump { | |
| std::tuple<Args...> args; | |
| template<class F> | |
| void operator->*(F&& f) && { |
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 <utility> | |
| template<class T> struct TD; | |
| template<class T> void f(T&& x) { TD<decltype(x)>(); } | |
| // T & = T& | |
| // T && = T&& | |
| // T& & = T& | |
| // 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
| #include <iostream> | |
| #include <sstream> | |
| #include <algorithm> | |
| template<class charT> | |
| struct word_inserter_impl { | |
| word_inserter_impl(int words, std::basic_string<charT>& str, charT delim) | |
| : str_(str) | |
| , delim_(delim) | |
| , words_(words) |
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 <string> | |
| #include <iostream> | |
| #include <initializer_list> | |
| enum struct Color { | |
| red,blue,orange,purple,green,black,yellow,invalid=-1 | |
| }; | |
| Color FromStringToColor(std::string const& str) { | |
| return ((str == "red") ? Color::red : |
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 <string> | |
| #include <cctype> | |
| #include <cassert> | |
| namespace detail { | |
| bool isMatchingPair(char c1, char c2) { | |
| return std::isupper(c1) && std::tolower(c1) == c2; | |
| } | |
| } |
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 <string> | |
| #include <algorithm> | |
| #include <map> | |
| #include <cassert> | |
| namespace detail { | |
| std::map<char, unsigned int> numerals = { {'I', 1}, {'E', 3}, {'V', 5}, {'X', 10}, {'L', 50} }; | |
| unsigned int numeral_rank(char c) { | |
| return numerals[c]; |
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 <utility> | |
| #include <tuple> | |
| #include <cassert> | |
| struct type_erasure { }; | |
| template<class T> | |
| struct wrapper : type_erasure { | |
| wrapper(T&& w) : w_(std::forward<T>(w)) { } | |
| T&& w_; |
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 <bitset> | |
| #include <vector> | |
| #include <algorithm> | |
| template<class T> | |
| T Rotate(T i) { | |
| return (i << 1) | (i >> sizeof(i)); | |
| //return ((i & (1 << (sizeof(T) - 1)) >> sizeof(T)) | (i << 1)); | |
| } |
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 <cstring> | |
| #define TO_STRING_FOR_CLASS(X)\ | |
| template<class T>\ | |
| const char* ToString();\ | |
| \ | |
| template<>\ | |
| const char* ToString<X>() {\ | |
| static const char* str = #X;\ |