diff --git a/CHANGELOG.md b/CHANGELOG.md index 926e0f78c..fc32cd98c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file. ## Next Release +### Style + +- re-formatting of whole codebase with clang-format 20.1.3 + # Tests - added integration tests for QM programs diff --git a/external/progressbar/include/progressbar.hpp b/external/progressbar/include/progressbar.hpp index 50ab6d089..2df368c10 100644 --- a/external/progressbar/include/progressbar.hpp +++ b/external/progressbar/include/progressbar.hpp @@ -39,143 +39,182 @@ #include #include -#include #include +#include -class progressbar { - - public: - // default destructor - ~progressbar() = default; - - // delete everything else - progressbar (progressbar const&) = delete; - progressbar& operator=(progressbar const&) = delete; - progressbar (progressbar&&) = delete; - progressbar& operator=(progressbar&&) = delete; - - // default constructor, must call set_niter later - inline progressbar(); - inline progressbar(int n, bool showbar=true, std::ostream& out=std::cerr); - - // reset bar to use it again - inline void reset(); - // set number of loop iterations - inline void set_niter(int iter); - // chose your style - inline void set_done_char(const std::string& sym) {done_char = sym;} - inline void set_todo_char(const std::string& sym) {todo_char = sym;} - inline void set_opening_bracket_char(const std::string& sym) {opening_bracket_char = sym;} - inline void set_closing_bracket_char(const std::string& sym) {closing_bracket_char = sym;} - // to show only the percentage - inline void show_bar(bool flag = true) {do_show_bar = flag;} - // set the output stream - inline void set_output_stream(const std::ostream& stream) {output.rdbuf(stream.rdbuf());} - // main function - inline void update(); - - private: - int progress; - int n_cycles; - int last_perc; - bool do_show_bar; - bool update_is_called; - - std::string done_char; - std::string todo_char; - std::string opening_bracket_char; - std::string closing_bracket_char; - - std::ostream& output; +class progressbar +{ + public: + // default destructor + ~progressbar() = default; + + // delete everything else + progressbar(progressbar const&) = delete; + progressbar& operator=(progressbar const&) = delete; + progressbar(progressbar&&) = delete; + progressbar& operator=(progressbar&&) = delete; + + // default constructor, must call set_niter later + inline progressbar(); + inline progressbar( + int n, + bool showbar = true, + std::ostream& out = std::cerr + ); + + // reset bar to use it again + inline void reset(); + // set number of loop iterations + inline void set_niter(int iter); + // chose your style + inline void set_done_char(const std::string& sym) { done_char = sym; } + inline void set_todo_char(const std::string& sym) { todo_char = sym; } + inline void set_opening_bracket_char(const std::string& sym) + { + opening_bracket_char = sym; + } + inline void set_closing_bracket_char(const std::string& sym) + { + closing_bracket_char = sym; + } + // to show only the percentage + inline void show_bar(bool flag = true) { do_show_bar = flag; } + // set the output stream + inline void set_output_stream(const std::ostream& stream) + { + output.rdbuf(stream.rdbuf()); + } + // main function + inline void update(); + + private: + int progress; + int n_cycles; + int last_perc; + bool do_show_bar; + bool update_is_called; + + std::string done_char; + std::string todo_char; + std::string opening_bracket_char; + std::string closing_bracket_char; + + std::ostream& output; }; -inline progressbar::progressbar() : - progress(0), - n_cycles(0), - last_perc(0), - do_show_bar(true), - update_is_called(false), - done_char("#"), - todo_char(" "), - opening_bracket_char("["), - closing_bracket_char("]"), - output(std::cerr) {} - -inline progressbar::progressbar(int n, bool showbar, std::ostream& out) : - progress(0), - n_cycles(n), - last_perc(0), - do_show_bar(showbar), - update_is_called(false), - done_char("#"), - todo_char(" "), - opening_bracket_char("["), - closing_bracket_char("]"), - output(out) {} - -inline void progressbar::reset() { - progress = 0, - update_is_called = false; +inline progressbar::progressbar() + : progress(0), + n_cycles(0), + last_perc(0), + do_show_bar(true), + update_is_called(false), + done_char("#"), + todo_char(" "), + opening_bracket_char("["), + closing_bracket_char("]"), + output(std::cerr) +{ +} + +inline progressbar::progressbar(int n, bool showbar, std::ostream& out) + : progress(0), + n_cycles(n), + last_perc(0), + do_show_bar(showbar), + update_is_called(false), + done_char("#"), + todo_char(" "), + opening_bracket_char("["), + closing_bracket_char("]"), + output(out) +{ +} + +inline void progressbar::reset() +{ + progress = 0, update_is_called = false; last_perc = 0; return; } -inline void progressbar::set_niter(int niter) { - if (niter <= 0) throw std::invalid_argument( - "progressbar::set_niter: number of iterations null or negative"); +inline void progressbar::set_niter(int niter) +{ + if (niter <= 0) + throw std::invalid_argument( + "progressbar::set_niter: number of iterations null or negative" + ); n_cycles = niter; return; } -inline void progressbar::update() { - - if (n_cycles == 0) throw std::runtime_error( - "progressbar::update: number of cycles not set"); - - if (!update_is_called) { - if (do_show_bar == true) { +inline void progressbar::update() +{ + if (n_cycles == 0) + throw std::runtime_error( + "progressbar::update: number of cycles not set" + ); + + if (!update_is_called) + { + if (do_show_bar == true) + { output << opening_bracket_char; for (int _ = 0; _ < 50; _++) output << todo_char; output << closing_bracket_char << " 0%"; } - else output << "0%"; + else + output << "0%"; } update_is_called = true; int perc = 0; // compute percentage, if did not change, do nothing and return - perc = progress*100./(n_cycles-1); - if (perc < last_perc) return; + perc = progress * 100. / (n_cycles - 1); + if (perc < last_perc) + return; // update percentage each unit - if (perc == last_perc + 1) { + if (perc == last_perc + 1) + { // erase the correct number of characters - if (perc <= 10) output << "\b\b" << perc << '%'; - else if (perc > 10 and perc < 100) output << "\b\b\b" << perc << '%'; - else if (perc == 100) output << "\b\b\b" << perc << '%'; + if (perc <= 10) + output << "\b\b" << perc << '%'; + else if (perc > 10 and perc < 100) + output << "\b\b\b" << perc << '%'; + else if (perc == 100) + output << "\b\b\b" << perc << '%'; } - if (do_show_bar == true) { + if (do_show_bar == true) + { // update bar every ten units - if (perc % 2 == 0) { + if (perc % 2 == 0) + { // erase closing bracket output << std::string(closing_bracket_char.size(), '\b'); // erase trailing percentage characters - if (perc < 10) output << "\b\b\b"; - else if (perc >= 10 && perc < 100) output << "\b\b\b\b"; - else if (perc == 100) output << "\b\b\b\b\b"; + if (perc < 10) + output << "\b\b\b"; + else if (perc >= 10 && perc < 100) + output << "\b\b\b\b"; + else if (perc == 100) + output << "\b\b\b\b\b"; // erase 'todo_char' - for (int j = 0; j < 50-(perc-1)/2; ++j) { + for (int j = 0; j < 50 - (perc - 1) / 2; ++j) + { output << std::string(todo_char.size(), '\b'); } // add one additional 'done_char' - if (perc == 0) output << todo_char; - else output << done_char; + if (perc == 0) + output << todo_char; + else + output << done_char; // refill with 'todo_char' - for (int j = 0; j < 50-(perc-1)/2-1; ++j) output << todo_char; + for (int j = 0; j < 50 - (perc - 1) / 2 - 1; ++j) + output << todo_char; // readd trailing percentage characters output << closing_bracket_char << ' ' << perc << '%'; diff --git a/external/toml++/include/toml.hpp b/external/toml++/include/toml.hpp index 048575180..01b724b02 100644 --- a/external/toml++/include/toml.hpp +++ b/external/toml++/include/toml.hpp @@ -6,12 +6,16 @@ // //---------------------------------------------------------------------------------------------------------------------- // -// - THIS FILE WAS ASSEMBLED FROM MULTIPLE HEADER FILES BY A SCRIPT - PLEASE DON'T EDIT IT DIRECTLY - +// - THIS FILE WAS ASSEMBLED FROM MULTIPLE HEADER FILES BY A SCRIPT - +// PLEASE DON'T EDIT IT DIRECTLY - // -// If you wish to submit a contribution to toml++, hooray and thanks! Before you crack on, please be aware that this -// file was assembled from a number of smaller files by a python script, and code contributions should not be made -// against it directly. You should instead make your changes in the relevant source file(s). The file names of the files -// that contributed to this header can be found at the beginnings and ends of the corresponding sections of this file. +// If you wish to submit a contribution to toml++, hooray and thanks! Before you +// crack on, please be aware that this file was assembled from a number of +// smaller files by a python script, and code contributions should not be made +// against it directly. You should instead make your changes in the relevant +// source file(s). The file names of the files that contributed to this header +// can be found at the beginnings and ends of the corresponding sections of this +// file. // //---------------------------------------------------------------------------------------------------------------------- // @@ -27,26 +31,32 @@ // // Copyright (c) Mark Gillard // -// 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: +// 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 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. +// 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. // //---------------------------------------------------------------------------------------------------------------------- #ifndef TOMLPLUSPLUS_H #define TOMLPLUSPLUS_H -#define INCLUDE_TOMLPLUSPLUS_H // old guard name used pre-v3 +#define INCLUDE_TOMLPLUSPLUS_H // old guard name used pre-v3 -//******** impl/preprocessor.h *************************************************************************************** +//******** impl/preprocessor.h +//*************************************************************************************** #ifndef __cplusplus #error toml++ is a C++ library. @@ -70,11 +80,13 @@ #endif #endif -#define TOML_MAKE_VERSION(major, minor, patch) (((major)*10000) + ((minor)*100) + ((patch))) +#define TOML_MAKE_VERSION(major, minor, patch) \ + (((major) * 10000) + ((minor) * 100) + ((patch))) #ifdef __clang__ -#define TOML_CLANG __clang_major__ -#define TOML_CLANG_VERSION TOML_MAKE_VERSION(__clang_major__, __clang_minor__, __clang_patchlevel__) +#define TOML_CLANG __clang_major__ +#define TOML_CLANG_VERSION \ + TOML_MAKE_VERSION(__clang_major__, __clang_minor__, __clang_patchlevel__) #else #define TOML_CLANG 0 #endif @@ -86,7 +98,7 @@ #define TOML_ICC_CL 0 #endif #else -#define TOML_ICC 0 +#define TOML_ICC 0 #define TOML_ICC_CL 0 #endif #if defined(_MSC_VER) && !TOML_CLANG && !TOML_ICC @@ -99,12 +111,14 @@ #else #define TOML_GCC 0 #endif -#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__) || defined(__CYGWIN__) +#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || \ + defined(__NT__) || defined(__CYGWIN__) #define TOML_WINDOWS 1 #else #define TOML_WINDOWS 0 #endif -#if defined(DOXYGEN) || defined(__DOXYGEN__) || defined(__POXY__) || defined(__poxy__) +#if defined(DOXYGEN) || defined(__DOXYGEN__) || defined(__POXY__) || \ + defined(__poxy__) #define TOML_DOXYGEN 1 #else #define TOML_DOXYGEN 0 @@ -123,7 +137,8 @@ // special handling for apple clang; see: // - https://github.com/marzer/tomlplusplus/issues/189 // - https://en.wikipedia.org/wiki/Xcode -// - https://stackoverflow.com/questions/19387043/how-can-i-reliably-detect-the-version-of-clang-at-preprocessing-time +// - +// https://stackoverflow.com/questions/19387043/how-can-i-reliably-detect-the-version-of-clang-at-preprocessing-time #if TOML_CLANG && defined(__apple_build_version__) #undef TOML_CLANG #if TOML_CLANG_VERSION >= TOML_MAKE_VERSION(14, 0, 0) @@ -143,19 +158,21 @@ #elif TOML_CLANG_VERSION >= TOML_MAKE_VERSION(10, 0, 1) #define TOML_CLANG 7 #else -#define TOML_CLANG 6 // not strictly correct but doesn't matter below this +#define TOML_CLANG 6 // not strictly correct but doesn't matter below this #endif #endif // IA64 -#if defined(__ia64__) || defined(__ia64) || defined(_IA64) || defined(__IA64__) || defined(_M_IA64) +#if defined(__ia64__) || defined(__ia64) || defined(_IA64) || \ + defined(__IA64__) || defined(_M_IA64) #define TOML_ARCH_ITANIUM 1 #else #define TOML_ARCH_ITANIUM 0 #endif // AMD64 -#if defined(__amd64__) || defined(__amd64) || defined(__x86_64__) || defined(__x86_64) || defined(_M_AMD64) +#if defined(__amd64__) || defined(__amd64) || defined(__x86_64__) || \ + defined(__x86_64) || defined(_M_AMD64) #define TOML_ARCH_AMD64 1 #else #define TOML_ARCH_AMD64 0 @@ -169,19 +186,19 @@ #endif // ARM -#if defined(__aarch64__) || defined(__ARM_ARCH_ISA_A64) || defined(_M_ARM64) || defined(__ARM_64BIT_STATE) \ - || defined(_M_ARM64EC) +#if defined(__aarch64__) || defined(__ARM_ARCH_ISA_A64) || \ + defined(_M_ARM64) || defined(__ARM_64BIT_STATE) || defined(_M_ARM64EC) #define TOML_ARCH_ARM32 0 #define TOML_ARCH_ARM64 1 -#define TOML_ARCH_ARM 1 +#define TOML_ARCH_ARM 1 #elif defined(__arm__) || defined(_M_ARM) || defined(__ARM_32BIT_STATE) #define TOML_ARCH_ARM32 1 #define TOML_ARCH_ARM64 0 -#define TOML_ARCH_ARM 1 +#define TOML_ARCH_ARM 1 #else #define TOML_ARCH_ARM32 0 #define TOML_ARCH_ARM64 0 -#define TOML_ARCH_ARM 0 +#define TOML_ARCH_ARM 0 #endif // TOML_HAS_INCLUDE @@ -248,11 +265,11 @@ // TOML_CONCAT #define TOML_CONCAT_1(x, y) x##y -#define TOML_CONCAT(x, y) TOML_CONCAT_1(x, y) +#define TOML_CONCAT(x, y) TOML_CONCAT_1(x, y) // TOML_MAKE_STRING #define TOML_MAKE_STRING_1(s) #s -#define TOML_MAKE_STRING(s) TOML_MAKE_STRING_1(s) +#define TOML_MAKE_STRING(s) TOML_MAKE_STRING_1(s) // TOML_PRAGMA_XXXX (compiler-specific pragmas) #if TOML_CLANG @@ -295,9 +312,9 @@ #ifdef _MSC_VER #define TOML_ALWAYS_INLINE __forceinline #elif TOML_GCC || TOML_CLANG || TOML_HAS_ATTR(__always_inline__) -#define TOML_ALWAYS_INLINE \ - TOML_ATTR(__always_inline__) \ - inline +#define TOML_ALWAYS_INLINE \ + TOML_ATTR(__always_inline__) \ + inline #else #define TOML_ALWAYS_INLINE inline #endif @@ -305,7 +322,7 @@ // TOML_NEVER_INLINE #ifdef _MSC_VER #define TOML_NEVER_INLINE TOML_DECLSPEC(noinline) -#elif TOML_CUDA // https://gitlab.gnome.org/GNOME/glib/-/issues/2555 +#elif TOML_CUDA // https://gitlab.gnome.org/GNOME/glib/-/issues/2555 TOML_ATTR(noinline) #else #if TOML_GCC || TOML_CLANG || TOML_HAS_ATTR(__noinline__) @@ -318,7 +335,7 @@ TOML_ATTR(noinline) // MSVC attributes #define TOML_ABSTRACT_INTERFACE TOML_DECLSPEC(novtable) -#define TOML_EMPTY_BASES TOML_DECLSPEC(empty_bases) +#define TOML_EMPTY_BASES TOML_DECLSPEC(empty_bases) // TOML_TRIVIAL_ABI #if TOML_CLANG || TOML_HAS_ATTR(__trivial_abi__) @@ -374,7 +391,8 @@ TOML_ATTR(noinline) // TOML_UNREACHABLE #ifdef _MSC_VER #define TOML_UNREACHABLE __assume(0) -#elif TOML_ICC || TOML_CLANG || TOML_GCC || TOML_HAS_BUILTIN(__builtin_unreachable) +#elif TOML_ICC || TOML_CLANG || TOML_GCC || \ + TOML_HAS_BUILTIN(__builtin_unreachable) #define TOML_UNREACHABLE __builtin_unreachable() #else #define TOML_UNREACHABLE static_assert(true) @@ -415,7 +433,7 @@ TOML_ATTR(noinline) // TOML_OPEN_ENUM + TOML_CLOSED_ENUM #if TOML_CLANG || TOML_HAS_ATTR(enum_extensibility) -#define TOML_OPEN_ENUM __attribute__((enum_extensibility(open))) +#define TOML_OPEN_ENUM __attribute__((enum_extensibility(open))) #define TOML_CLOSED_ENUM __attribute__((enum_extensibility(closed))) #else #define TOML_OPEN_ENUM @@ -427,69 +445,76 @@ TOML_ATTR(noinline) #define TOML_CLOSED_FLAGS_ENUM TOML_CLOSED_ENUM TOML_FLAGS_ENUM // TOML_MAKE_FLAGS -#define TOML_MAKE_FLAGS_2(T, op, linkage) \ - TOML_CONST_INLINE_GETTER \ - linkage constexpr T operator op(T lhs, T rhs) noexcept \ - { \ - using under = std::underlying_type_t; \ - return static_cast(static_cast(lhs) op static_cast(rhs)); \ - } \ - \ - linkage constexpr T& operator TOML_CONCAT(op, =)(T & lhs, T rhs) noexcept \ - { \ - return lhs = (lhs op rhs); \ - } \ - \ - static_assert(true) -#define TOML_MAKE_FLAGS_1(T, linkage) \ - static_assert(std::is_enum_v); \ - \ - TOML_MAKE_FLAGS_2(T, &, linkage); \ - TOML_MAKE_FLAGS_2(T, |, linkage); \ - TOML_MAKE_FLAGS_2(T, ^, linkage); \ - \ - TOML_CONST_INLINE_GETTER \ - linkage constexpr T operator~(T val) noexcept \ - { \ - using under = std::underlying_type_t; \ - return static_cast(~static_cast(val)); \ - } \ - \ - TOML_CONST_INLINE_GETTER \ - linkage constexpr bool operator!(T val) noexcept \ - { \ - using under = std::underlying_type_t; \ - return !static_cast(val); \ - } \ - \ - static_assert(true) +#define TOML_MAKE_FLAGS_2(T, op, linkage) \ + TOML_CONST_INLINE_GETTER \ + linkage constexpr T operator op(T lhs, T rhs) noexcept \ + { \ + using under = std::underlying_type_t; \ + return static_cast(static_cast(lhs) \ + op static_cast(rhs)); \ + } \ + \ + linkage constexpr T& operator TOML_CONCAT(op, =)(T & lhs, T rhs) noexcept \ + { \ + return lhs = (lhs op rhs); \ + } \ + \ + static_assert(true) +#define TOML_MAKE_FLAGS_1(T, linkage) \ + static_assert(std::is_enum_v); \ + \ + TOML_MAKE_FLAGS_2(T, &, linkage); \ + TOML_MAKE_FLAGS_2(T, |, linkage); \ + TOML_MAKE_FLAGS_2(T, ^, linkage); \ + \ + TOML_CONST_INLINE_GETTER \ + linkage constexpr T operator~(T val) noexcept \ + { \ + using under = std::underlying_type_t; \ + return static_cast(~static_cast(val)); \ + } \ + \ + TOML_CONST_INLINE_GETTER \ + linkage constexpr bool operator!(T val) noexcept \ + { \ + using under = std::underlying_type_t; \ + return !static_cast(val); \ + } \ + \ + static_assert(true) #define TOML_MAKE_FLAGS(T) TOML_MAKE_FLAGS_1(T, ) #define TOML_UNUSED(...) static_cast(__VA_ARGS__) -#define TOML_DELETE_DEFAULTS(T) \ - T(const T&) = delete; \ - T(T&&) = delete; \ - T& operator=(const T&) = delete; \ - T& operator=(T&&) = delete - -#define TOML_ASYMMETRICAL_EQUALITY_OPS(LHS, RHS, ...) \ - __VA_ARGS__ TOML_NODISCARD \ - friend bool operator==(RHS rhs, LHS lhs) noexcept \ - { \ - return lhs == rhs; \ - } \ - __VA_ARGS__ TOML_NODISCARD \ - friend bool operator!=(LHS lhs, RHS rhs) noexcept \ - { \ - return !(lhs == rhs); \ - } \ - __VA_ARGS__ TOML_NODISCARD \ - friend bool operator!=(RHS rhs, LHS lhs) noexcept \ - { \ - return !(lhs == rhs); \ - } \ - static_assert(true) +#define TOML_DELETE_DEFAULTS(T) \ + T(const T&) = delete; \ + T(T&&) = delete; \ + T& operator=(const T&) = delete; \ + T& operator=(T&&) = delete + +#define TOML_ASYMMETRICAL_EQUALITY_OPS(LHS, RHS, ...) \ + __VA_ARGS__ TOML_NODISCARD friend bool operator==( \ + RHS rhs, \ + LHS lhs \ + ) noexcept \ + { \ + return lhs == rhs; \ + } \ + __VA_ARGS__ TOML_NODISCARD friend bool operator!=( \ + LHS lhs, \ + RHS rhs \ + ) noexcept \ + { \ + return !(lhs == rhs); \ + } \ + __VA_ARGS__ TOML_NODISCARD friend bool operator!=( \ + RHS rhs, \ + LHS lhs \ + ) noexcept \ + { \ + return !(lhs == rhs); \ + } \ + static_assert(true) #define TOML_EVAL_BOOL_1(T, F) T #define TOML_EVAL_BOOL_0(T, F) F @@ -502,208 +527,215 @@ TOML_ATTR(noinline) #if TOML_CLANG -#define TOML_PUSH_WARNINGS \ - TOML_PRAGMA_CLANG(diagnostic push) \ - TOML_PRAGMA_CLANG(diagnostic ignored "-Wunknown-warning-option") \ - static_assert(true) - -#define TOML_DISABLE_SWITCH_WARNINGS \ - TOML_PRAGMA_CLANG(diagnostic ignored "-Wswitch") \ - static_assert(true) - -#define TOML_DISABLE_ARITHMETIC_WARNINGS \ - TOML_PRAGMA_CLANG(diagnostic ignored "-Wfloat-equal") \ - TOML_PRAGMA_CLANG(diagnostic ignored "-Wdouble-promotion") \ - TOML_PRAGMA_CLANG(diagnostic ignored "-Wchar-subscripts") \ - TOML_PRAGMA_CLANG(diagnostic ignored "-Wshift-sign-overflow") \ - static_assert(true) - -#define TOML_DISABLE_SPAM_WARNINGS \ - TOML_PRAGMA_CLANG_GE_9(diagnostic ignored "-Wctad-maybe-unsupported") \ - TOML_PRAGMA_CLANG_GE_10(diagnostic ignored "-Wzero-as-null-pointer-constant") \ - TOML_PRAGMA_CLANG_GE_11(diagnostic ignored "-Wsuggest-destructor-override") \ - TOML_PRAGMA_CLANG(diagnostic ignored "-Wweak-vtables") \ - TOML_PRAGMA_CLANG(diagnostic ignored "-Wweak-template-vtables") \ - TOML_PRAGMA_CLANG(diagnostic ignored "-Wdouble-promotion") \ - TOML_PRAGMA_CLANG(diagnostic ignored "-Wchar-subscripts") \ - TOML_PRAGMA_CLANG(diagnostic ignored "-Wmissing-field-initializers") \ - TOML_PRAGMA_CLANG(diagnostic ignored "-Wpadded") \ - static_assert(true) - -#define TOML_POP_WARNINGS \ - TOML_PRAGMA_CLANG(diagnostic pop) \ - static_assert(true) - -#define TOML_DISABLE_WARNINGS \ - TOML_PRAGMA_CLANG(diagnostic push) \ - TOML_PRAGMA_CLANG(diagnostic ignored "-Weverything") \ - static_assert(true, "") - -#define TOML_ENABLE_WARNINGS \ - TOML_PRAGMA_CLANG(diagnostic pop) \ - static_assert(true) +#define TOML_PUSH_WARNINGS \ + TOML_PRAGMA_CLANG(diagnostic push) \ + TOML_PRAGMA_CLANG(diagnostic ignored "-Wunknown-warning-option") \ + static_assert(true) + +#define TOML_DISABLE_SWITCH_WARNINGS \ + TOML_PRAGMA_CLANG(diagnostic ignored "-Wswitch") \ + static_assert(true) + +#define TOML_DISABLE_ARITHMETIC_WARNINGS \ + TOML_PRAGMA_CLANG(diagnostic ignored "-Wfloat-equal") \ + TOML_PRAGMA_CLANG(diagnostic ignored "-Wdouble-promotion") \ + TOML_PRAGMA_CLANG(diagnostic ignored "-Wchar-subscripts") \ + TOML_PRAGMA_CLANG(diagnostic ignored "-Wshift-sign-overflow") \ + static_assert(true) + +#define TOML_DISABLE_SPAM_WARNINGS \ + TOML_PRAGMA_CLANG_GE_9(diagnostic ignored "-Wctad-maybe-unsupported") \ + TOML_PRAGMA_CLANG_GE_10( \ + diagnostic ignored "-Wzero-as-null-pointer-constant" \ + ) \ + TOML_PRAGMA_CLANG_GE_11( \ + diagnostic ignored "-Wsuggest-destructor-override" \ + ) \ + TOML_PRAGMA_CLANG(diagnostic ignored "-Wweak-vtables") \ + TOML_PRAGMA_CLANG(diagnostic ignored "-Wweak-template-vtables") \ + TOML_PRAGMA_CLANG(diagnostic ignored "-Wdouble-promotion") \ + TOML_PRAGMA_CLANG(diagnostic ignored "-Wchar-subscripts") \ + TOML_PRAGMA_CLANG(diagnostic ignored "-Wmissing-field-initializers") \ + TOML_PRAGMA_CLANG(diagnostic ignored "-Wpadded") \ + static_assert(true) + +#define TOML_POP_WARNINGS \ + TOML_PRAGMA_CLANG(diagnostic pop) \ + static_assert(true) + +#define TOML_DISABLE_WARNINGS \ + TOML_PRAGMA_CLANG(diagnostic push) \ + TOML_PRAGMA_CLANG(diagnostic ignored "-Weverything") \ + static_assert(true, "") + +#define TOML_ENABLE_WARNINGS \ + TOML_PRAGMA_CLANG(diagnostic pop) \ + static_assert(true) #define TOML_SIMPLE_STATIC_ASSERT_MESSAGES 1 #elif TOML_MSVC -#define TOML_PUSH_WARNINGS \ - __pragma(warning(push)) \ - static_assert(true) +#define TOML_PUSH_WARNINGS __pragma(warning(push)) static_assert(true) -#if TOML_HAS_INCLUDE() +#if TOML_HAS_INCLUDE() #pragma warning(push, 0) #include #pragma warning(pop) -#define TOML_DISABLE_CODE_ANALYSIS_WARNINGS \ - __pragma(warning(disable : ALL_CODE_ANALYSIS_WARNINGS)) \ - static_assert(true) +#define TOML_DISABLE_CODE_ANALYSIS_WARNINGS \ + __pragma(warning(disable : ALL_CODE_ANALYSIS_WARNINGS)) static_assert(true) #else #define TOML_DISABLE_CODE_ANALYSIS_WARNINGS static_assert(true) #endif -#define TOML_DISABLE_SWITCH_WARNINGS \ - __pragma(warning(disable : 4061)) \ - __pragma(warning(disable : 4062)) \ - __pragma(warning(disable : 4063)) \ - __pragma(warning(disable : 5262)) /* switch-case implicit fallthrough (false-positive) */ \ - __pragma(warning(disable : 26819)) /* cg: unannotated fallthrough */ \ - static_assert(true) - -#define TOML_DISABLE_SPAM_WARNINGS \ - __pragma(warning(disable : 4127)) /* conditional expr is constant */ \ - __pragma(warning(disable : 4324)) /* structure was padded due to alignment specifier */ \ - __pragma(warning(disable : 4348)) \ - __pragma(warning(disable : 4464)) /* relative include path contains '..' */ \ - __pragma(warning(disable : 4505)) /* unreferenced local function removed */ \ - __pragma(warning(disable : 4514)) /* unreferenced inline function has been removed */ \ - __pragma(warning(disable : 4582)) /* constructor is not implicitly called */ \ - __pragma(warning(disable : 4619)) /* there is no warning number 'XXXX' */ \ - __pragma(warning(disable : 4623)) /* default constructor was implicitly defined as deleted */ \ - __pragma(warning(disable : 4625)) /* copy constructor was implicitly defined as deleted */ \ - __pragma(warning(disable : 4626)) /* assignment operator was implicitly defined as deleted */ \ - __pragma(warning(disable : 4710)) /* function not inlined */ \ - __pragma(warning(disable : 4711)) /* function selected for automatic expansion */ \ - __pragma(warning(disable : 4820)) /* N bytes padding added */ \ - __pragma(warning(disable : 4946)) /* reinterpret_cast used between related classes */ \ - __pragma(warning(disable : 5026)) /* move constructor was implicitly defined as deleted */ \ - __pragma(warning(disable : 5027)) /* move assignment operator was implicitly defined as deleted */ \ - __pragma(warning(disable : 5039)) /* potentially throwing function passed to 'extern "C"' function */ \ - __pragma(warning(disable : 5045)) /* Compiler will insert Spectre mitigation */ \ - __pragma(warning(disable : 5264)) /* const variable is not used (false-positive) */ \ - __pragma(warning(disable : 26451)) \ - __pragma(warning(disable : 26490)) \ - __pragma(warning(disable : 26495)) \ - __pragma(warning(disable : 26812)) \ - __pragma(warning(disable : 26819)) \ - static_assert(true) - -#define TOML_DISABLE_ARITHMETIC_WARNINGS \ - __pragma(warning(disable : 4365)) /* argument signed/unsigned mismatch */ \ - __pragma(warning(disable : 4738)) /* storing 32-bit float result in memory */ \ - __pragma(warning(disable : 5219)) /* implicit conversion from integral to float */ \ - static_assert(true) - -#define TOML_POP_WARNINGS \ - __pragma(warning(pop)) \ - static_assert(true) - -#define TOML_DISABLE_WARNINGS \ - __pragma(warning(push, 0)) \ - __pragma(warning(disable : 4348)) \ - __pragma(warning(disable : 4668)) \ - __pragma(warning(disable : 5105)) \ - __pragma(warning(disable : 5264)) \ - TOML_DISABLE_CODE_ANALYSIS_WARNINGS; \ - TOML_DISABLE_SWITCH_WARNINGS; \ - TOML_DISABLE_SPAM_WARNINGS; \ - TOML_DISABLE_ARITHMETIC_WARNINGS; \ - static_assert(true) +#define TOML_DISABLE_SWITCH_WARNINGS \ + __pragma(warning(disable : 4061)) __pragma(warning(disable : 4062)) \ + __pragma(warning(disable : 4063)) __pragma(warning(disable : 5262) \ + ) /* switch-case implicit fallthrough (false-positive) */ \ + __pragma(warning(disable : 26819)) /* cg: unannotated fallthrough */ \ + static_assert(true) + +#define TOML_DISABLE_SPAM_WARNINGS \ + __pragma(warning(disable : 4127)) /* conditional expr is constant */ \ + __pragma(warning(disable : 4324) \ + ) /* structure was padded due to alignment specifier */ \ + __pragma(warning(disable : 4348)) __pragma(warning(disable : 4464) \ + ) /* relative include path contains '..' */ \ + __pragma(warning(disable : 4505) \ + ) /* unreferenced local function removed */ \ + __pragma(warning(disable : 4514) \ + ) /* unreferenced inline function has been removed */ \ + __pragma(warning(disable : 4582) \ + ) /* constructor is not implicitly called */ \ + __pragma(warning(disable : 4619) \ + ) /* there is no warning number 'XXXX' */ \ + __pragma(warning(disable : 4623) \ + ) /* default constructor was implicitly defined as deleted */ \ + __pragma(warning(disable : 4625) \ + ) /* copy constructor was implicitly defined as deleted */ \ + __pragma(warning(disable : 4626) \ + ) /* assignment operator was implicitly defined as deleted */ \ + __pragma(warning(disable : 4710)) /* function not inlined */ \ + __pragma(warning(disable : 4711) \ + ) /* function selected for automatic expansion */ \ + __pragma(warning(disable : 4820)) /* N bytes padding added */ \ + __pragma(warning(disable : 4946) \ + ) /* reinterpret_cast used between related classes */ \ + __pragma(warning(disable : 5026) \ + ) /* move constructor was implicitly defined as deleted */ \ + __pragma(warning(disable : 5027) \ + ) /* move assignment operator was implicitly defined as deleted */ \ + __pragma(warning(disable : 5039) \ + ) /* potentially throwing function passed to 'extern "C"' function */ \ + __pragma(warning(disable : 5045) \ + ) /* Compiler will insert Spectre mitigation */ \ + __pragma(warning(disable : 5264) \ + ) /* const variable is not used (false-positive) */ \ + __pragma(warning(disable : 26451)) __pragma(warning(disable : 26490)) \ + __pragma(warning(disable : 26495)) \ + __pragma(warning(disable : 26812)) \ + __pragma(warning(disable : 26819)) static_assert(true) + +#define TOML_DISABLE_ARITHMETIC_WARNINGS \ + __pragma(warning(disable : 4365)) /* argument signed/unsigned mismatch */ \ + __pragma(warning(disable : 4738) \ + ) /* storing 32-bit float result in memory */ \ + __pragma(warning(disable : 5219) \ + ) /* implicit conversion from integral to float */ \ + static_assert(true) + +#define TOML_POP_WARNINGS __pragma(warning(pop)) static_assert(true) + +#define TOML_DISABLE_WARNINGS \ + __pragma(warning(push, 0)) __pragma(warning(disable : 4348)) \ + __pragma(warning(disable : 4668)) __pragma(warning(disable : 5105)) \ + __pragma(warning(disable : 5264)) \ + TOML_DISABLE_CODE_ANALYSIS_WARNINGS; \ + TOML_DISABLE_SWITCH_WARNINGS; \ + TOML_DISABLE_SPAM_WARNINGS; \ + TOML_DISABLE_ARITHMETIC_WARNINGS; \ + static_assert(true) #define TOML_ENABLE_WARNINGS TOML_POP_WARNINGS #elif TOML_ICC -#define TOML_PUSH_WARNINGS \ - __pragma(warning(push)) \ - static_assert(true) +#define TOML_PUSH_WARNINGS __pragma(warning(push)) static_assert(true) -#define TOML_DISABLE_SPAM_WARNINGS \ - __pragma(warning(disable : 82)) /* storage class is not first */ \ - __pragma(warning(disable : 111)) /* statement unreachable (false-positive) */ \ - __pragma(warning(disable : 869)) /* unreferenced parameter */ \ - __pragma(warning(disable : 1011)) /* missing return (false-positive) */ \ - __pragma(warning(disable : 2261)) /* assume expr side-effects discarded */ \ - static_assert(true) +#define TOML_DISABLE_SPAM_WARNINGS \ + __pragma(warning(disable : 82)) /* storage class is not first */ \ + __pragma(warning(disable : 111) \ + ) /* statement unreachable (false-positive) */ \ + __pragma(warning(disable : 869)) /* unreferenced parameter */ \ + __pragma(warning(disable : 1011) \ + ) /* missing return (false-positive) */ \ + __pragma(warning(disable : 2261) \ + ) /* assume expr side-effects discarded */ \ + static_assert(true) -#define TOML_POP_WARNINGS \ - __pragma(warning(pop)) \ - static_assert(true) +#define TOML_POP_WARNINGS __pragma(warning(pop)) static_assert(true) -#define TOML_DISABLE_WARNINGS \ - __pragma(warning(push, 0)) \ - TOML_DISABLE_SPAM_WARNINGS +#define TOML_DISABLE_WARNINGS \ + __pragma(warning(push, 0)) TOML_DISABLE_SPAM_WARNINGS -#define TOML_ENABLE_WARNINGS \ - __pragma(warning(pop)) \ - static_assert(true) +#define TOML_ENABLE_WARNINGS __pragma(warning(pop)) static_assert(true) #elif TOML_GCC -#define TOML_PUSH_WARNINGS \ - TOML_PRAGMA_GCC(diagnostic push) \ - static_assert(true) - -#define TOML_DISABLE_SWITCH_WARNINGS \ - TOML_PRAGMA_GCC(diagnostic ignored "-Wswitch") \ - TOML_PRAGMA_GCC(diagnostic ignored "-Wswitch-enum") \ - TOML_PRAGMA_GCC(diagnostic ignored "-Wswitch-default") \ - static_assert(true) - -#define TOML_DISABLE_ARITHMETIC_WARNINGS \ - TOML_PRAGMA_GCC(diagnostic ignored "-Wfloat-equal") \ - TOML_PRAGMA_GCC(diagnostic ignored "-Wsign-conversion") \ - TOML_PRAGMA_GCC(diagnostic ignored "-Wchar-subscripts") \ - static_assert(true) - -#define TOML_DISABLE_SUGGEST_ATTR_WARNINGS \ - TOML_PRAGMA_GCC(diagnostic ignored "-Wsuggest-attribute=const") \ - TOML_PRAGMA_GCC(diagnostic ignored "-Wsuggest-attribute=pure") \ - static_assert(true) - -#define TOML_DISABLE_SPAM_WARNINGS \ - TOML_PRAGMA_GCC(diagnostic ignored "-Wpadded") \ - TOML_PRAGMA_GCC(diagnostic ignored "-Wcast-align") \ - TOML_PRAGMA_GCC(diagnostic ignored "-Wcomment") \ - TOML_PRAGMA_GCC(diagnostic ignored "-Wtype-limits") \ - TOML_PRAGMA_GCC(diagnostic ignored "-Wuseless-cast") \ - TOML_PRAGMA_GCC(diagnostic ignored "-Wchar-subscripts") \ - TOML_PRAGMA_GCC(diagnostic ignored "-Wsubobject-linkage") \ - TOML_PRAGMA_GCC(diagnostic ignored "-Wmissing-field-initializers") \ - TOML_PRAGMA_GCC(diagnostic ignored "-Wmaybe-uninitialized") \ - TOML_PRAGMA_GCC(diagnostic ignored "-Wnoexcept") \ - TOML_PRAGMA_GCC(diagnostic ignored "-Wnull-dereference") \ - TOML_PRAGMA_GCC(diagnostic ignored "-Wduplicated-branches") \ - static_assert(true) - -#define TOML_POP_WARNINGS \ - TOML_PRAGMA_GCC(diagnostic pop) \ - static_assert(true) - -#define TOML_DISABLE_WARNINGS \ - TOML_PRAGMA_GCC(diagnostic push) \ - TOML_PRAGMA_GCC(diagnostic ignored "-Wall") \ - TOML_PRAGMA_GCC(diagnostic ignored "-Wextra") \ - TOML_PRAGMA_GCC(diagnostic ignored "-Wpedantic") \ - TOML_DISABLE_SWITCH_WARNINGS; \ - TOML_DISABLE_ARITHMETIC_WARNINGS; \ - TOML_DISABLE_SUGGEST_ATTR_WARNINGS; \ - TOML_DISABLE_SPAM_WARNINGS; \ - static_assert(true) - -#define TOML_ENABLE_WARNINGS \ - TOML_PRAGMA_GCC(diagnostic pop) \ - static_assert(true) +#define TOML_PUSH_WARNINGS \ + TOML_PRAGMA_GCC(diagnostic push) \ + static_assert(true) + +#define TOML_DISABLE_SWITCH_WARNINGS \ + TOML_PRAGMA_GCC(diagnostic ignored "-Wswitch") \ + TOML_PRAGMA_GCC(diagnostic ignored "-Wswitch-enum") \ + TOML_PRAGMA_GCC(diagnostic ignored "-Wswitch-default") \ + static_assert(true) + +#define TOML_DISABLE_ARITHMETIC_WARNINGS \ + TOML_PRAGMA_GCC(diagnostic ignored "-Wfloat-equal") \ + TOML_PRAGMA_GCC(diagnostic ignored "-Wsign-conversion") \ + TOML_PRAGMA_GCC(diagnostic ignored "-Wchar-subscripts") \ + static_assert(true) + +#define TOML_DISABLE_SUGGEST_ATTR_WARNINGS \ + TOML_PRAGMA_GCC(diagnostic ignored "-Wsuggest-attribute=const") \ + TOML_PRAGMA_GCC(diagnostic ignored "-Wsuggest-attribute=pure") \ + static_assert(true) + +#define TOML_DISABLE_SPAM_WARNINGS \ + TOML_PRAGMA_GCC(diagnostic ignored "-Wpadded") \ + TOML_PRAGMA_GCC(diagnostic ignored "-Wcast-align") \ + TOML_PRAGMA_GCC(diagnostic ignored "-Wcomment") \ + TOML_PRAGMA_GCC(diagnostic ignored "-Wtype-limits") \ + TOML_PRAGMA_GCC(diagnostic ignored "-Wuseless-cast") \ + TOML_PRAGMA_GCC(diagnostic ignored "-Wchar-subscripts") \ + TOML_PRAGMA_GCC(diagnostic ignored "-Wsubobject-linkage") \ + TOML_PRAGMA_GCC(diagnostic ignored "-Wmissing-field-initializers") \ + TOML_PRAGMA_GCC(diagnostic ignored "-Wmaybe-uninitialized") \ + TOML_PRAGMA_GCC(diagnostic ignored "-Wnoexcept") \ + TOML_PRAGMA_GCC(diagnostic ignored "-Wnull-dereference") \ + TOML_PRAGMA_GCC(diagnostic ignored "-Wduplicated-branches") \ + static_assert(true) + +#define TOML_POP_WARNINGS \ + TOML_PRAGMA_GCC(diagnostic pop) \ + static_assert(true) + +#define TOML_DISABLE_WARNINGS \ + TOML_PRAGMA_GCC(diagnostic push) \ + TOML_PRAGMA_GCC(diagnostic ignored "-Wall") \ + TOML_PRAGMA_GCC(diagnostic ignored "-Wextra") \ + TOML_PRAGMA_GCC(diagnostic ignored "-Wpedantic") \ + TOML_DISABLE_SWITCH_WARNINGS; \ + TOML_DISABLE_ARITHMETIC_WARNINGS; \ + TOML_DISABLE_SUGGEST_ATTR_WARNINGS; \ + TOML_DISABLE_SPAM_WARNINGS; \ + static_assert(true) + +#define TOML_ENABLE_WARNINGS \ + TOML_PRAGMA_GCC(diagnostic pop) \ + static_assert(true) #endif @@ -748,10 +780,12 @@ TOML_ATTR(noinline) #endif // header-only mode -#if !defined(TOML_HEADER_ONLY) && defined(TOML_ALL_INLINE) // was TOML_ALL_INLINE pre-2.0 +#if !defined(TOML_HEADER_ONLY) && \ + defined(TOML_ALL_INLINE) // was TOML_ALL_INLINE pre-2.0 #define TOML_HEADER_ONLY TOML_ALL_INLINE #endif -#if !defined(TOML_HEADER_ONLY) || (defined(TOML_HEADER_ONLY) && TOML_HEADER_ONLY) || TOML_INTELLISENSE +#if !defined(TOML_HEADER_ONLY) || \ + (defined(TOML_HEADER_ONLY) && TOML_HEADER_ONLY) || TOML_INTELLISENSE #undef TOML_HEADER_ONLY #define TOML_HEADER_ONLY 1 #endif @@ -768,12 +802,15 @@ TOML_ATTR(noinline) #define TOML_IMPLEMENTATION 0 #endif -// dll/shared lib function exports (legacy - TOML_API was the old name for this setting) -#if !defined(TOML_EXPORTED_MEMBER_FUNCTION) && !defined(TOML_EXPORTED_STATIC_FUNCTION) \ - && !defined(TOML_EXPORTED_FREE_FUNCTION) && !defined(TOML_EXPORTED_CLASS) && defined(TOML_API) +// dll/shared lib function exports (legacy - TOML_API was the old name for this +// setting) +#if !defined(TOML_EXPORTED_MEMBER_FUNCTION) && \ + !defined(TOML_EXPORTED_STATIC_FUNCTION) && \ + !defined(TOML_EXPORTED_FREE_FUNCTION) && !defined(TOML_EXPORTED_CLASS) && \ + defined(TOML_API) #define TOML_EXPORTED_MEMBER_FUNCTION TOML_API #define TOML_EXPORTED_STATIC_FUNCTION TOML_API -#define TOML_EXPORTED_FREE_FUNCTION TOML_API +#define TOML_EXPORTED_FREE_FUNCTION TOML_API #endif // dll/shared lib exports @@ -785,20 +822,20 @@ TOML_ATTR(noinline) #undef TOML_EXPORTED_FREE_FUNCTION #if TOML_WINDOWS #if TOML_IMPLEMENTATION -#define TOML_EXPORTED_CLASS __declspec(dllexport) +#define TOML_EXPORTED_CLASS __declspec(dllexport) #define TOML_EXPORTED_FREE_FUNCTION __declspec(dllexport) #else -#define TOML_EXPORTED_CLASS __declspec(dllimport) +#define TOML_EXPORTED_CLASS __declspec(dllimport) #define TOML_EXPORTED_FREE_FUNCTION __declspec(dllimport) #endif #ifndef TOML_CALLCONV #define TOML_CALLCONV __cdecl #endif #elif defined(__GNUC__) && __GNUC__ >= 4 -#define TOML_EXPORTED_CLASS __attribute__((visibility("default"))) +#define TOML_EXPORTED_CLASS __attribute__((visibility("default"))) #define TOML_EXPORTED_MEMBER_FUNCTION __attribute__((visibility("default"))) #define TOML_EXPORTED_STATIC_FUNCTION __attribute__((visibility("default"))) -#define TOML_EXPORTED_FREE_FUNCTION __attribute__((visibility("default"))) +#define TOML_EXPORTED_FREE_FUNCTION __attribute__((visibility("default"))) #endif #endif #ifndef TOML_EXPORTED_CLASS @@ -815,11 +852,14 @@ TOML_ATTR(noinline) #endif // experimental language features -#if !defined(TOML_ENABLE_UNRELEASED_FEATURES) && defined(TOML_UNRELEASED_FEATURES) // was TOML_UNRELEASED_FEATURES - // pre-3.0 +#if !defined(TOML_ENABLE_UNRELEASED_FEATURES) && \ + defined(TOML_UNRELEASED_FEATURES) // was TOML_UNRELEASED_FEATURES + // pre-3.0 #define TOML_ENABLE_UNRELEASED_FEATURES TOML_UNRELEASED_FEATURES #endif -#if (defined(TOML_ENABLE_UNRELEASED_FEATURES) && TOML_ENABLE_UNRELEASED_FEATURES) || TOML_INTELLISENSE +#if (defined(TOML_ENABLE_UNRELEASED_FEATURES) && \ + TOML_ENABLE_UNRELEASED_FEATURES) || \ + TOML_INTELLISENSE #undef TOML_ENABLE_UNRELEASED_FEATURES #define TOML_ENABLE_UNRELEASED_FEATURES 1 #endif @@ -828,32 +868,39 @@ TOML_ATTR(noinline) #endif // parser -#if !defined(TOML_ENABLE_PARSER) && defined(TOML_PARSER) // was TOML_PARSER pre-3.0 +#if !defined(TOML_ENABLE_PARSER) && \ + defined(TOML_PARSER) // was TOML_PARSER pre-3.0 #define TOML_ENABLE_PARSER TOML_PARSER #endif -#if !defined(TOML_ENABLE_PARSER) || (defined(TOML_ENABLE_PARSER) && TOML_ENABLE_PARSER) || TOML_INTELLISENSE +#if !defined(TOML_ENABLE_PARSER) || \ + (defined(TOML_ENABLE_PARSER) && TOML_ENABLE_PARSER) || TOML_INTELLISENSE #undef TOML_ENABLE_PARSER #define TOML_ENABLE_PARSER 1 #endif // formatters -#if !defined(TOML_ENABLE_FORMATTERS) || (defined(TOML_ENABLE_FORMATTERS) && TOML_ENABLE_FORMATTERS) || TOML_INTELLISENSE +#if !defined(TOML_ENABLE_FORMATTERS) || \ + (defined(TOML_ENABLE_FORMATTERS) && TOML_ENABLE_FORMATTERS) || \ + TOML_INTELLISENSE #undef TOML_ENABLE_FORMATTERS #define TOML_ENABLE_FORMATTERS 1 #endif // SIMD -#if !defined(TOML_ENABLE_SIMD) || (defined(TOML_ENABLE_SIMD) && TOML_ENABLE_SIMD) || TOML_INTELLISENSE +#if !defined(TOML_ENABLE_SIMD) || \ + (defined(TOML_ENABLE_SIMD) && TOML_ENABLE_SIMD) || TOML_INTELLISENSE #undef TOML_ENABLE_SIMD #define TOML_ENABLE_SIMD 1 #endif // windows compat -#if !defined(TOML_ENABLE_WINDOWS_COMPAT) && defined(TOML_WINDOWS_COMPAT) // was TOML_WINDOWS_COMPAT pre-3.0 +#if !defined(TOML_ENABLE_WINDOWS_COMPAT) && \ + defined(TOML_WINDOWS_COMPAT) // was TOML_WINDOWS_COMPAT pre-3.0 #define TOML_ENABLE_WINDOWS_COMPAT TOML_WINDOWS_COMPAT #endif -#if !defined(TOML_ENABLE_WINDOWS_COMPAT) || (defined(TOML_ENABLE_WINDOWS_COMPAT) && TOML_ENABLE_WINDOWS_COMPAT) \ - || TOML_INTELLISENSE +#if !defined(TOML_ENABLE_WINDOWS_COMPAT) || \ + (defined(TOML_ENABLE_WINDOWS_COMPAT) && TOML_ENABLE_WINDOWS_COMPAT) || \ + TOML_INTELLISENSE #undef TOML_ENABLE_WINDOWS_COMPAT #define TOML_ENABLE_WINDOWS_COMPAT 1 #endif @@ -900,7 +947,8 @@ TOML_ATTR(noinline) #ifndef TOML_MAX_NESTED_VALUES #define TOML_MAX_NESTED_VALUES 256 // this refers to the depth of nested values, e.g. inline tables and arrays. -// 256 is crazy high! if you're hitting this limit with real input, TOML is probably the wrong tool for the job... +// 256 is crazy high! if you're hitting this limit with real input, TOML is +// probably the wrong tool for the job... #endif #ifdef TOML_CHAR_8_STRINGS @@ -941,12 +989,14 @@ TOML_ENABLE_WARNINGS; #define TOML_ENABLE_FLOAT16 0 #endif -#if !defined(TOML_FLOAT_CHARCONV) && (TOML_GCC || TOML_CLANG || (TOML_ICC && !TOML_ICC_CL)) +#if !defined(TOML_FLOAT_CHARCONV) && \ + (TOML_GCC || TOML_CLANG || (TOML_ICC && !TOML_ICC_CL)) // not supported by any version of GCC or Clang as of 26/11/2020 // not supported by any version of ICC on Linux as of 11/01/2021 #define TOML_FLOAT_CHARCONV 0 #endif -#if !defined(TOML_INT_CHARCONV) && (defined(__EMSCRIPTEN__) || defined(__APPLE__)) +#if !defined(TOML_INT_CHARCONV) && \ + (defined(__EMSCRIPTEN__) || defined(__APPLE__)) // causes link errors on emscripten // causes Mac OS SDK version errors on some versions of Apple Clang #define TOML_INT_CHARCONV 0 @@ -960,7 +1010,7 @@ TOML_ENABLE_WARNINGS; #if (TOML_INT_CHARCONV || TOML_FLOAT_CHARCONV) && !TOML_HAS_INCLUDE() #undef TOML_INT_CHARCONV #undef TOML_FLOAT_CHARCONV -#define TOML_INT_CHARCONV 0 +#define TOML_INT_CHARCONV 0 #define TOML_FLOAT_CHARCONV 0 #endif @@ -969,19 +1019,21 @@ TOML_ENABLE_WARNINGS; #else #define TOML_REQUIRES(...) #endif -#define TOML_ENABLE_IF(...) , typename std::enable_if<(__VA_ARGS__), int>::type = 0 -#define TOML_CONSTRAINED_TEMPLATE(condition, ...) \ - template <__VA_ARGS__ TOML_ENABLE_IF(condition)> \ - TOML_REQUIRES(condition) -#define TOML_HIDDEN_CONSTRAINT(condition, ...) TOML_CONSTRAINED_TEMPLATE(condition, __VA_ARGS__) +#define TOML_ENABLE_IF(...) \ + , typename std::enable_if<(__VA_ARGS__), int>::type = 0 +#define TOML_CONSTRAINED_TEMPLATE(condition, ...) \ + template <__VA_ARGS__ TOML_ENABLE_IF(condition)> \ + TOML_REQUIRES(condition) +#define TOML_HIDDEN_CONSTRAINT(condition, ...) \ + TOML_CONSTRAINED_TEMPLATE(condition, __VA_ARGS__) -#if defined(__SIZEOF_FLOAT128__) && defined(__FLT128_MANT_DIG__) && defined(__LDBL_MANT_DIG__) \ - && __FLT128_MANT_DIG__ > __LDBL_MANT_DIG__ +#if defined(__SIZEOF_FLOAT128__) && defined(__FLT128_MANT_DIG__) && \ + defined(__LDBL_MANT_DIG__) && __FLT128_MANT_DIG__ > __LDBL_MANT_DIG__ #define TOML_FLOAT128 __float128 #endif #ifdef __SIZEOF_INT128__ -#define TOML_INT128 __int128_t +#define TOML_INT128 __int128_t #define TOML_UINT128 __uint128_t #endif @@ -1120,9 +1172,9 @@ TOML_DISABLE_SUGGEST_ATTR_WARNINGS; // misc warning false-positives #if TOML_MSVC -#pragma warning(disable : 5031) // #pragma warning(pop): likely mismatch +#pragma warning(disable : 5031) // #pragma warning(pop): likely mismatch #if TOML_SHARED_LIB -#pragma warning(disable : 4251) // dll exports for std lib types +#pragma warning(disable : 4251) // dll exports for std lib types #endif #elif TOML_CLANG TOML_PRAGMA_CLANG(diagnostic ignored "-Wheader-hygiene") @@ -1134,13 +1186,15 @@ TOML_PRAGMA_CLANG(diagnostic ignored "-Wreserved-identifier") #endif #endif -//******** impl/std_new.h ******************************************************************************************** +//******** impl/std_new.h +//******************************************************************************************** TOML_DISABLE_WARNINGS; #include TOML_ENABLE_WARNINGS; -#if (!defined(__apple_build_version__) && TOML_CLANG >= 8) || TOML_GCC >= 7 || TOML_ICC >= 1910 || TOML_MSVC >= 1914 +#if (!defined(__apple_build_version__) && TOML_CLANG >= 8) || TOML_GCC >= 7 || \ + TOML_ICC >= 1910 || TOML_MSVC >= 1914 #define TOML_LAUNDER(x) __builtin_launder(x) #elif defined(__cpp_lib_launder) && __cpp_lib_launder >= 201606 #define TOML_LAUNDER(x) std::launder(x) @@ -1148,52 +1202,54 @@ TOML_ENABLE_WARNINGS; #define TOML_LAUNDER(x) x #endif -//******** impl/std_string.h ***************************************************************************************** +//******** impl/std_string.h +//***************************************************************************************** TOML_DISABLE_WARNINGS; -#include #include +#include TOML_ENABLE_WARNINGS; -#if TOML_DOXYGEN \ - || (defined(__cpp_char8_t) && __cpp_char8_t >= 201811 && defined(__cpp_lib_char8_t) \ - && __cpp_lib_char8_t >= 201907) +#if TOML_DOXYGEN || \ + (defined(__cpp_char8_t) && __cpp_char8_t >= 201811 && \ + defined(__cpp_lib_char8_t) && __cpp_lib_char8_t >= 201907) #define TOML_HAS_CHAR8 1 #else #define TOML_HAS_CHAR8 0 #endif -namespace toml // non-abi namespace; this is not an error +namespace toml // non-abi namespace; this is not an error { - using namespace std::string_literals; - using namespace std::string_view_literals; -} + using namespace std::string_literals; + using namespace std::string_view_literals; +} // namespace toml #if TOML_ENABLE_WINDOWS_COMPAT TOML_IMPL_NAMESPACE_START { - TOML_NODISCARD - TOML_EXPORTED_FREE_FUNCTION - std::string narrow(std::wstring_view); + TOML_NODISCARD + TOML_EXPORTED_FREE_FUNCTION + std::string narrow(std::wstring_view); - TOML_NODISCARD - TOML_EXPORTED_FREE_FUNCTION - std::wstring widen(std::string_view); + TOML_NODISCARD + TOML_EXPORTED_FREE_FUNCTION + std::wstring widen(std::string_view); #if TOML_HAS_CHAR8 - TOML_NODISCARD - TOML_EXPORTED_FREE_FUNCTION - std::wstring widen(std::u8string_view); + TOML_NODISCARD + TOML_EXPORTED_FREE_FUNCTION + std::wstring widen(std::u8string_view); #endif } TOML_IMPL_NAMESPACE_END; -#endif // TOML_ENABLE_WINDOWS_COMPAT +#endif // TOML_ENABLE_WINDOWS_COMPAT -//******** impl/std_optional.h *************************************************************************************** +//******** impl/std_optional.h +//*************************************************************************************** TOML_DISABLE_WARNINGS; #if !TOML_HAS_CUSTOM_OPTIONAL_TYPE @@ -1205,30 +1261,31 @@ TOML_NAMESPACE_START { #if TOML_HAS_CUSTOM_OPTIONAL_TYPE - template - using optional = TOML_OPTIONAL_TYPE; + template + using optional = TOML_OPTIONAL_TYPE; #else - template - using optional = std::optional; + template + using optional = std::optional; #endif } TOML_NAMESPACE_END; -//******** impl/forward_declarations.h ******************************************************************************* +//******** impl/forward_declarations.h +//******************************************************************************* TOML_DISABLE_WARNINGS; -#include -#include -#include #include #include #include +#include +#include +#include +#include #include #include -#include #include TOML_ENABLE_WARNINGS; TOML_PUSH_WARNINGS; @@ -1243,13 +1300,18 @@ TOML_PUSH_WARNINGS; #endif #ifndef TOML_DISABLE_ENVIRONMENT_CHECKS -#define TOML_ENV_MESSAGE \ - "If you're seeing this error it's because you're building toml++ for an environment that doesn't conform to " \ - "one of the 'ground truths' assumed by the library. Essentially this just means that I don't have the " \ - "resources to test on more platforms, but I wish I did! You can try disabling the checks by defining " \ - "TOML_DISABLE_ENVIRONMENT_CHECKS, but your mileage may vary. Please consider filing an issue at " \ - "https://github.com/marzer/tomlplusplus/issues to help me improve support for your target environment. " \ - "Thanks!" +#define TOML_ENV_MESSAGE \ + "If you're seeing this error it's because you're building toml++ for an " \ + "environment that doesn't conform to " \ + "one of the 'ground truths' assumed by the library. Essentially this " \ + "just means that I don't have the " \ + "resources to test on more platforms, but I wish I did! You can try " \ + "disabling the checks by defining " \ + "TOML_DISABLE_ENVIRONMENT_CHECKS, but your mileage may vary. Please " \ + "consider filing an issue at " \ + "https://github.com/marzer/tomlplusplus/issues to help me improve " \ + "support for your target environment. " \ + "Thanks!" static_assert(CHAR_BIT == 8, TOML_ENV_MESSAGE); static_assert(FLT_RADIX == 2, TOML_ENV_MESSAGE); @@ -1260,77 +1322,78 @@ static_assert(std::numeric_limits::digits == 53, TOML_ENV_MESSAGE); static_assert(std::numeric_limits::digits10 == 15, TOML_ENV_MESSAGE); #undef TOML_ENV_MESSAGE -#endif // !TOML_DISABLE_ENVIRONMENT_CHECKS +#endif // !TOML_DISABLE_ENVIRONMENT_CHECKS -// undocumented forward declarations are hidden from doxygen because they fuck it up =/ +// undocumented forward declarations are hidden from doxygen because they fuck +// it up =/ -namespace toml // non-abi namespace; this is not an error +namespace toml // non-abi namespace; this is not an error { - using ::std::size_t; - using ::std::intptr_t; - using ::std::uintptr_t; - using ::std::ptrdiff_t; - using ::std::nullptr_t; - using ::std::int8_t; - using ::std::int16_t; - using ::std::int32_t; - using ::std::int64_t; - using ::std::uint8_t; - using ::std::uint16_t; - using ::std::uint32_t; - using ::std::uint64_t; - using ::std::uint_least32_t; - using ::std::uint_least64_t; -} + using ::std::int16_t; + using ::std::int32_t; + using ::std::int64_t; + using ::std::int8_t; + using ::std::intptr_t; + using ::std::nullptr_t; + using ::std::ptrdiff_t; + using ::std::size_t; + using ::std::uint16_t; + using ::std::uint32_t; + using ::std::uint64_t; + using ::std::uint8_t; + using ::std::uint_least32_t; + using ::std::uint_least64_t; + using ::std::uintptr_t; +} // namespace toml TOML_NAMESPACE_START { - struct date; - struct time; - struct time_offset; + struct date; + struct time; + struct time_offset; - TOML_ABI_NAMESPACE_BOOL(TOML_HAS_CUSTOM_OPTIONAL_TYPE, custopt, stdopt); - struct date_time; - TOML_ABI_NAMESPACE_END; + TOML_ABI_NAMESPACE_BOOL(TOML_HAS_CUSTOM_OPTIONAL_TYPE, custopt, stdopt); + struct date_time; + TOML_ABI_NAMESPACE_END; - struct source_position; - struct source_region; + struct source_position; + struct source_region; - class node; - template - class node_view; + class node; + template + class node_view; - class key; - class array; - class table; - template - class value; + class key; + class array; + class table; + template + class value; - class path; + class path; - class toml_formatter; - class json_formatter; - class yaml_formatter; + class toml_formatter; + class json_formatter; + class yaml_formatter; - TOML_ABI_NAMESPACE_BOOL(TOML_EXCEPTIONS, ex, noex); + TOML_ABI_NAMESPACE_BOOL(TOML_EXCEPTIONS, ex, noex); #if TOML_EXCEPTIONS - using parse_result = table; + using parse_result = table; #else - class parse_result; + class parse_result; #endif - TOML_ABI_NAMESPACE_END; // TOML_EXCEPTIONS + TOML_ABI_NAMESPACE_END; // TOML_EXCEPTIONS } TOML_NAMESPACE_END; TOML_IMPL_NAMESPACE_START { - using node_ptr = std::unique_ptr; + using node_ptr = std::unique_ptr; - TOML_ABI_NAMESPACE_BOOL(TOML_EXCEPTIONS, impl_ex, impl_noex); - class parser; - TOML_ABI_NAMESPACE_END; // TOML_EXCEPTIONS + TOML_ABI_NAMESPACE_BOOL(TOML_EXCEPTIONS, impl_ex, impl_noex); + class parser; + TOML_ABI_NAMESPACE_END; // TOML_EXCEPTIONS - // clang-format off + // clang-format off inline constexpr std::string_view control_char_escapes[] = { @@ -1382,7 +1445,7 @@ TOML_IMPL_NAMESPACE_START "date-time"sv }; - // clang-format on + // clang-format on } TOML_IMPL_NAMESPACE_END; @@ -1400,741 +1463,863 @@ namespace toml { } -TOML_NAMESPACE_START // abi namespace +TOML_NAMESPACE_START // abi namespace { - inline namespace literals - { - } - - enum class TOML_CLOSED_ENUM node_type : uint8_t - { - none, - table, - array, - string, - integer, - floating_point, - boolean, - date, - time, - date_time - }; - - template - inline std::basic_ostream& operator<<(std::basic_ostream& lhs, node_type rhs) - { - const auto str = impl::node_type_friendly_names[static_cast>(rhs)]; - using str_char_t = decltype(str)::value_type; - if constexpr (std::is_same_v) - return lhs << str; - else - { - if constexpr (sizeof(Char) == sizeof(str_char_t)) - return lhs << std::basic_string_view{ reinterpret_cast(str.data()), str.length() }; - else - return lhs << str.data(); - } - } - - enum class TOML_OPEN_FLAGS_ENUM value_flags : uint16_t // being an "OPEN" flags enum is not an error - { - none, - format_as_binary = 1, - format_as_octal = 2, - format_as_hexadecimal = 3, - }; - TOML_MAKE_FLAGS(value_flags); - - inline constexpr value_flags preserve_source_value_flags = - POXY_IMPLEMENTATION_DETAIL(value_flags{ static_cast>(-1) }); - - enum class TOML_CLOSED_FLAGS_ENUM format_flags : uint64_t - { - none, - quote_dates_and_times = (1ull << 0), - quote_infinities_and_nans = (1ull << 1), - allow_literal_strings = (1ull << 2), - allow_multi_line_strings = (1ull << 3), - allow_real_tabs_in_strings = (1ull << 4), - allow_unicode_strings = (1ull << 5), - allow_binary_integers = (1ull << 6), - allow_octal_integers = (1ull << 7), - allow_hexadecimal_integers = (1ull << 8), - indent_sub_tables = (1ull << 9), - indent_array_elements = (1ull << 10), - indentation = indent_sub_tables | indent_array_elements, - relaxed_float_precision = (1ull << 11), - terse_key_value_pairs = (1ull << 12), - }; - TOML_MAKE_FLAGS(format_flags); - - template - struct TOML_TRIVIAL_ABI inserter - { - static_assert(std::is_reference_v); - - T value; - }; - template - inserter(T&&) -> inserter; - template - inserter(T&) -> inserter; - - using default_formatter = toml_formatter; + inline namespace literals + { + } + + enum class TOML_CLOSED_ENUM node_type : uint8_t + { + none, + table, + array, + string, + integer, + floating_point, + boolean, + date, + time, + date_time + }; + + template + inline std::basic_ostream& operator<<( + std::basic_ostream& lhs, + node_type rhs + ) + { + const auto str = impl::node_type_friendly_names + [static_cast>(rhs)]; + using str_char_t = decltype(str)::value_type; + if constexpr (std::is_same_v) + return lhs << str; + else + { + if constexpr (sizeof(Char) == sizeof(str_char_t)) + return lhs << std::basic_string_view{ + reinterpret_cast(str.data()), + str.length() + }; + else + return lhs << str.data(); + } + } + + enum class TOML_OPEN_FLAGS_ENUM + value_flags : uint16_t // being an "OPEN" flags enum is not an error + { + none, + format_as_binary = 1, + format_as_octal = 2, + format_as_hexadecimal = 3, + }; + TOML_MAKE_FLAGS(value_flags); + + inline constexpr value_flags preserve_source_value_flags = + POXY_IMPLEMENTATION_DETAIL( + value_flags{static_cast>(-1)} + ); + + enum class TOML_CLOSED_FLAGS_ENUM format_flags : uint64_t + { + none, + quote_dates_and_times = (1ull << 0), + quote_infinities_and_nans = (1ull << 1), + allow_literal_strings = (1ull << 2), + allow_multi_line_strings = (1ull << 3), + allow_real_tabs_in_strings = (1ull << 4), + allow_unicode_strings = (1ull << 5), + allow_binary_integers = (1ull << 6), + allow_octal_integers = (1ull << 7), + allow_hexadecimal_integers = (1ull << 8), + indent_sub_tables = (1ull << 9), + indent_array_elements = (1ull << 10), + indentation = indent_sub_tables | indent_array_elements, + relaxed_float_precision = (1ull << 11), + terse_key_value_pairs = (1ull << 12), + }; + TOML_MAKE_FLAGS(format_flags); + + template + struct TOML_TRIVIAL_ABI inserter + { + static_assert(std::is_reference_v); + + T value; + }; + template + inserter(T&&) -> inserter; + template + inserter(T&) -> inserter; + + using default_formatter = toml_formatter; } TOML_NAMESPACE_END; TOML_IMPL_NAMESPACE_START { - template - using remove_cvref = std::remove_cv_t>; + template + using remove_cvref = std::remove_cv_t>; - template - using common_signed_type = std::common_type_t...>; + template + using common_signed_type = std::common_type_t...>; - template - inline constexpr bool is_one_of = (false || ... || std::is_same_v); + template + inline constexpr bool is_one_of = (false || ... || std::is_same_v); - template - inline constexpr bool all_integral = (std::is_integral_v && ...); + template + inline constexpr bool all_integral = (std::is_integral_v && ...); - template - inline constexpr bool is_cvref = std::is_reference_v || std::is_const_v || std::is_volatile_v; + template + inline constexpr bool is_cvref = + std::is_reference_v || std::is_const_v || std::is_volatile_v; - template - inline constexpr bool is_wide_string = - is_one_of, const wchar_t*, wchar_t*, std::wstring_view, std::wstring>; + template + inline constexpr bool is_wide_string = is_one_of< + std::decay_t, + const wchar_t*, + wchar_t*, + std::wstring_view, + std::wstring>; - template - inline constexpr bool value_retrieval_is_nothrow = !std::is_same_v, std::string> + template + inline constexpr bool value_retrieval_is_nothrow = + !std::is_same_v, std::string> #if TOML_HAS_CHAR8 - && !std::is_same_v, std::u8string> -#endif - - && !is_wide_string; - - template - struct copy_ref_; - template - using copy_ref = typename copy_ref_::type; - - template - struct copy_ref_ - { - using type = Dest; - }; - - template - struct copy_ref_ - { - using type = std::add_lvalue_reference_t; - }; - - template - struct copy_ref_ - { - using type = std::add_rvalue_reference_t; - }; - - template - struct copy_cv_; - template - using copy_cv = typename copy_cv_::type; - - template - struct copy_cv_ - { - using type = Dest; - }; - - template - struct copy_cv_ - { - using type = std::add_const_t; - }; - - template - struct copy_cv_ - { - using type = std::add_volatile_t; - }; - - template - struct copy_cv_ - { - using type = std::add_cv_t; - }; - - template - using copy_cvref = - copy_ref, std::remove_reference_t>, Dest>, Src>; - - template - inline constexpr bool dependent_false = false; - - template - inline constexpr bool first_is_same = false; - template - inline constexpr bool first_is_same = true; - - // general value traits - // (as they relate to their equivalent native TOML type) - template - struct value_traits - { - using native_type = void; - static constexpr bool is_native = false; - static constexpr bool is_losslessly_convertible_to_native = false; - static constexpr bool can_represent_native = false; - static constexpr bool can_partially_represent_native = false; - static constexpr auto type = node_type::none; - }; - - template - struct value_traits : value_traits - {}; - template - struct value_traits : value_traits - {}; - template - struct value_traits : value_traits - {}; - template - struct value_traits : value_traits - {}; - template - struct value_traits : value_traits - {}; - - // integer value_traits specializations - standard types - template - struct integer_limits - { - static constexpr auto min = (std::numeric_limits::min)(); - static constexpr auto max = (std::numeric_limits::max)(); - }; - template - struct integer_traits_base : integer_limits - { - using native_type = int64_t; - static constexpr bool is_native = std::is_same_v; - static constexpr bool is_signed = static_cast(-1) < T{}; // for impls not specializing std::is_signed - static constexpr auto type = node_type::integer; - static constexpr bool can_partially_represent_native = true; - }; - template - struct unsigned_integer_traits : integer_traits_base - { - static constexpr bool is_losslessly_convertible_to_native = integer_limits::max <= 9223372036854775807ULL; - static constexpr bool can_represent_native = false; - }; - template - struct signed_integer_traits : integer_traits_base - { - using native_type = int64_t; - static constexpr bool is_losslessly_convertible_to_native = - integer_limits::min >= (-9223372036854775807LL - 1LL) && integer_limits::max <= 9223372036854775807LL; - static constexpr bool can_represent_native = - integer_limits::min <= (-9223372036854775807LL - 1LL) && integer_limits::max >= 9223372036854775807LL; - }; - template ::is_signed> - struct integer_traits : signed_integer_traits - {}; - template - struct integer_traits : unsigned_integer_traits - {}; - template <> - struct value_traits : integer_traits - {}; - template <> - struct value_traits : integer_traits - {}; - template <> - struct value_traits : integer_traits - {}; - template <> - struct value_traits : integer_traits - {}; - template <> - struct value_traits : integer_traits - {}; - template <> - struct value_traits : integer_traits - {}; - template <> - struct value_traits : integer_traits - {}; - template <> - struct value_traits : integer_traits - {}; - template <> - struct value_traits : integer_traits - {}; - template <> - struct value_traits : integer_traits - {}; - static_assert(value_traits::is_native); - static_assert(value_traits::is_signed); - static_assert(value_traits::is_losslessly_convertible_to_native); - static_assert(value_traits::can_represent_native); - static_assert(value_traits::can_partially_represent_native); - - // integer value_traits specializations - non-standard types + && !std::is_same_v, std::u8string> +#endif + + && !is_wide_string; + + template + struct copy_ref_; + template + using copy_ref = typename copy_ref_::type; + + template + struct copy_ref_ + { + using type = Dest; + }; + + template + struct copy_ref_ + { + using type = std::add_lvalue_reference_t; + }; + + template + struct copy_ref_ + { + using type = std::add_rvalue_reference_t; + }; + + template + struct copy_cv_; + template + using copy_cv = typename copy_cv_::type; + + template + struct copy_cv_ + { + using type = Dest; + }; + + template + struct copy_cv_ + { + using type = std::add_const_t; + }; + + template + struct copy_cv_ + { + using type = std::add_volatile_t; + }; + + template + struct copy_cv_ + { + using type = std::add_cv_t; + }; + + template + using copy_cvref = copy_ref< + copy_ref< + copy_cv< + std::remove_reference_t, + std::remove_reference_t>, + Dest>, + Src>; + + template + inline constexpr bool dependent_false = false; + + template + inline constexpr bool first_is_same = false; + template + inline constexpr bool first_is_same = true; + + // general value traits + // (as they relate to their equivalent native TOML type) + template + struct value_traits + { + using native_type = void; + static constexpr bool is_native = false; + static constexpr bool is_losslessly_convertible_to_native = false; + static constexpr bool can_represent_native = false; + static constexpr bool can_partially_represent_native = false; + static constexpr auto type = node_type::none; + }; + + template + struct value_traits : value_traits + { + }; + template + struct value_traits : value_traits + { + }; + template + struct value_traits : value_traits + { + }; + template + struct value_traits : value_traits + { + }; + template + struct value_traits : value_traits + { + }; + + // integer value_traits specializations - standard types + template + struct integer_limits + { + static constexpr auto min = (std::numeric_limits::min)(); + static constexpr auto max = (std::numeric_limits::max)(); + }; + template + struct integer_traits_base : integer_limits + { + using native_type = int64_t; + static constexpr bool is_native = std::is_same_v; + static constexpr bool is_signed = + static_cast(-1) < + T{}; // for impls not specializing std::is_signed + static constexpr auto type = node_type::integer; + static constexpr bool can_partially_represent_native = true; + }; + template + struct unsigned_integer_traits : integer_traits_base + { + static constexpr bool is_losslessly_convertible_to_native = + integer_limits::max <= 9223372036854775807ULL; + static constexpr bool can_represent_native = false; + }; + template + struct signed_integer_traits : integer_traits_base + { + using native_type = int64_t; + static constexpr bool is_losslessly_convertible_to_native = + integer_limits::min >= (-9223372036854775807LL - 1LL) && + integer_limits::max <= 9223372036854775807LL; + static constexpr bool can_represent_native = + integer_limits::min <= (-9223372036854775807LL - 1LL) && + integer_limits::max >= 9223372036854775807LL; + }; + template ::is_signed> + struct integer_traits : signed_integer_traits + { + }; + template + struct integer_traits : unsigned_integer_traits + { + }; + template <> + struct value_traits : integer_traits + { + }; + template <> + struct value_traits : integer_traits + { + }; + template <> + struct value_traits : integer_traits + { + }; + template <> + struct value_traits : integer_traits + { + }; + template <> + struct value_traits : integer_traits + { + }; + template <> + struct value_traits : integer_traits + { + }; + template <> + struct value_traits : integer_traits + { + }; + template <> + struct value_traits : integer_traits + { + }; + template <> + struct value_traits : integer_traits + { + }; + template <> + struct value_traits : integer_traits + { + }; + static_assert(value_traits::is_native); + static_assert(value_traits::is_signed); + static_assert(value_traits::is_losslessly_convertible_to_native); + static_assert(value_traits::can_represent_native); + static_assert(value_traits::can_partially_represent_native); + + // integer value_traits specializations - non-standard types #ifdef TOML_INT128 - template <> - struct integer_limits - { - static constexpr TOML_INT128 max = - static_cast((TOML_UINT128{ 1u } << ((__SIZEOF_INT128__ * CHAR_BIT) - 1)) - 1); - static constexpr TOML_INT128 min = -max - TOML_INT128{ 1 }; - }; - template <> - struct integer_limits - { - static constexpr TOML_UINT128 min = TOML_UINT128{}; - static constexpr TOML_UINT128 max = (2u * static_cast(integer_limits::max)) + 1u; - }; - template <> - struct value_traits : integer_traits - {}; - template <> - struct value_traits : integer_traits - {}; + template <> + struct integer_limits + { + static constexpr TOML_INT128 max = static_cast( + (TOML_UINT128{1u} << ((__SIZEOF_INT128__ * CHAR_BIT) - 1)) - 1 + ); + static constexpr TOML_INT128 min = -max - TOML_INT128{1}; + }; + template <> + struct integer_limits + { + static constexpr TOML_UINT128 min = TOML_UINT128{}; + static constexpr TOML_UINT128 max = + (2u * static_cast(integer_limits::max)) + + 1u; + }; + template <> + struct value_traits : integer_traits + { + }; + template <> + struct value_traits : integer_traits + { + }; #endif #ifdef TOML_SMALL_INT_TYPE - template <> - struct value_traits : signed_integer_traits - {}; -#endif - - // floating-point traits base - template - struct float_traits_base - { - static constexpr auto type = node_type::floating_point; - using native_type = double; - static constexpr bool is_native = std::is_same_v; - static constexpr bool is_signed = true; - - static constexpr int bits = static_cast(sizeof(T) * CHAR_BIT); - static constexpr int digits = MantissaDigits; - static constexpr int digits10 = DecimalDigits; - - static constexpr bool is_losslessly_convertible_to_native = bits <= 64 // - && digits <= 53 // DBL_MANT_DIG - && digits10 <= 15; // DBL_DIG - - static constexpr bool can_represent_native = digits >= 53 // DBL_MANT_DIG - && digits10 >= 15; // DBL_DIG - - static constexpr bool can_partially_represent_native = digits > 0 && digits10 > 0; - }; - template - struct float_traits : float_traits_base::digits, std::numeric_limits::digits10> - {}; + template <> + struct value_traits + : signed_integer_traits + { + }; +#endif + + // floating-point traits base + template + struct float_traits_base + { + static constexpr auto type = node_type::floating_point; + using native_type = double; + static constexpr bool is_native = std::is_same_v; + static constexpr bool is_signed = true; + + static constexpr int bits = static_cast(sizeof(T) * CHAR_BIT); + static constexpr int digits = MantissaDigits; + static constexpr int digits10 = DecimalDigits; + + static constexpr bool is_losslessly_convertible_to_native = + bits <= 64 // + && digits <= 53 // DBL_MANT_DIG + && digits10 <= 15; // DBL_DIG + + static constexpr bool can_represent_native = + digits >= 53 // DBL_MANT_DIG + && digits10 >= 15; // DBL_DIG + + static constexpr bool can_partially_represent_native = + digits > 0 && digits10 > 0; + }; + template + struct float_traits : float_traits_base< + T, + std::numeric_limits::digits, + std::numeric_limits::digits10> + { + }; #if TOML_ENABLE_FLOAT16 - template <> - struct float_traits<_Float16> : float_traits_base<_Float16, __FLT16_MANT_DIG__, __FLT16_DIG__> - {}; + template <> + struct float_traits<_Float16> + : float_traits_base<_Float16, __FLT16_MANT_DIG__, __FLT16_DIG__> + { + }; #endif #ifdef TOML_FLOAT128 - template <> - struct float_traits : float_traits_base - {}; -#endif - - // floating-point traits - template <> - struct value_traits : float_traits - {}; - template <> - struct value_traits : float_traits - {}; - template <> - struct value_traits : float_traits - {}; + template <> + struct float_traits + : float_traits_base + { + }; +#endif + + // floating-point traits + template <> + struct value_traits : float_traits + { + }; + template <> + struct value_traits : float_traits + { + }; + template <> + struct value_traits : float_traits + { + }; #if TOML_ENABLE_FLOAT16 - template <> - struct value_traits<_Float16> : float_traits<_Float16> - {}; + template <> + struct value_traits<_Float16> : float_traits<_Float16> + { + }; #endif #ifdef TOML_FLOAT128 - template <> - struct value_traits : float_traits - {}; + template <> + struct value_traits : float_traits + { + }; #endif #ifdef TOML_SMALL_FLOAT_TYPE - template <> - struct value_traits : float_traits - {}; -#endif - static_assert(value_traits::is_native); - static_assert(value_traits::is_losslessly_convertible_to_native); - static_assert(value_traits::can_represent_native); - static_assert(value_traits::can_partially_represent_native); - - // string value_traits specializations - char-based strings - template - struct string_traits - { - using native_type = std::string; - static constexpr bool is_native = std::is_same_v; - static constexpr bool is_losslessly_convertible_to_native = true; - static constexpr bool can_represent_native = - !std::is_array_v && (!std::is_pointer_v || std::is_const_v>); - static constexpr bool can_partially_represent_native = can_represent_native; - static constexpr auto type = node_type::string; - }; - template <> - struct value_traits : string_traits - {}; - template <> - struct value_traits : string_traits - {}; - template <> - struct value_traits : string_traits - {}; - template - struct value_traits : string_traits - {}; - template <> - struct value_traits : string_traits - {}; - template - struct value_traits : string_traits - {}; - - // string value_traits specializations - char8_t-based strings + template <> + struct value_traits + : float_traits + { + }; +#endif + static_assert(value_traits::is_native); + static_assert(value_traits::is_losslessly_convertible_to_native); + static_assert(value_traits::can_represent_native); + static_assert(value_traits::can_partially_represent_native); + + // string value_traits specializations - char-based strings + template + struct string_traits + { + using native_type = std::string; + static constexpr bool is_native = std::is_same_v; + static constexpr bool is_losslessly_convertible_to_native = true; + static constexpr bool can_represent_native = + !std::is_array_v && (!std::is_pointer_v || + std::is_const_v>); + static constexpr bool can_partially_represent_native = + can_represent_native; + static constexpr auto type = node_type::string; + }; + template <> + struct value_traits : string_traits + { + }; + template <> + struct value_traits : string_traits + { + }; + template <> + struct value_traits : string_traits + { + }; + template + struct value_traits : string_traits + { + }; + template <> + struct value_traits : string_traits + { + }; + template + struct value_traits : string_traits + { + }; + + // string value_traits specializations - char8_t-based strings #if TOML_HAS_CHAR8 - template <> - struct value_traits : string_traits - {}; - template <> - struct value_traits : string_traits - {}; - template <> - struct value_traits : string_traits - {}; - template - struct value_traits : string_traits - {}; - template <> - struct value_traits : string_traits - {}; - template - struct value_traits : string_traits - {}; -#endif - - // string value_traits specializations - wchar_t-based strings on Windows + template <> + struct value_traits : string_traits + { + }; + template <> + struct value_traits : string_traits + { + }; + template <> + struct value_traits : string_traits + { + }; + template + struct value_traits : string_traits + { + }; + template <> + struct value_traits : string_traits + { + }; + template + struct value_traits : string_traits + { + }; +#endif + + // string value_traits specializations - wchar_t-based strings on Windows #if TOML_ENABLE_WINDOWS_COMPAT - template - struct wstring_traits - { - using native_type = std::string; - static constexpr bool is_native = false; - static constexpr bool is_losslessly_convertible_to_native = true; // narrow - static constexpr bool can_represent_native = std::is_same_v; // widen - static constexpr bool can_partially_represent_native = can_represent_native; - static constexpr auto type = node_type::string; - }; - template <> - struct value_traits : wstring_traits - {}; - template <> - struct value_traits : wstring_traits - {}; - template <> - struct value_traits : wstring_traits - {}; - template - struct value_traits : wstring_traits - {}; - template <> - struct value_traits : wstring_traits - {}; - template - struct value_traits : wstring_traits - {}; -#endif - - // other 'native' value_traits specializations - template - struct native_value_traits - { - using native_type = T; - static constexpr bool is_native = true; - static constexpr bool is_losslessly_convertible_to_native = true; - static constexpr bool can_represent_native = true; - static constexpr bool can_partially_represent_native = true; - static constexpr auto type = NodeType; - }; - template <> - struct value_traits : native_value_traits - {}; - template <> - struct value_traits : native_value_traits - {}; - template <> - struct value_traits