Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- template <typename T, typename Type = std::remove_reference<T>>
- concept is_non_pointer = (std::is_pointer_v<Type> == false);
- template <typename T, typename Type = std::remove_reference<T>>
- concept is_const_pointer = (std::is_pointer_v<Type> && std::is_const_v<Type>);
- template <typename T, typename Type = std::remove_reference<T>>
- concept is_non_const_pointer
- = (std::is_pointer_v<Type> && (std::is_const_v<Type> == false));
- /**
- * @brief General helper, just takes non pointers and forwards them
- */
- template <typename _T>
- requires is_non_pointer<_T>
- auto &&
- quit_helper (_T &&val)
- {
- return std::forward<_T> (val);
- }
- /**
- * @brief Takes a const T* and reinterpret_cast<> to const void*
- * @note This method is for const pointers
- * @returns const T* => const void*
- */
- template <typename _T>
- requires is_const_pointer<_T>
- auto
- quit_helper (_T val)
- {
- static_assert (sizeof (_T) == sizeof (const void *));
- return static_cast<const void *> (std::remove_reference<_T> (val));
- }
- /**
- * @brief Takes a T* and reinterpret_cast<> to void*
- * @note This method is for non-const pointers only.
- * @returns T* => void*
- */
- template <typename _T>
- requires is_non_const_pointer<_T>
- auto
- quit_helper (_T val)
- {
- static_assert (sizeof (_T) == sizeof (void *));
- return static_cast<void *> (val);
- }
- /**
- * @brief prints message according to provided arguments and calls
- * std::exit(1), terminating the application
- * @tparam Args Packed types
- * @param fmt char type specifying how to format
- * @param args packed parameters to format according @p fmt
- */
- template <typename... Args>
- void
- quit (std::string_view fmt, Args &&...args)
- {
- auto m = std::vformat (
- std::string_view{ fmt },
- std::make_format_args (quit_helper (std::forward<Args> (args))...));
- std::cout << m << "\n";
- std::exit (1);
- }
- template <typename... Args>
- void
- quit (std::string &fmt, Args &&...args)
- {
- auto sfmt = std::string_view{ fmt };
- quit (sfmt, std::forward<Args> (args)...);
- }
- template <typename... Args>
- void
- quit (const char *fmt, Args &&...args)
- {
- auto sfmt = std::string_view{ fmt };
- quit (sfmt, std::forward<Args> (args)...);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement