mirror of
https://github.com/marzer/tomlplusplus.git
synced 2026-02-22 16:02:12 +00:00
fixed compilation on older implementations without std::launder
also: - fixed `json_formatter` type deduction on older compilers - added build configuration option for compiling examples
This commit is contained in:
@@ -82,6 +82,7 @@
|
||||
#undef TOML_IMPLEMENTATION
|
||||
#undef TOML_INLINE_FUNC_IMPL
|
||||
#undef TOML_COMPILER_EXCEPTIONS
|
||||
#undef TOML_LAUNDER
|
||||
#endif
|
||||
|
||||
/// \mainpage toml++
|
||||
|
||||
@@ -318,6 +318,9 @@
|
||||
TOML_PUSH_WARNINGS
|
||||
TOML_DISABLE_ALL_WARNINGS
|
||||
|
||||
#if __has_include(<version>)
|
||||
#include <version>
|
||||
#endif
|
||||
#include <cstdint>
|
||||
#include <cstring> //memcpy, memset
|
||||
#include <memory>
|
||||
@@ -350,6 +353,12 @@ TOML_POP_WARNINGS
|
||||
#define TOML_STRING_PREFIX(S) S
|
||||
#endif
|
||||
|
||||
#ifdef __cpp_lib_launder
|
||||
#define TOML_LAUNDER(x) std::launder(x)
|
||||
#else
|
||||
#define TOML_LAUNDER(x) x
|
||||
#endif
|
||||
|
||||
////////// FORWARD DECLARATIONS & TYPEDEFS
|
||||
// clang-format on
|
||||
|
||||
|
||||
@@ -459,6 +459,10 @@ TOML_START
|
||||
friend std::basic_ostream<T>& operator << (std::basic_ostream<T>&, default_formatter<U>&&) TOML_MAY_THROW;
|
||||
};
|
||||
|
||||
default_formatter(const table&) -> default_formatter<char>;
|
||||
default_formatter(const array&) -> default_formatter<char>;
|
||||
template <typename T> default_formatter(const value<T>&) -> default_formatter<char>;
|
||||
|
||||
template <typename CHAR>
|
||||
inline void default_formatter<CHAR>::print_inline(const toml::table& tbl) TOML_MAY_THROW
|
||||
{
|
||||
|
||||
@@ -103,10 +103,8 @@ TOML_START
|
||||
/// \param source The source TOML object.
|
||||
/// \param flags Format option flags.
|
||||
TOML_NODISCARD_CTOR
|
||||
explicit json_formatter(
|
||||
const toml::node& source,
|
||||
format_flags flags = format_flags::quote_dates_and_times) noexcept
|
||||
: base{ source, flags }
|
||||
explicit json_formatter(const toml::node& source, format_flags flags = {}) noexcept
|
||||
: base{ source, flags | format_flags::quote_dates_and_times }
|
||||
{}
|
||||
|
||||
template <typename T, typename U>
|
||||
@@ -115,6 +113,10 @@ TOML_START
|
||||
friend std::basic_ostream<T>& operator << (std::basic_ostream<T>&, json_formatter<U>&&) TOML_MAY_THROW;
|
||||
};
|
||||
|
||||
json_formatter(const table&) -> json_formatter<char>;
|
||||
json_formatter(const array&) -> json_formatter<char>;
|
||||
template <typename T> json_formatter(const value<T>&) -> json_formatter<char>;
|
||||
|
||||
template <typename CHAR>
|
||||
inline void json_formatter<CHAR>::print(const toml::table& tbl) TOML_MAY_THROW
|
||||
{
|
||||
|
||||
@@ -52,9 +52,9 @@ TOML_START
|
||||
void destroy() noexcept
|
||||
{
|
||||
if (is_err)
|
||||
std::launder(reinterpret_cast<parse_error*>(&storage))->~parse_error();
|
||||
TOML_LAUNDER(reinterpret_cast<parse_error*>(&storage))->~parse_error();
|
||||
else
|
||||
std::launder(reinterpret_cast<table*>(&storage))->~table();
|
||||
TOML_LAUNDER(reinterpret_cast<table*>(&storage))->~table();
|
||||
}
|
||||
|
||||
public:
|
||||
@@ -70,38 +70,38 @@ TOML_START
|
||||
[[nodiscard]] table& get() & noexcept
|
||||
{
|
||||
TOML_ASSERT(!is_err);
|
||||
return *std::launder(reinterpret_cast<table*>(&storage));
|
||||
return *TOML_LAUNDER(reinterpret_cast<table*>(&storage));
|
||||
}
|
||||
/// \brief Returns the internal toml::table (rvalue overload).
|
||||
[[nodiscard]] table&& get() && noexcept
|
||||
{
|
||||
TOML_ASSERT(!is_err);
|
||||
return std::move(*std::launder(reinterpret_cast<table*>(&storage)));
|
||||
return std::move(*TOML_LAUNDER(reinterpret_cast<table*>(&storage)));
|
||||
}
|
||||
/// \brief Returns the internal toml::table (const lvalue overload).
|
||||
[[nodiscard]] const table& get() const& noexcept
|
||||
{
|
||||
TOML_ASSERT(!is_err);
|
||||
return *std::launder(reinterpret_cast<const table*>(&storage));
|
||||
return *TOML_LAUNDER(reinterpret_cast<const table*>(&storage));
|
||||
}
|
||||
|
||||
/// \brief Returns the internal toml::parse_error.
|
||||
[[nodiscard]] parse_error& error() & noexcept
|
||||
{
|
||||
TOML_ASSERT(is_err);
|
||||
return *std::launder(reinterpret_cast<parse_error*>(&storage));
|
||||
return *TOML_LAUNDER(reinterpret_cast<parse_error*>(&storage));
|
||||
}
|
||||
/// \brief Returns the internal toml::parse_error (rvalue overload).
|
||||
[[nodiscard]] parse_error&& error() && noexcept
|
||||
{
|
||||
TOML_ASSERT(is_err);
|
||||
return std::move(*std::launder(reinterpret_cast<parse_error*>(&storage)));
|
||||
return std::move(*TOML_LAUNDER(reinterpret_cast<parse_error*>(&storage)));
|
||||
}
|
||||
/// \brief Returns the internal toml::parse_error (const lvalue overload).
|
||||
[[nodiscard]] const parse_error& error() const& noexcept
|
||||
{
|
||||
TOML_ASSERT(is_err);
|
||||
return *std::launder(reinterpret_cast<const parse_error*>(&storage));
|
||||
return *TOML_LAUNDER(reinterpret_cast<const parse_error*>(&storage));
|
||||
}
|
||||
|
||||
/// \brief Returns the internal toml::table.
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
#pragma once
|
||||
|
||||
#define TOML_LIB_MAJOR 0
|
||||
#define TOML_LIB_MINOR 4
|
||||
#define TOML_LIB_PATCH 4
|
||||
#define TOML_LIB_MINOR 5
|
||||
#define TOML_LIB_PATCH 0
|
||||
|
||||
#define TOML_LANG_MAJOR 0
|
||||
#define TOML_LANG_MINOR 5
|
||||
|
||||
Reference in New Issue
Block a user