declare toml::get_line(std::string_view, source_index) constexpr (#256)

This commit is contained in:
Niels Dekker
2025-02-26 10:47:47 +01:00
committed by GitHub
parent f3f625819a
commit 8b86a2490c
3 changed files with 7 additions and 3 deletions

View File

@@ -237,7 +237,7 @@ TOML_NAMESPACE_START
/// \returns The specified line, excluding any possible trailing carriage return or line feed character.
/// \remarks Returns an empty string_view when there is no line at the specified line number, in the specified document.
TOML_NODISCARD
inline std::string_view get_line(std::string_view doc, source_index line_num) noexcept
constexpr std::string_view get_line(std::string_view doc, source_index line_num) noexcept
{
if (line_num == 0)
{

View File

@@ -454,7 +454,11 @@ b = []
SECTION("tomlplusplus/issues/254") // https://github.com/marzer/tomlplusplus/issues/254
{
for (const toml::source_index line_num: { 0u, 1u, 2u })
// Check constexpr support.
static_assert(toml::get_line(""sv, 1) == std::string_view{});
static_assert(toml::get_line("alpha = 1\nbeta = 2\n # last line # "sv, 1) == "alpha = 1"sv);
for (const toml::source_index line_num : { 0u, 1u, 2u })
{
CHECK(toml::get_line(""sv, line_num) == std::string_view{});
}

View File

@@ -2636,7 +2636,7 @@ TOML_NAMESPACE_START
};
TOML_NODISCARD
inline std::string_view get_line(std::string_view doc, source_index line_num) noexcept
constexpr std::string_view get_line(std::string_view doc, source_index line_num) noexcept
{
if (line_num == 0)
{