Compare commits
No commits in common. "70fd273a70450473d37ba6a058e105b5e11dfad5" and "f9cbfdd018ef7e36aeaf3bf4db096e1dc0ef47eb" have entirely different histories.
70fd273a70
...
f9cbfdd018
@ -1,5 +1,5 @@
|
|||||||
cmake_minimum_required(VERSION 3.21)
|
cmake_minimum_required(VERSION 3.21)
|
||||||
project(const_fmt)
|
project(logger)
|
||||||
|
|
||||||
set(CMAKE_CXX_STANDARD 20)
|
set(CMAKE_CXX_STANDARD 20)
|
||||||
|
|
||||||
@ -11,8 +11,14 @@ endif()
|
|||||||
|
|
||||||
include_directories(.)
|
include_directories(.)
|
||||||
|
|
||||||
|
add_executable(logger src/main.cpp)
|
||||||
|
|
||||||
add_subdirectory(examples)
|
|
||||||
|
if(MSVC)
|
||||||
|
target_compile_options(logger PRIVATE /W4 /WX)
|
||||||
|
else()
|
||||||
|
target_compile_options(logger PRIVATE -O3 -Wall -Wextra -pedantic -fno-exceptions)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
|
||||||
option(PACKAGE_TESTS "Build the tests" ON)
|
option(PACKAGE_TESTS "Build the tests" ON)
|
||||||
|
|||||||
52
const_fmt/Logger.h
Normal file
52
const_fmt/Logger.h
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
#ifndef LOGGER_LOGGER_H
|
||||||
|
#define LOGGER_LOGGER_H
|
||||||
|
|
||||||
|
|
||||||
|
#include <array>
|
||||||
|
#include <iostream>
|
||||||
|
#include <tuple>
|
||||||
|
|
||||||
|
#include "format.h"
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* Logger class
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
namespace detail {
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
concept output_policy_c = requires(T t) {
|
||||||
|
t.write('c');
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace detail
|
||||||
|
|
||||||
|
|
||||||
|
template <detail::output_policy_c output_policy_t>
|
||||||
|
class Logger {
|
||||||
|
|
||||||
|
public:
|
||||||
|
Logger(output_policy_t output_policy) : m_output_policy(output_policy) {
|
||||||
|
}
|
||||||
|
|
||||||
|
template <detail::ConstString msg, typename... args_t>
|
||||||
|
void log(args_t... args) {
|
||||||
|
const auto formatted_msg = format<msg>(args...);
|
||||||
|
|
||||||
|
for (const auto& c : formatted_msg) {
|
||||||
|
m_output_policy.write(c);
|
||||||
|
}
|
||||||
|
|
||||||
|
m_output_policy.write('\n');
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
output_policy_t& m_output_policy;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif // LOGGER_LOGGER_H
|
||||||
@ -1,7 +0,0 @@
|
|||||||
add_executable(const_fmt_example src/examples.cpp)
|
|
||||||
|
|
||||||
if(MSVC)
|
|
||||||
target_compile_options(const_fmt_example PRIVATE /W4 /WX)
|
|
||||||
else()
|
|
||||||
target_compile_options(const_fmt_example PRIVATE -O3 -Wall -Wextra -pedantic -fno-exceptions)
|
|
||||||
endif()
|
|
||||||
@ -1,8 +0,0 @@
|
|||||||
#include <const_fmt/format.h>
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
int main() {
|
|
||||||
// TODO
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
13
src/main.cpp
Normal file
13
src/main.cpp
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
#include <const_fmt/Logger.h>
|
||||||
|
|
||||||
|
|
||||||
|
int main(int argc, char* argv[]) {
|
||||||
|
auto formatted = "Test: {:12} {:012.5} {:8}"_fmt(argv[0], 123.45, -1234567);
|
||||||
|
|
||||||
|
for (const auto& c : formatted)
|
||||||
|
std::cout << c;
|
||||||
|
std::cout << std::endl;
|
||||||
|
|
||||||
|
// return formatted[6];
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@ -14,15 +14,8 @@ macro(package_add_test TESTNAME)
|
|||||||
PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY "${PROJECT_DIR}"
|
PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY "${PROJECT_DIR}"
|
||||||
)
|
)
|
||||||
set_target_properties(${TESTNAME} PROPERTIES FOLDER tests)
|
set_target_properties(${TESTNAME} PROPERTIES FOLDER tests)
|
||||||
|
|
||||||
if(MSVC)
|
|
||||||
target_compile_options(${TESTNAME} PRIVATE /W4 /WX)
|
|
||||||
else()
|
|
||||||
target_compile_options(${TESTNAME} PRIVATE -O3 -Wall -Wextra -pedantic -fno-exceptions)
|
|
||||||
endif()
|
|
||||||
endmacro()
|
endmacro()
|
||||||
|
|
||||||
|
|
||||||
package_add_test(utility_test src/utility.cpp)
|
package_add_test(utility_test src/utility.cpp)
|
||||||
package_add_test(parse_test src/parse.cpp)
|
package_add_test(parse_test src/parse.cpp)
|
||||||
package_add_test(format_test src/format.cpp)
|
package_add_test(format_test src/format.cpp)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user