diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 1344b71f..70b6892a 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -88,6 +88,7 @@ if(NOT ${projectPrefix}API_FREESTANDING) BASE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/include FILES + include/mp-units/bits/constexpr_format.h include/mp-units/bits/fmt.h include/mp-units/bits/format.h include/mp-units/bits/ostream.h diff --git a/src/core/include/mp-units/bits/constexpr_format.h b/src/core/include/mp-units/bits/constexpr_format.h new file mode 100644 index 00000000..7265daba --- /dev/null +++ b/src/core/include/mp-units/bits/constexpr_format.h @@ -0,0 +1,49 @@ +// The MIT License (MIT) +// +// Copyright (c) 2018 Mateusz Pusz +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +#pragma once + +#include // IWYU pragma: keep + +#ifndef MP_UNITS_IN_MODULE_INTERFACE +#include +#ifdef MP_UNITS_IMPORT_STD +import std; +#else +#include +#endif +#endif + +namespace mp_units::detail { + +[[nodiscard]] consteval std::string constexpr_format([[maybe_unused]] auto fmt, [[maybe_unused]] auto&&... args) +{ + std::string text; +#if MP_UNITS_USE_FMTLIB + fmt::format_to(std::back_inserter(text), fmt, std::forward(args)...); +#else + static_assert(false, "`std::format` is not `constexpr` yet"); +#endif + return text; +}; + +} // namespace mp_units::detail diff --git a/src/core/include/mp-units/ext/format.h b/src/core/include/mp-units/ext/format.h index 5d8c1fd2..4bcc0b3b 100644 --- a/src/core/include/mp-units/ext/format.h +++ b/src/core/include/mp-units/ext/format.h @@ -33,6 +33,7 @@ MP_UNITS_DIAGNOSTIC_PUSH MP_UNITS_DIAGNOSTIC_IGNORE_UNREACHABLE MP_UNITS_DIAGNOSTIC_IGNORE_SHADOW +#include #include MP_UNITS_DIAGNOSTIC_POP #else // MP_UNITS_USE_FMTLIB