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
| #pragma once | |
| #include <string> | |
| namespace ard | |
| { | |
| namespace detail | |
| { | |
| // Type to format mapping | |
| template <class T> constexpr nullptr_t type_fmt {}; | |
| using fmt_t = const char[]; |
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> | |
| template <class T> struct overload : T { using T::operator(); }; | |
| template <class T> overload(T) -> overload<T>; | |
| int main() | |
| { | |
| auto f = [x = 1, y = 2]() { return x + y; }; | |
| // auto [a, b] = f; // error: cannot decompose lambda closure type 'main()::<lambda()>' |
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> | |
| template <class F> | |
| struct waterfall | |
| { | |
| waterfall(F&& f) | |
| : fn(std::forward<F>(f)) | |
| {} | |
| template <class... Args> |
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 <tuple> | |
| #include <string> | |
| template <class> | |
| struct is_tuple : std::false_type | |
| { }; | |
| template <class... T> | |
| struct is_tuple<std::tuple<T...>> : std::true_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 <iostream> | |
| #include <string_view> | |
| template <class T> | |
| constexpr std::string_view typeid_name(const T&) | |
| { | |
| std::string_view sv = __PRETTY_FUNCTION__; | |
| sv.remove_prefix(sv.find('=') + 2); | |
| return { sv.data(), sv.find(';') }; |
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_view> | |
| struct header | |
| { | |
| header* prev; | |
| std::string_view name; | |
| std::string_view value; | |
| header(header* other = nullptr) noexcept |
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 <vector> | |
| #include <memory> | |
| #include <cassert> | |
| template <class T> | |
| void draw(const T& x, std::ostream& out, size_t position) | |
| { | |
| out << std::string(position, ' ') << x << std::endl; |
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> | |
| // | |
| // Lambda without captures is convertible to function pointer. | |
| // For a definition like this: | |
| // | |
| // void some_c_func(void (*callback)()); | |
| // | |
| // We can just pass lambda to above function without captures. | |
| // |
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 <tuple> | |
| // Compile with | |
| // time g++ -std=c++17 -ftemplate-depth=1100 reduce_compile_time.cpp | |
| // Note! -ftemplate-depth=1100 needed only if USE_TYPELIST not defined. | |
| // There are four different methods to select type from a type list | |
| // by run-time 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 <iostream> | |
| #include <utility> | |
| template <size_t I, class F> | |
| inline auto ct_value(F&& f) | |
| { | |
| return std::forward<F>(f)(std::integral_constant<size_t, I>()); | |
| } | |
| template <class F, size_t... I> |