diff --git a/CMakeLists.txt b/CMakeLists.txt index 57c4e7e..34f9df5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -168,8 +168,8 @@ endif() -add_executable(exe EXCLUDE_FROM_ALL main.cpp) -target_link_libraries(exe PUBLIC ${PROJECT_NAME}) +# add_executable(exe EXCLUDE_FROM_ALL main.cpp) +# target_link_libraries(exe PUBLIC ${PROJECT_NAME}) # get_target_property(ZZ exe INCLUDE_DIRECTORIES) diff --git a/mcc_serializer.h b/mcc_serializer.h new file mode 100644 index 0000000..5f2fc8b --- /dev/null +++ b/mcc_serializer.h @@ -0,0 +1,77 @@ +#pragma once + +#include + +#include "mcc_concepts.h" +#include "mcc_traits.h" + +namespace mcc +{ + + +struct mcc_serializer_interface_t { + virtual ~mcc_serializer_interface_t() = default; + + template SelfT, traits::mcc_output_char_range R, typename ValueT> + mcc_error_c auto operator()(this SelfT&& self, R& output, ValueT&& value) + { + return std::forward(self).operator=(output, std::forward(value)); + } +}; + +template +concept mcc_serializer_c = std::derived_from; + + +template +class MccSerializer : public mcc_serializer_interface_t +{ +public: + static constexpr std::string_view defaultDelimiter{","}; + + typedef std::error_code error_t; + + MccSerializer() = default; + + ~MccSerializer() = default; + + error_t operator()(traits::mcc_output_char_range auto& output, VT&& value) + requires std::formattable + { + std::format_to(std::back_inserter(output), "{}", value); + + return {}; + } + +protected: + std::string _delimiter{defaultDelimiter}; +}; + + + +template +class MccSerializer : public mcc_serializer_interface_t +{ +public: + error_t operator()(traits::mcc_output_char_range auto& output, T&& value) + { + std::format_to(std::back_inserter(output), "{}", value.degrees()); + + return {}; + } +}; + + +static_assert(mcc_serializer_c>, "!!!"); + +static_assert(mcc_serializer_c>, "!!!"); + +void f() +{ + MccSerializer s; + + std::string str; + s(str, impl::MccAngleALT{1.1}); +} + +} // namespace mcc