Files
2024-12-31 19:51:42 -06:00

89 lines
2.6 KiB
C++

#include <format>
#include <iostream>
#include <locale>
#include <print>
#include <source_location>
#include <ranges>
#include <vector>
#include <type_traits>
// *** Log Testing **************************
// This fills temp for some reason.
// Not very fast.
enum class Level {
DEBUG,
INFO,
WARN,
ERROR
};
template <Level L, class ...Args>
struct print {};
template <Level L, class ...Args>
struct print<L, const char *, Args...> {
//print ( const char *msg, Args && ...args, [[maybe_unused]]std::source_location loc = std::source_location::current () ) { // can't use on anything that can't be moved
print ( const char *msg, const Args & ...args, [[maybe_unused]]std::source_location loc = std::source_location::current () ) {
auto type = '?';
if constexpr ( L == Level::DEBUG ) {
type = 'D';
}
else if constexpr ( L == Level::INFO ) {
type = 'I';
}
else if constexpr ( L == Level::WARN ) {
type = 'W';
}
else if constexpr ( L == Level::ERROR ) {
type = 'E';
}
std::println ( "[{}] {}:{} - {}", type, loc.file_name (), loc.line (), std::vformat ( msg, std::make_format_args ( args ... ) ) );
//std::println ( "[{}] {}:{} - {}", type, loc.file_name (), loc.line (), std::vformat ( msg, std::make_format_args ( std::remove_cvref_t<args...> ) ) ); // looks like what i want to fix the move argument, but i don't think it works with pack expansion.
//std::println ( "[{}] {}:{} - {}", type, loc.file_name (), loc.line (), std::vformat ( msg, std::make_format_args ( std::forward<Args> ( args )... ) ) );
}
};
template <Level L, class ... Args>
print ( Args ... ) -> print<L, Args ...>; // deduction guide
template <class ... Args>
using debug = print<Level::DEBUG, Args ...>;
template <class ... Args>
using info = print<Level::INFO, Args ...>;
template <class ... Args>
using warn = print<Level::WARN, Args ...>;
template <class ... Args>
using error = print<Level::ERROR, Args ...>;
// *** Log Testing **************************
struct Vector3 {
uint8_t r;
uint8_t g;
uint8_t b;
};
auto main ( [[maybe_unused]] int, [[maybe_unused]] char ** ) -> int {
std::vector<uint8_t> grayVector ( 1316*480, 128 );
const auto toVector3 = [](const uint8_t &value ) {
return Vector3 { value, value, value };
};
const auto colorSpan = std::span<uint8_t> ( grayVector ) | std::views::transform ( toVector3 );
for ( const auto &v : colorSpan ) {
info ( "{}, {}, {}\n", v.r, v.g, v.b );
}
return 0;
}