removed <cmath> dependency

also:
- fixed some pedantic clang warnings
- added preliminary support for ICC
- documentation fixes
This commit is contained in:
Mark Gillard 2020-02-29 22:34:08 +02:00
parent 36df648407
commit 98c599ec2c
18 changed files with 226 additions and 150 deletions

View File

@ -1,6 +1,11 @@
# toml++ (tomlplusplus) · [![c++version](https://img.shields.io/badge/c%2B%2B-17%2C%2020-informational)][cpp_compilers] [![tomlversion](https://img.shields.io/badge/TOML-v0.5.0-informational)][v0.5.0] [![CircleCI](https://circleci.com/gh/marzer/tomlplusplus.svg?style=shield)](https://circleci.com/gh/marzer/tomlplusplus) [![GitHub](https://img.shields.io/github/license/marzer/tomlplusplus)](./LICENSE) [![Mentioned in Awesome C++](https://awesome.re/mentioned-badge.svg)](https://github.com/fffaraz/awesome-cpp)
![banner](docs/tomlplusplus-banner-small.png)
![banner](docs/tomlplusplus-banner-small.png)
[![C++](https://img.shields.io/badge/c%2B%2B-17%2C%2020-informational)][cpp_compilers]
[![TOML](https://img.shields.io/badge/TOML-v0.5.0-informational)][v0.5.0]
[![MIT license](https://img.shields.io/badge/license-MIT-blue.svg)](./LICENSE)
[![Releases](https://img.shields.io/github/release/marzer/tomlplusplus.svg)](https://github.com/marzer/tomlplusplus/releases)
[![Mentioned in Awesome C++](https://awesome.re/mentioned-badge.svg)](https://github.com/fffaraz/awesome-cpp)
[![CircleCI](https://circleci.com/gh/marzer/tomlplusplus.svg?style=shield)](https://circleci.com/gh/marzer/tomlplusplus)
====
- Header-only
- [TOML v0.5.0](https://github.com/toml-lang/toml/blob/master/versions/en/toml-v0.5.0.md), plus optional support for some [unreleased TOML language features]
- C++17 (plus some C++20 features where available, e.g. experimental support for char8_t strings)

View File

@ -171,3 +171,13 @@ pre.m-code + pre.m-console span
{
color: rgb(140,140,140);
}
/* github badges (index.html) */
.gh-badges
{
padding-bottom: 0.75rem;
}
.gh-badges a
{
margin-right: 0.5rem;
}

View File

@ -281,7 +281,7 @@
/// for (auto& elem : *arr)
/// {
/// // visitation helps deal with the polymorphic nature of TOML data
/// elem.visit([=](auto&& el) noexcept
/// elem.visit([](auto&& el) noexcept
/// {
/// if constexpr (toml::is_number<decltype(el)>)
/// (*el)++;

View File

@ -192,7 +192,7 @@ TOML_START
///
/// for (size_t i = 0; i < arr.size(); i++)
/// {
/// arr[i].visit([=](auto&& el) noexcept
/// arr[i].visit([](auto&& el) noexcept
/// {
/// if constexpr (toml::is_number<decltype(el)>)
/// (*el)++;
@ -476,7 +476,7 @@ TOML_START
//# potentially move the initial value into the last element
values[i].reset(impl::make_node(std::forward<U>(val)));
return { values.begin() + start_idx };
return { values.begin() + static_cast<ptrdiff_t>(start_idx) };
}
}
}
@ -504,7 +504,7 @@ TOML_START
size_t i = start_idx;
for (auto it = first; it != last; it++)
values[i].reset(impl::make_node(*it));
return { values.begin() + start_idx };
return { values.begin() + static_cast<ptrdiff_t>(start_idx) };
}
}
}
@ -530,7 +530,7 @@ TOML_START
size_t i = start_idx;
for (auto& val : ilist)
values[i].reset(impl::make_node(val));
return { values.begin() + start_idx };
return { values.begin() + static_cast<ptrdiff_t>(start_idx) };
}
}
}
@ -916,7 +916,7 @@ TOML_START
size_after_flattening += leaf_count;
}
else
values.erase(values.cbegin() + i);
values.erase(values.cbegin() + static_cast<ptrdiff_t>(i));
}
if (!requires_flattening)

View File

@ -46,10 +46,6 @@
#ifdef __clang__
#ifndef __cpp_exceptions
#define TOML_EXCEPTIONS 0
#endif
#define TOML_PUSH_WARNINGS _Pragma("clang diagnostic push")
#define TOML_DISABLE_SWITCH_WARNINGS _Pragma("clang diagnostic ignored \"-Wswitch\"")
#define TOML_DISABLE_INIT_WARNINGS _Pragma("clang diagnostic ignored \"-Wmissing-field-initializers\"")
@ -72,11 +68,7 @@
#define TOML_USE_STREAMS_FOR_FLOATS 1
#endif
#elif defined(_MSC_VER)
#ifndef _CPPUNWIND
#define TOML_EXCEPTIONS 0
#endif
#elif defined(_MSC_VER) || (defined(__INTEL_COMPILER) && defined(__ICL))
#define TOML_CPP_VERSION _MSVC_LANG
#define TOML_PUSH_WARNINGS __pragma(warning(push))
@ -96,10 +88,6 @@
#elif defined(__GNUC__)
#ifndef __cpp_exceptions
#define TOML_EXCEPTIONS 0
#endif
#define TOML_PUSH_WARNINGS _Pragma("GCC diagnostic push")
#define TOML_DISABLE_SWITCH_WARNINGS _Pragma("GCC diagnostic ignored \"-Wswitch\"")
#define TOML_DISABLE_INIT_WARNINGS _Pragma("GCC diagnostic ignored \"-Wmissing-field-initializers\"") \
@ -140,14 +128,13 @@
#elif TOML_CPP_VERSION >= 201703L
#define TOML_CPP 17
#endif
#ifndef TOML_EXCEPTIONS
#define TOML_EXCEPTIONS 1
#endif
#if TOML_EXCEPTIONS
#if defined(__EXCEPTIONS) || defined(__cpp_exceptions) || defined(_CPPUNWIND)
#define TOML_EXCEPTIONS 1
#define TOML_MAY_THROW
#define TOML_MAY_THROW_UNLESS(...) noexcept(__VA_ARGS__)
#define TOML_INLINE_NS_EX
#else
#define TOML_EXCEPTIONS 0
#define TOML_MAY_THROW noexcept
#define TOML_MAY_THROW_UNLESS(...) noexcept
#define TOML_INLINE_NS_EX _noex
@ -275,7 +262,6 @@ TOML_DISABLE_ALL_WARNINGS
#include <cstdint>
#include <cstring> //memcpy, memset
#include <cmath> //log10
#include <optional>
#include <memory>
#include <string_view>

View File

@ -146,13 +146,11 @@ TOML_START
/// Z
/// \eout
///
/// \param hours The total hours.
/// \param minutes The total minutes.
///
/// \returns A time_offset.
/// \param h The total hours.
/// \param m The total minutes.
TOML_NODISCARD_CTOR
constexpr time_offset(int8_t hours, int8_t minutes) noexcept
: minutes{ static_cast<int16_t>(hours * 60 + minutes) }
constexpr time_offset(int8_t h, int8_t m) noexcept
: minutes{ static_cast<int16_t>(h * 60 + m) }
{}
/// \brief Equality operator.

View File

@ -83,31 +83,47 @@ TOML_IMPL_START
{
return n.get().length() + 2_sz; // + ""
}
else if constexpr (is_integer<decltype(n)>)
else if constexpr (is_number<decltype(n)>)
{
auto v = n.get();
if (!v)
return 1_sz;
size_t weight = {};
if (v < 0)
static constexpr auto digit_count = [](auto num) noexcept
-> size_t
{
weight += 1;
v *= -1;
}
return weight + static_cast<size_t>(std::log10(static_cast<double>(v)));
}
else if constexpr (is_floating_point<decltype(n)>)
{
auto v = n.get();
if (v == 0.0)
return 3_sz;
size_t weight = 2_sz; // ".0"
if (v < 0.0)
using number_t = decltype(num);
size_t digits = 1_sz;
while (num >= number_t{ 10 })
{
num /= number_t{ 10 };
digits++;
}
return digits;
};
if constexpr (is_integer<decltype(n)>)
{
weight += 1;
v *= -1.0;
auto v = n.get();
if (!v)
return 1_sz;
size_t weight = {};
if (v < 0)
{
weight += 1;
v *= -1;
}
return weight + digit_count(v);
}
else if constexpr (is_floating_point<decltype(n)>)
{
auto v = n.get();
if (v == 0.0)
return 3_sz;
size_t weight = 2_sz; // ".0"
if (v < 0.0)
{
weight += 1;
v *= -1.0;
}
return weight + digit_count(v);
}
return weight + static_cast<size_t>(std::log10(v));
}
else if constexpr (is_boolean<decltype(n)>)
{

View File

@ -27,10 +27,10 @@ TOML_IMPL_START
{
private:
const toml::node* source_;
format_flags flags_;
int indent_;
bool naked_newline_;
std::basic_ostream<CHAR>* stream_ = nullptr;
format_flags flags_;
int8_t indent_;
bool naked_newline_;
protected:
@ -40,8 +40,8 @@ TOML_IMPL_START
static constexpr size_t indent_columns = 4;
static constexpr toml::string_view indent_string = TOML_STRING_PREFIX(" "sv);
[[nodiscard]] int indent() const noexcept { return indent_; }
void indent(int level) noexcept { indent_ = level; }
[[nodiscard]] int8_t indent() const noexcept { return indent_; }
void indent(int8_t level) noexcept { indent_ = level; }
void increase_indent() noexcept { indent_++; }
void decrease_indent() noexcept { indent_--; }
@ -49,7 +49,7 @@ TOML_IMPL_START
void attach(std::basic_ostream<CHAR>& stream) noexcept
{
indent_ = 0;
indent_ = {};
naked_newline_ = true;
stream_ = &stream;
}
@ -70,7 +70,7 @@ TOML_IMPL_START
void print_indent() TOML_MAY_THROW
{
for (int i = 0; i < indent_; i++)
for (int8_t i = 0; i < indent_; i++)
{
print_to_stream(indent_string, *stream_);
naked_newline_ = false;

View File

@ -374,10 +374,13 @@ TOML_START
template <typename CHAR>
friend std::basic_ostream<CHAR>& operator << (std::basic_ostream<CHAR>& os, const node_view& nv) TOML_MAY_THROW
{
nv.visit([&](const auto& node) TOML_MAY_THROW
if (nv.node_)
{
os << node;
});
nv.node_->visit([&os](const auto& n) TOML_MAY_THROW
{
os << n;
});
}
return os;
}
};

View File

@ -41,11 +41,11 @@ TOML_START
class parse_result final
{
private:
bool is_err;
std::aligned_storage_t<
(sizeof(table) < sizeof(parse_error) ? sizeof(parse_error) : sizeof(table)),
(alignof(table) < alignof(parse_error) ? alignof(parse_error) : alignof(table))
> storage;
bool is_err;
void destroy() noexcept
{
@ -334,9 +334,9 @@ TOML_IMPL_START
(concatenator(std::forward<T>(args)), ...);
*ptr = '\0';
#if TOML_EXCEPTIONS
TOML_ERROR( buf, current_position(1), reader.source_path() );
TOML_ERROR(buf, current_position(1), reader.source_path());
#else
TOML_ERROR( std::string(buf, ptr - buf), current_position(1), reader.source_path());
TOML_ERROR(std::string(buf, static_cast<size_t>(ptr - buf)), current_position(1), reader.source_path());
#endif
}
}

View File

@ -21,7 +21,7 @@ TOML_IMPL_START
{
static_assert(sizeof(CHAR1) == 1);
static_assert(sizeof(CHAR2) == 1);
stream.write(reinterpret_cast<const CHAR2*>(str.data()), str.length());
stream.write(reinterpret_cast<const CHAR2*>(str.data()), static_cast<std::streamsize>(str.length()));
}
template <typename CHAR1, typename CHAR2>
@ -30,7 +30,7 @@ TOML_IMPL_START
{
static_assert(sizeof(CHAR1) == 1);
static_assert(sizeof(CHAR2) == 1);
stream.write(reinterpret_cast<const CHAR2*>(str.data()), str.length());
stream.write(reinterpret_cast<const CHAR2*>(str.data()), static_cast<std::streamsize>(str.length()));
}
template <typename CHAR>

View File

@ -678,7 +678,6 @@ TOML_START
/// node ["a"] was an integer
/// \eout
///
/// \tparam T The node's type.
/// \param key The node's key.
///
/// \returns A pointer to the node at the specified key, or nullptr.
@ -686,7 +685,6 @@ TOML_START
/// \brief Gets the node at a specific key (const overload).
///
/// \tparam T The node's type.
/// \param key The node's key.
///
/// \returns A pointer to the node at the specified key, or nullptr.

View File

@ -1,23 +1,61 @@
project(
'tomlplusplus', 'cpp',
version : '0.1.0',
'tomlplusplus',
'cpp',
version : '0.2.2',
license : 'MIT',
default_options : [
'cpp_std=c++17',
'warning_level=3',
'werror=true',
'cpp_eh=default'
]
)
compiler = meson.get_compiler('cpp')
message(['compiler ID: ', compiler.get_id()])
if compiler.get_id() == 'gcc'
add_project_arguments(['-fmax-errors=5', '-Wno-attributes', '-Wno-init-list-lifetime' ], language : 'cpp')
add_project_arguments([
'-fmax-errors=5',
'-Wno-attributes',
'-Wno-init-list-lifetime'
],
language : 'cpp'
)
endif
if compiler.get_id() == 'clang'
add_project_arguments(['-ferror-limit=5', '-fchar8_t'], language : 'cpp')
add_project_arguments([
'-ferror-limit=5',
'-fchar8_t',
'-Wno-c++98-compat',
'-Wno-c++98-compat-pedantic',
'-Wno-float-equal',
'-Wno-switch-enum',
'-Wno-documentation-unknown-command',
'-Wno-padded',
'-Wno-weak-vtables',
'-Wno-double-promotion'
#, '-Weverything'
],
language : 'cpp'
)
endif
if compiler.get_id() == 'intel-cl'
add_project_arguments([
'/Qoption,cpp,--unicode_source_kind,UTF-8',
'/std=c++latest',
'/wd82', # storage class is not first
'/wd280', # selector expression is constant (why the fuck is that a warning?)
'/wd411', # class provides no constructor (duh, it's an aggregate)
'/wd1011', # missing return statement (false negative)
'/wd1628', # function marked [[noreturn]] returns (false positive)
'/wd3280' # declaration hides member (triggered in Catch2)
],
language : 'cpp'
)
endif
compiler_supports_char8_strings = compiler.compiles('''
@ -33,9 +71,6 @@ compiler_supports_char8_strings = compiler.compiles('''
args : [ '-std=c++2a' ]
)
#pymod = import('python')
#python = pymod.find_installation('python3')
inc = include_directories(['include', 'extern'])
subdir('tests')

View File

@ -407,11 +407,25 @@ class ModifiersFix2(ModifiersFixBase):
# applies some basic fixes to index.html
class IndexPageFix(object):
__badges = [
('C++', 'https://img.shields.io/badge/c%2B%2B-17%2C%2020-informational', 'https://en.cppreference.com/w/cpp/compiler_support'),
('TOML', 'https://img.shields.io/badge/TOML-v0.5.0-informational', 'https://github.com/toml-lang/toml/blob/master/versions/en/toml-v0.5.0.md'),
('MIT License', 'https://img.shields.io/badge/license-MIT-blue.svg', 'https://github.com/marzer/tomlplusplus/blob/master/LICENSE'),
('Releases', 'https://img.shields.io/github/release/marzer/tomlplusplus.svg', 'https://github.com/marzer/tomlplusplus/releases'),
('Mentioned in Awesome C++', 'https://awesome.re/mentioned-badge.svg', 'https://github.com/fffaraz/awesome-cpp'),
('CircleCI', 'https://circleci.com/gh/marzer/tomlplusplus.svg?style=shield', 'https://circleci.com/gh/marzer/tomlplusplus')
]
def __call__(self, file, doc):
if file != 'index.html':
return False
parent = doc.body.main.article.div.div.div
parent('h1')[0].replace_with(parent('img')[0].extract())
banner = parent('img')[0].extract()
parent('h1')[0].replace_with(banner)
parent = doc.new_tag('div', class_='gh-badges', after=banner)
for (alt, src, href) in self.__badges:
anchor = doc.new_tag('a', parent=parent, href=href, target='_blank')
doc.new_tag('img', parent=anchor, src=src, alt='caption')
return True
@ -831,8 +845,6 @@ def postprocess_file(dir, file, fixes):
def delete_directory(dir_path):
if (path.exists(dir_path)):
print('Deleting {}'.format(dir_path))

View File

@ -14,8 +14,11 @@ TOML_POP_WARNINGS
template <typename CHAR, typename FUNC>
void parsing_should_succeed(std::basic_string_view<CHAR> toml_str, FUNC&& func, std::string_view source_path = {}) noexcept
{
INFO("String being parsed: '"sv << std::string_view( reinterpret_cast<const char*>(toml_str.data()), toml_str.length() ) << "'"sv)
constexpr auto validate_table = [](table&& tabl, std::string_view path) noexcept -> table&&
{
INFO("Validating table source information"sv)
CHECK(tabl.source().begin != source_position{});
CHECK(tabl.source().end != source_position{});
if (path.empty())
@ -33,10 +36,14 @@ void parsing_should_succeed(std::basic_string_view<CHAR> toml_str, FUNC&& func,
try
{
std::forward<FUNC>(func)(validate_table(toml::parse(toml_str, source_path), source_path));
{
INFO("Parsing string directly"sv)
std::forward<FUNC>(func)(validate_table(toml::parse(toml_str, source_path), source_path));
}
{
INFO("Parsing from a string stream"sv)
std::basic_stringstream<CHAR, std::char_traits<CHAR>, std::allocator<CHAR>> ss;
ss.write(toml_str.data(), toml_str.length());
ss.write(toml_str.data(), static_cast<std::streamsize>(toml_str.length()));
std::forward<FUNC>(func)(validate_table(toml::parse(ss, source_path), source_path));
}
}
@ -52,6 +59,7 @@ void parsing_should_succeed(std::basic_string_view<CHAR> toml_str, FUNC&& func,
#else
{
INFO("Parsing string directly"sv)
toml::parse_result result = toml::parse(toml_str, source_path);
if (result)
std::forward<FUNC>(func)(validate_table(std::move(result), source_path));
@ -67,8 +75,9 @@ void parsing_should_succeed(std::basic_string_view<CHAR> toml_str, FUNC&& func,
}
{
INFO("Parsing from a string stream"sv)
std::basic_stringstream<CHAR, std::char_traits<CHAR>, std::allocator<CHAR>> ss;
ss.write(toml_str.data(), toml_str.length());
ss.write(toml_str.data(), static_cast<std::streamsize>(toml_str.length()));
toml::parse_result result = toml::parse(ss, source_path);
if (result)
std::forward<FUNC>(func)(validate_table(std::move(result), source_path));
@ -117,7 +126,7 @@ void parsing_should_fail(std::basic_string_view<CHAR> toml_str) noexcept
run_tests([=]()
{
std::basic_stringstream<CHAR, std::char_traits<CHAR>, std::allocator<CHAR>> ss;
ss.write(toml_str.data(), toml_str.length());
ss.write(toml_str.data(), static_cast<std::streamsize>(toml_str.length()));
(void)toml::parse(ss);
});
@ -142,7 +151,7 @@ void parsing_should_fail(std::basic_string_view<CHAR> toml_str) noexcept
run_tests([=]() noexcept
{
std::basic_stringstream<CHAR, std::char_traits<CHAR>, std::allocator<CHAR>> ss;
ss.write(toml_str.data(), toml_str.length());
ss.write(toml_str.data(), static_cast<std::streamsize>(toml_str.length()));
return toml::parse(ss);
});
@ -203,8 +212,6 @@ void parse_expected_value(std::string_view value_str, const T& expected) noexcep
parsing_should_succeed(std::string_view{ val }, [&](table&& tbl) noexcept
{
INFO("String being parsed: '"sv << val << "'"sv);
CHECK(tbl.size() == 1);
auto nv = tbl[S("val"sv)];
REQUIRE(nv);

126
toml.hpp
View File

@ -110,10 +110,6 @@
#ifdef __clang__
#ifndef __cpp_exceptions
#define TOML_EXCEPTIONS 0
#endif
#define TOML_PUSH_WARNINGS _Pragma("clang diagnostic push")
#define TOML_DISABLE_SWITCH_WARNINGS _Pragma("clang diagnostic ignored \"-Wswitch\"")
#define TOML_DISABLE_INIT_WARNINGS _Pragma("clang diagnostic ignored \"-Wmissing-field-initializers\"")
@ -136,11 +132,7 @@
#define TOML_USE_STREAMS_FOR_FLOATS 1
#endif
#elif defined(_MSC_VER)
#ifndef _CPPUNWIND
#define TOML_EXCEPTIONS 0
#endif
#elif defined(_MSC_VER) || (defined(__INTEL_COMPILER) && defined(__ICL))
#define TOML_CPP_VERSION _MSVC_LANG
#define TOML_PUSH_WARNINGS __pragma(warning(push))
@ -160,10 +152,6 @@
#elif defined(__GNUC__)
#ifndef __cpp_exceptions
#define TOML_EXCEPTIONS 0
#endif
#define TOML_PUSH_WARNINGS _Pragma("GCC diagnostic push")
#define TOML_DISABLE_SWITCH_WARNINGS _Pragma("GCC diagnostic ignored \"-Wswitch\"")
#define TOML_DISABLE_INIT_WARNINGS _Pragma("GCC diagnostic ignored \"-Wmissing-field-initializers\"") \
@ -204,14 +192,13 @@
#elif TOML_CPP_VERSION >= 201703L
#define TOML_CPP 17
#endif
#ifndef TOML_EXCEPTIONS
#define TOML_EXCEPTIONS 1
#endif
#if TOML_EXCEPTIONS
#if defined(__EXCEPTIONS) || defined(__cpp_exceptions) || defined(_CPPUNWIND)
#define TOML_EXCEPTIONS 1
#define TOML_MAY_THROW
#define TOML_MAY_THROW_UNLESS(...) noexcept(__VA_ARGS__)
#define TOML_INLINE_NS_EX
#else
#define TOML_EXCEPTIONS 0
#define TOML_MAY_THROW noexcept
#define TOML_MAY_THROW_UNLESS(...) noexcept
#define TOML_INLINE_NS_EX _noex
@ -343,7 +330,6 @@ TOML_DISABLE_ALL_WARNINGS
#include <cstdint>
#include <cstring> //memcpy, memset
#include <cmath> //log10
#include <optional>
#include <memory>
#include <string_view>
@ -926,8 +912,8 @@ TOML_START
{}
TOML_NODISCARD_CTOR
constexpr time_offset(int8_t hours, int8_t minutes) noexcept
: minutes{ static_cast<int16_t>(hours * 60 + minutes) }
constexpr time_offset(int8_t h, int8_t m) noexcept
: minutes{ static_cast<int16_t>(h * 60 + m) }
{}
[[nodiscard]]
@ -1035,7 +1021,7 @@ TOML_IMPL_START
{
static_assert(sizeof(CHAR1) == 1);
static_assert(sizeof(CHAR2) == 1);
stream.write(reinterpret_cast<const CHAR2*>(str.data()), str.length());
stream.write(reinterpret_cast<const CHAR2*>(str.data()), static_cast<std::streamsize>(str.length()));
}
template <typename CHAR1, typename CHAR2>
@ -1044,7 +1030,7 @@ TOML_IMPL_START
{
static_assert(sizeof(CHAR1) == 1);
static_assert(sizeof(CHAR2) == 1);
stream.write(reinterpret_cast<const CHAR2*>(str.data()), str.length());
stream.write(reinterpret_cast<const CHAR2*>(str.data()), static_cast<std::streamsize>(str.length()));
}
template <typename CHAR>
@ -2218,7 +2204,7 @@ TOML_START
values[i].reset(impl::make_node(val));
values[i].reset(impl::make_node(std::forward<U>(val)));
return { values.begin() + start_idx };
return { values.begin() + static_cast<ptrdiff_t>(start_idx) };
}
}
}
@ -2238,7 +2224,7 @@ TOML_START
size_t i = start_idx;
for (auto it = first; it != last; it++)
values[i].reset(impl::make_node(*it));
return { values.begin() + start_idx };
return { values.begin() + static_cast<ptrdiff_t>(start_idx) };
}
}
}
@ -2257,7 +2243,7 @@ TOML_START
size_t i = start_idx;
for (auto& val : ilist)
values[i].reset(impl::make_node(val));
return { values.begin() + start_idx };
return { values.begin() + static_cast<ptrdiff_t>(start_idx) };
}
}
}
@ -2455,7 +2441,7 @@ TOML_START
size_after_flattening += leaf_count;
}
else
values.erase(values.cbegin() + i);
values.erase(values.cbegin() + static_cast<ptrdiff_t>(i));
}
if (!requires_flattening)
@ -3083,10 +3069,13 @@ TOML_START
template <typename CHAR>
friend std::basic_ostream<CHAR>& operator << (std::basic_ostream<CHAR>& os, const node_view& nv) TOML_MAY_THROW
{
nv.visit([&](const auto& node) TOML_MAY_THROW
if (nv.node_)
{
os << node;
});
nv.node_->visit([&os](const auto& n) TOML_MAY_THROW
{
os << n;
});
}
return os;
}
};
@ -4704,12 +4693,11 @@ TOML_START
class parse_result final
{
private:
bool is_err;
std::aligned_storage_t<
(sizeof(table) < sizeof(parse_error) ? sizeof(parse_error) : sizeof(table)),
(alignof(table) < alignof(parse_error) ? alignof(parse_error) : alignof(table))
> storage;
bool is_err;
void destroy() noexcept
{
if (is_err)
@ -4976,9 +4964,9 @@ TOML_IMPL_START
(concatenator(std::forward<T>(args)), ...);
*ptr = '\0';
#if TOML_EXCEPTIONS
TOML_ERROR( buf, current_position(1), reader.source_path() );
TOML_ERROR(buf, current_position(1), reader.source_path());
#else
TOML_ERROR( std::string(buf, ptr - buf), current_position(1), reader.source_path());
TOML_ERROR(std::string(buf, static_cast<size_t>(ptr - buf)), current_position(1), reader.source_path());
#endif
}
}
@ -7846,10 +7834,10 @@ TOML_IMPL_START
{
private:
const toml::node* source_;
format_flags flags_;
int indent_;
bool naked_newline_;
std::basic_ostream<CHAR>* stream_ = nullptr;
format_flags flags_;
int8_t indent_;
bool naked_newline_;
protected:
@ -7859,14 +7847,14 @@ TOML_IMPL_START
static constexpr size_t indent_columns = 4;
static constexpr toml::string_view indent_string = TOML_STRING_PREFIX(" "sv);
[[nodiscard]] int indent() const noexcept { return indent_; }
void indent(int level) noexcept { indent_ = level; }
[[nodiscard]] int8_t indent() const noexcept { return indent_; }
void indent(int8_t level) noexcept { indent_ = level; }
void increase_indent() noexcept { indent_++; }
void decrease_indent() noexcept { indent_--; }
void clear_naked_newline() noexcept { naked_newline_ = false; }
void attach(std::basic_ostream<CHAR>& stream) noexcept
{
indent_ = 0;
indent_ = {};
naked_newline_ = true;
stream_ = &stream;
}
@ -7887,7 +7875,7 @@ TOML_IMPL_START
void print_indent() TOML_MAY_THROW
{
for (int i = 0; i < indent_; i++)
for (int8_t i = 0; i < indent_; i++)
{
print_to_stream(indent_string, *stream_);
naked_newline_ = false;
@ -8047,31 +8035,47 @@ TOML_IMPL_START
{
return n.get().length() + 2_sz; // + ""
}
else if constexpr (is_integer<decltype(n)>)
else if constexpr (is_number<decltype(n)>)
{
auto v = n.get();
if (!v)
return 1_sz;
size_t weight = {};
if (v < 0)
static constexpr auto digit_count = [](auto num) noexcept
-> size_t
{
weight += 1;
v *= -1;
}
return weight + static_cast<size_t>(std::log10(static_cast<double>(v)));
}
else if constexpr (is_floating_point<decltype(n)>)
{
auto v = n.get();
if (v == 0.0)
return 3_sz;
size_t weight = 2_sz; // ".0"
if (v < 0.0)
using number_t = decltype(num);
size_t digits = 1_sz;
while (num >= number_t{ 10 })
{
num /= number_t{ 10 };
digits++;
}
return digits;
};
if constexpr (is_integer<decltype(n)>)
{
weight += 1;
v *= -1.0;
auto v = n.get();
if (!v)
return 1_sz;
size_t weight = {};
if (v < 0)
{
weight += 1;
v *= -1;
}
return weight + digit_count(v);
}
else if constexpr (is_floating_point<decltype(n)>)
{
auto v = n.get();
if (v == 0.0)
return 3_sz;
size_t weight = 2_sz; // ".0"
if (v < 0.0)
{
weight += 1;
v *= -1.0;
}
return weight + digit_count(v);
}
return weight + static_cast<size_t>(std::log10(v));
}
else if constexpr (is_boolean<decltype(n)>)
{

View File

@ -80,6 +80,7 @@
<None Include="..\docs\Doxyfile-mcss" />
<None Include="..\docs\tomlplusplus.css" />
<None Include="..\docs\tomlplusplus.js" />
<None Include="..\meson.build" />
<None Include="..\python\ci_single_header_check.py" />
<None Include="..\python\generate_documentation.py" />
<None Include="..\python\generate_single_header.py" />

View File

@ -78,6 +78,7 @@
<Filter>doc</Filter>
</None>
<None Include="..\CONTRIBUTING.md" />
<None Include="..\meson.build" />
</ItemGroup>
<ItemGroup>
<Filter Include="include">