Skip to content

Commit 8b86a24

Browse files
authored
declare toml::get_line(std::string_view, source_index) constexpr (#256)
1 parent f3f6258 commit 8b86a24

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

include/toml++/impl/source_region.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ TOML_NAMESPACE_START
237237
/// \returns The specified line, excluding any possible trailing carriage return or line feed character.
238238
/// \remarks Returns an empty string_view when there is no line at the specified line number, in the specified document.
239239
TOML_NODISCARD
240-
inline std::string_view get_line(std::string_view doc, source_index line_num) noexcept
240+
constexpr std::string_view get_line(std::string_view doc, source_index line_num) noexcept
241241
{
242242
if (line_num == 0)
243243
{

tests/user_feedback.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,11 @@ b = []
454454

455455
SECTION("tomlplusplus/issues/254") // https://github.com/marzer/tomlplusplus/issues/254
456456
{
457-
for (const toml::source_index line_num: { 0u, 1u, 2u })
457+
// Check constexpr support.
458+
static_assert(toml::get_line(""sv, 1) == std::string_view{});
459+
static_assert(toml::get_line("alpha = 1\nbeta = 2\n # last line # "sv, 1) == "alpha = 1"sv);
460+
461+
for (const toml::source_index line_num : { 0u, 1u, 2u })
458462
{
459463
CHECK(toml::get_line(""sv, line_num) == std::string_view{});
460464
}

toml.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2636,7 +2636,7 @@ TOML_NAMESPACE_START
26362636
};
26372637

26382638
TOML_NODISCARD
2639-
inline std::string_view get_line(std::string_view doc, source_index line_num) noexcept
2639+
constexpr std::string_view get_line(std::string_view doc, source_index line_num) noexcept
26402640
{
26412641
if (line_num == 0)
26422642
{

0 commit comments

Comments
 (0)