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
| template<class T, typename... Ts> | |
| using type_t = T; | |
| // Alternative implementation for compilers before | |
| // [CWG 1558](http://open-std.org/JTC1/SC22/WG21/docs/cwg_defects.html#1558) | |
| // template<class T, typename... Ts> struct type_t_impl { typedef T type;}; | |
| // template<class T, typename... Ts> using type_t = typename type_t_impl<T, Ts...>::type; | |
| // Usage example: |
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
| // N4317 "New Safer Functions to Advance Iterators" paper can be found at | |
| // http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4317.pdf | |
| namespace detail { | |
| template<class InputIter> | |
| inline void do_advance(InputIter& it, InputIter end, typename std::iterator_traits<InputIter>::difference_type n, std::input_iterator_tag) | |
| { | |
| assert(n >= 0); | |
| for (; (n > 0) && (it != end); --n) | |
| ++it; |
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
| """ | |
| Extra LLDB Formatters | |
| Contains formatters for: | |
| - `llvm::SmallVector` - https://llvm.org/doxygen/classllvm_1_1SmallVector.html | |
| - `boost::container::flat_map` - https://www.boost.org/doc/libs/1_69_0/doc/html/boost/container/flat_map.html | |
| - `boost::optional` - https://www.boost.org/doc/libs/1_69_0/libs/optional/doc/html/index.html | |
| - `mpark::variant` - https://github.com/mpark/variant | |
| Load into LLDB with `command script import /path/to/extra-formatters.py` |
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
| // version 1.0 | |
| template<class T, class D> | |
| inline auto make_handle(T* p, D&& d) noexcept(std::is_nothrow_constructible<typename std::decay<D>::type, D&&>::value) | |
| -> std::unique_ptr<T, typename std::decay<D>::type> | |
| { | |
| return {p, std::forward<D>(d)}; | |
| } | |
| auto h1 = make_handle(fopen("test", "r"), fclose); | |
| auto h2 = make_handle(dlopen("bla"), dlclose); |
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
| std::string wstr_to_utf8(boost::wstring_view); | |
| namespace detail { | |
| template<class T, class = void> | |
| struct narrow_impl | |
| { | |
| template<class U> | |
| static U&& invoke(U&& s) noexcept | |
| { | |
| static_assert(std::is_same<T, U&&>::value, "error"); |
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
| alias pretty-json="python -c 'import json; import sys; json.dump(json.load(open(sys.argv[1], \"r\") if len(sys.argv) > 1 else sys.stdin), sys.stdout, indent=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
| #include <type_traits> | |
| #include <utility> | |
| struct Bar {}; | |
| // Note about `is_convertible<T&&, Foo>`. `T&&` is essential there! | |
| struct Foo | |
| { | |
| template<class T, class = typename std::enable_if<!std::is_convertible<T&&, Foo>::value>::type> | |
| Foo(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
| ///////////////////////////////////////////// | |
| // parser.h | |
| #include <memory> | |
| template<class T> | |
| struct delegating_delete { | |
| inline void operator() (T *p) const noexcept { do_delete(p); } | |
| }; | |
| namespace parser { |
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
| // A compilation of the following posts: | |
| // http://stackoverflow.com/questions/18648069/g-doesnt-compile-constexpr-function-with-assert-in-it | |
| // http://ericniebler.com/2014/09/27/assert-and-constexpr-in-cxx11/ | |
| #include <cassert> | |
| #include <utility> | |
| template<class Assert> | |
| inline void constexpr_assert_failed(Assert&& a) noexcept { std::forward<Assert>(a)(); } | |
| // When evaluated at compile time emits a compilation error if condition is not true. |
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 <chrono> | |
| #include <type_traits> | |
| // Floating seconds duration | |
| using fseconds = std::chrono::duration<double>; | |
| class PerfTimer | |
| { | |
| public: | |
| using clock = std::conditional< |