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
| // Merge using same set of arguments for construction | |
| template <class... Ts> | |
| struct overload : Ts... { | |
| template <class... Args> | |
| overload(Args&&... args) : Ts{ std::forward<Args>(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
| template <class... Args> | |
| auto make_reversed_tuple(Args&&... args) { | |
| return []<class T, size_t... I>(T&& t, std::index_sequence<I...>) { | |
| return std::forward_as_tuple(std::get<sizeof...(I)-1-I>(std::forward<T>(t))...); | |
| } | |
| (std::forward_as_tuple(std::forward<Args>(args)...), std::index_sequence_for<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
| template <class T, class Type, class T1, class... Args> | |
| decltype(auto) reversed_invoke(Type T::* f, T1&& t1, Args&&... args) | |
| { | |
| return [f]<class Tup, size_t... I>(T1&& arg, Tup&& t, std::index_sequence<I...>) { | |
| return std::invoke(f, std::forward<T1>(arg), | |
| std::get<sizeof...(I)-1-I>(std::forward<Tup>(t))...); | |
| } | |
| (std::forward<T1>(t1), | |
| std::forward_as_tuple(std::forward<Args>(args)...), | |
| std::index_sequence_for<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
| // Unreference tuple for raw memory copy. | |
| // Primary template for non referenced elements. | |
| template <class T, class = void> | |
| struct tuple_unref { | |
| tuple_unref(T& t) noexcept : value(t) { } | |
| T& value; | |
| }; | |
| // A specialization for tuple containing | |
| // at least one reference 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
| #pragma once | |
| #include <tuple> | |
| // Conditionally select argument. | |
| // On true return argument packed in std::tuple. | |
| template <bool> | |
| struct zero_or_one { | |
| template <class T> static std::tuple<T&&> get(T&& t) { | |
| return std::forward<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 <sstream> | |
| struct stream_exception : std::exception | |
| { | |
| using std::exception::exception; | |
| template <class T> | |
| stream_exception& operator<<(const T& arg) { | |
| std::ostringstream oss; | |
| oss << arg; |
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
| // Usage: | |
| // void fn(const string_type& str) { | |
| // std::cout << str << '\n'; | |
| // } | |
| struct string_type : std::string_view | |
| { | |
| // Takes const char*, std::string, std::string_view | |
| template <class T, class = std::enable_if_t< | |
| std::is_constructible_v<std::string_view, const 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
| #pragma once | |
| template <class> | |
| struct function; | |
| template <class R, class... Args> | |
| struct function<R(Args...)> { | |
| private: | |
| template <class F> | |
| static R call_impl(void* fn, Args&&... 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
| // Extract function argument types | |
| #pragma once | |
| #include <type_traits> | |
| // std::void_t since C++17 | |
| template <class...> using void_t = void; | |
| // Primary template | |
| template <class F, class = void> |
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 <variant> | |
| #include <map> | |
| struct diagram { | |
| diagram() { std::cout << "diagram constructed\n"; } | |
| }; | |
| struct unit { | |
| unit() { std::cout << "unit constructed\n"; } |
OlderNewer