Skip to content

Commit

Permalink
removed double-bracket requirement for toml::table constructor
Browse files Browse the repository at this point in the history
also:
- fixed incorrect `noexcept` specifications on many functions
- fixed missing `#include <initializer_list>`
- removed unnecessary uses of `final`
  • Loading branch information
marzer committed Oct 26, 2021
1 parent dbc0782 commit bd9944a
Show file tree
Hide file tree
Showing 37 changed files with 1,498 additions and 1,452 deletions.
2 changes: 1 addition & 1 deletion cpp.hint
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
#define TOML_TRIVIAL_ABI
#define TOML_ABSTRACT_BASE
#define TOML_EMPTY_BASES
#define TOML_MAY_THROW
#define TOML_CONSTRAINED_TEMPLATE(cond, ...) template <__VA_ARGS__>
#define TOML_LIKELY(...) (__VA_ARGS__)
#define TOML_UNLIKELY(...) (__VA_ARGS__)
#define TOML_NODISCARD
#define TOML_NODISCARD_CTOR
#define TOML_RETURNS_BY_THROWING
#define TOML_EXTERN_NOEXCEPT(...)
#define TOML_EXTERNAL_LINKAGE
#define TOML_INTERNAL_LINKAGE static
#define TOML_ANON_NAMESPACE_START namespace
Expand Down
8 changes: 4 additions & 4 deletions docs/pages/main_page.dox
Original file line number Diff line number Diff line change
Expand Up @@ -303,18 +303,18 @@

int main()
{
auto tbl = toml::table{{
auto tbl = toml::table{
{ "lib", "toml++" },
{ "cpp", toml::array{ 17, 20, "and beyond" } },
{ "toml", toml::array{ "1.0.0", "and beyond" } },
{ "repo", "https://github.com/marzer/tomlplusplus/" },
{ "author", toml::table{{
{ "author", toml::table{
{ "name", "Mark Gillard" },
{ "github", "https://github.com/marzer" },
{ "twitter", "https://twitter.com/marzer8789" }
}}
}
},
}};
};

// serializing as TOML
std::cout << "###### TOML ######" << "\n\n";
Expand Down
31 changes: 16 additions & 15 deletions include/toml++/impl/array.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,18 @@

#include "value.h"
#include "std_vector.h"
#include "std_initializer_list.h"
#include "make_node.h"
#include "header_start.h"

/// \cond
TOML_IMPL_NAMESPACE_START
{
template <bool IsConst>
class TOML_TRIVIAL_ABI array_iterator final
class TOML_TRIVIAL_ABI array_iterator
{
private:
template <bool C>
template <bool>
friend class array_iterator;
friend class TOML_NAMESPACE::array;

Expand Down Expand Up @@ -251,10 +252,10 @@ TOML_NAMESPACE_START
std::vector<std::unique_ptr<node>> elements;

TOML_API
void preinsertion_resize(size_t idx, size_t count) noexcept;
void preinsertion_resize(size_t idx, size_t count);

template <typename T>
void emplace_back_if_not_empty_view(T&& val) noexcept
void emplace_back_if_not_empty_view(T&& val)
{
if constexpr (is_node_view<T>)
{
Expand Down Expand Up @@ -308,7 +309,7 @@ TOML_NAMESPACE_START
/// \brief Copy constructor.
TOML_NODISCARD_CTOR
TOML_API
array(const array&) noexcept;
array(const array&);

/// \brief Move constructor.
TOML_NODISCARD_CTOR
Expand All @@ -317,7 +318,7 @@ TOML_NAMESPACE_START

/// \brief Copy-assignment operator.
TOML_API
array& operator=(const array&) noexcept;
array& operator=(const array&);

/// \brief Move-assignment operator.
TOML_API
Expand Down Expand Up @@ -356,7 +357,7 @@ TOML_NAMESPACE_START
/// \tparam ElemTypes One of the TOML node or value types (or a type promotable to one).
/// \param val The node or value used to initialize element 0.
/// \param vals The nodes or values used to initialize elements 1...N.
TOML_CONSTRAINED_TEMPLATE((sizeof...(ElemTypes) > 0 || !std::is_same_v<impl::remove_cvref_t<ElemType>, array>),
TOML_CONSTRAINED_TEMPLATE((sizeof...(ElemTypes) > 0 || !std::is_same_v<impl::remove_cvref<ElemType>, array>),
typename ElemType,
typename... ElemTypes)
TOML_NODISCARD_CTOR
Expand Down Expand Up @@ -594,7 +595,7 @@ TOML_NAMESPACE_START
/// \attention The return value will always be `end()` if the input value was an empty toml::node_view,
/// because no insertion can take place. This is the only circumstance in which this can occur.
template <typename ElemType>
iterator insert(const_iterator pos, ElemType&& val) noexcept
iterator insert(const_iterator pos, ElemType&& val)
{
if constexpr (is_node_view<ElemType>)
{
Expand Down Expand Up @@ -642,7 +643,7 @@ TOML_NAMESPACE_START
/// \attention The return value will always be `end()` if the input value was an empty toml::node_view,
/// because no insertion can take place. This is the only circumstance in which this can occur.
template <typename ElemType>
iterator insert(const_iterator pos, size_t count, ElemType&& val) noexcept
iterator insert(const_iterator pos, size_t count, ElemType&& val)
{
if constexpr (is_node_view<ElemType>)
{
Expand Down Expand Up @@ -682,7 +683,7 @@ TOML_NAMESPACE_START
/// \conditional_return{All objects in the range were empty toml::node_views}
/// A copy of pos
template <typename Iter>
iterator insert(const_iterator pos, Iter first, Iter last) noexcept
iterator insert(const_iterator pos, Iter first, Iter last)
{
const auto distance = std::distance(first, last);
if (distance <= 0)
Expand Down Expand Up @@ -732,7 +733,7 @@ TOML_NAMESPACE_START
/// \conditional_return{All objects in the list were empty toml::node_views}
/// A copy of pos
template <typename ElemType>
iterator insert(const_iterator pos, std::initializer_list<ElemType> ilist) noexcept
iterator insert(const_iterator pos, std::initializer_list<ElemType> ilist)
{
return insert(pos, ilist.begin(), ilist.end());
}
Expand Down Expand Up @@ -762,7 +763,7 @@ TOML_NAMESPACE_START
/// \remarks There is no difference between insert() and emplace()
/// for trivial value types (floats, ints, bools).
template <typename ElemType, typename... Args>
iterator emplace(const_iterator pos, Args&&... args) noexcept
iterator emplace(const_iterator pos, Args&&... args)
{
using type = impl::unwrap_node<ElemType>;
static_assert((impl::is_native<type> || impl::is_one_of<type, table, array>)&&!impl::is_cvref<type>,
Expand Down Expand Up @@ -848,7 +849,7 @@ TOML_NAMESPACE_START
/// \param new_size The number of elements the array will have after resizing.
/// \param default_init_val The node or value used to initialize new elements if the array needs to grow.
template <typename ElemType>
void resize(size_t new_size, ElemType&& default_init_val) noexcept
void resize(size_t new_size, ElemType&& default_init_val)
{
static_assert(!is_node_view<ElemType>,
"The default element type argument to toml::array::resize may not be toml::node_view.");
Expand Down Expand Up @@ -911,7 +912,7 @@ TOML_NAMESPACE_START
/// \attention No insertion takes place if the input value is an empty toml::node_view.
/// This is the only circumstance in which this can occur.
template <typename ElemType>
void push_back(ElemType&& val) noexcept
void push_back(ElemType&& val)
{
emplace_back_if_not_empty_view(static_cast<ElemType&&>(val));
}
Expand All @@ -938,7 +939,7 @@ TOML_NAMESPACE_START
/// \remarks There is no difference between push_back() and emplace_back()
/// For trivial value types (floats, ints, bools).
template <typename ElemType, typename... Args>
decltype(auto) emplace_back(Args&&... args) noexcept
decltype(auto) emplace_back(Args&&... args)
{
using type = impl::unwrap_node<ElemType>;
static_assert((impl::is_native<type> || impl::is_one_of<type, table, array>)&&!impl::is_cvref<type>,
Expand Down
6 changes: 3 additions & 3 deletions include/toml++/impl/array.inl
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ TOML_ANON_NAMESPACE_END;
TOML_NAMESPACE_START
{
TOML_EXTERNAL_LINKAGE
array::array(const array& other) noexcept //
array::array(const array& other) //
: node(other)
{
elements.reserve(other.elements.size());
Expand All @@ -66,7 +66,7 @@ TOML_NAMESPACE_START
}

TOML_EXTERNAL_LINKAGE
array& array::operator=(const array& rhs) noexcept
array& array::operator=(const array& rhs)
{
if (&rhs != this)
{
Expand All @@ -91,7 +91,7 @@ TOML_NAMESPACE_START
}

TOML_EXTERNAL_LINKAGE
void array::preinsertion_resize(size_t idx, size_t count) noexcept
void array::preinsertion_resize(size_t idx, size_t count)
{
TOML_ASSERT(idx <= elements.size());
TOML_ASSERT(count >= 1u);
Expand Down
6 changes: 3 additions & 3 deletions include/toml++/impl/default_formatter.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ TOML_NAMESPACE_START
/// operators of the TOML node types already print themselves out using this formatter.
///
/// \detail \cpp
/// auto tbl = toml::table{{
/// auto tbl = toml::table{
/// { "description", "This is some TOML, yo." },
/// { "fruit", toml::array{ "apple", "orange", "pear" } },
/// { "numbers", toml::array{ 1, 2, 3, 4, 5 } },
/// { "table", toml::table{{ { "foo", "bar" } }} }
/// }};
/// { "table", toml::table{ { "foo", "bar" } } }
/// };
///
/// // these two lines are equivalent:
/// std::cout << toml::default_formatter{ tbl } << "\n";
Expand Down
35 changes: 21 additions & 14 deletions include/toml++/impl/forward_declarations.h
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ TOML_NAMESPACE_END;
TOML_IMPL_NAMESPACE_START
{
template <typename T>
using remove_cvref_t = std::remove_cv_t<std::remove_reference_t<T>>;
using remove_cvref = std::remove_cv_t<std::remove_reference_t<T>>;

template <typename T, typename... U>
inline constexpr bool is_one_of = (false || ... || std::is_same_v<T, U>);
Expand All @@ -347,6 +347,14 @@ TOML_IMPL_NAMESPACE_START
inline constexpr bool is_wide_string =
is_one_of<std::decay_t<T>, const wchar_t*, wchar_t*, std::wstring_view, std::wstring>;

template <typename T>
static constexpr bool value_retrieval_is_nothrow = !std::is_same_v<remove_cvref<T>, std::string>
#if TOML_HAS_CHAR8
&& !std::is_same_v<remove_cvref<T>, std::u8string>
#endif

&& !is_wide_string<T>;

template <typename T>
inline constexpr bool dependent_false = false;

Expand Down Expand Up @@ -767,7 +775,7 @@ TOML_IMPL_NAMESPACE_START
static constexpr auto value = node_type::none;
};
template <typename T>
inline constexpr node_type node_type_of = node_type_getter<unwrap_node<remove_cvref_t<T>>>::value;
inline constexpr node_type node_type_of = node_type_getter<unwrap_node<remove_cvref<T>>>::value;
}
TOML_IMPL_NAMESPACE_END;
/// \endcond
Expand All @@ -776,47 +784,47 @@ TOML_NAMESPACE_START
{
/// \brief Metafunction for determining if a type is, or is a reference to, a toml::table.
template <typename T>
inline constexpr bool is_table = std::is_same_v<impl::remove_cvref_t<T>, table>;
inline constexpr bool is_table = std::is_same_v<impl::remove_cvref<T>, table>;

/// \brief Metafunction for determining if a type is, or is a reference to, a toml::array.
template <typename T>
inline constexpr bool is_array = std::is_same_v<impl::remove_cvref_t<T>, array>;
inline constexpr bool is_array = std::is_same_v<impl::remove_cvref<T>, array>;

/// \brief Metafunction for determining if a type satisfies either toml::is_table or toml::is_array.
template <typename T>
inline constexpr bool is_container = is_table<T> || is_array<T>;

/// \brief Metafunction for determining if a type is, or is a reference to, a std::string or toml::value<std::string>.
template <typename T>
inline constexpr bool is_string = std::is_same_v<impl::wrap_node<impl::remove_cvref_t<T>>, value<std::string>>;
inline constexpr bool is_string = std::is_same_v<impl::wrap_node<impl::remove_cvref<T>>, value<std::string>>;

/// \brief Metafunction for determining if a type is, or is a reference to, a int64_t or toml::value<int64_t>.
template <typename T>
inline constexpr bool is_integer = std::is_same_v<impl::wrap_node<impl::remove_cvref_t<T>>, value<int64_t>>;
inline constexpr bool is_integer = std::is_same_v<impl::wrap_node<impl::remove_cvref<T>>, value<int64_t>>;

/// \brief Metafunction for determining if a type is, or is a reference to, a double or toml::value<double>.
template <typename T>
inline constexpr bool is_floating_point = std::is_same_v<impl::wrap_node<impl::remove_cvref_t<T>>, value<double>>;
inline constexpr bool is_floating_point = std::is_same_v<impl::wrap_node<impl::remove_cvref<T>>, value<double>>;

/// \brief Metafunction for determining if a type satisfies either toml::is_integer or toml::is_floating_point.
template <typename T>
inline constexpr bool is_number = is_integer<T> || is_floating_point<T>;

/// \brief Metafunction for determining if a type is, or is a reference to, a bool or toml::value<bool>.
template <typename T>
inline constexpr bool is_boolean = std::is_same_v<impl::wrap_node<impl::remove_cvref_t<T>>, value<bool>>;
inline constexpr bool is_boolean = std::is_same_v<impl::wrap_node<impl::remove_cvref<T>>, value<bool>>;

/// \brief Metafunction for determining if a type is, or is a reference to, a toml::date or toml::value<date>.
template <typename T>
inline constexpr bool is_date = std::is_same_v<impl::wrap_node<impl::remove_cvref_t<T>>, value<date>>;
inline constexpr bool is_date = std::is_same_v<impl::wrap_node<impl::remove_cvref<T>>, value<date>>;

/// \brief Metafunction for determining if a type is, or is a reference to, a toml::time or toml::value<time>.
template <typename T>
inline constexpr bool is_time = std::is_same_v<impl::wrap_node<impl::remove_cvref_t<T>>, value<time>>;
inline constexpr bool is_time = std::is_same_v<impl::wrap_node<impl::remove_cvref<T>>, value<time>>;

/// \brief Metafunction for determining if a type is, or is a reference to, a toml::date_time or toml::value<date_time>.
template <typename T>
inline constexpr bool is_date_time = std::is_same_v<impl::wrap_node<impl::remove_cvref_t<T>>, value<date_time>>;
inline constexpr bool is_date_time = std::is_same_v<impl::wrap_node<impl::remove_cvref<T>>, value<date_time>>;

/// \brief Metafunction for determining if a type satisfies any of toml::is_date, toml::is_time or toml::is_date_time.
template <typename T>
Expand All @@ -829,12 +837,11 @@ TOML_NAMESPACE_START
/// \brief Metafunction for determining if a type is, or is a reference to, a toml::node (or one of its subclasses).
template <typename T>
inline constexpr bool is_node =
std::is_same_v<toml::node, impl::remove_cvref_t<T>> || std::is_base_of_v<toml::node, impl::remove_cvref_t<T>>;
std::is_same_v<toml::node, impl::remove_cvref<T>> || std::is_base_of_v<toml::node, impl::remove_cvref<T>>;

/// \brief Metafunction for determining if a type is, or is a reference to, a toml::node_view.
template <typename T>
inline constexpr bool is_node_view =
impl::is_one_of<impl::remove_cvref_t<T>, node_view<node>, node_view<const node>>;
inline constexpr bool is_node_view = impl::is_one_of<impl::remove_cvref<T>, node_view<node>, node_view<const node>>;
}
TOML_NAMESPACE_END;

Expand Down
19 changes: 9 additions & 10 deletions include/toml++/impl/make_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ TOML_IMPL_NAMESPACE_START
template <typename T>
TOML_NODISCARD
TOML_ATTR(returns_nonnull)
auto* make_node_specialized(T && val) noexcept
auto* make_node_specialized(T && val)
{
using type = unwrap_node<remove_cvref_t<T>>;
using type = unwrap_node<remove_cvref<T>>;
static_assert(!std::is_same_v<type, node>);
static_assert(!is_node_view<type>);

if constexpr (is_one_of<type, array, table>)
{
return new type{ static_cast<T&&>(val) };
}
else if constexpr (is_native<type> && !std::is_same_v<remove_cvref_t<T>, type>)
else if constexpr (is_native<type> && !std::is_same_v<remove_cvref<T>, type>)
{
return new value<type>{ static_cast<T&&>(val) };
}
Expand All @@ -35,7 +35,7 @@ TOML_IMPL_NAMESPACE_START
static_assert(is_native<type> || is_losslessly_convertible_to_native<type>,
"Value initializers must be (or be promotable to) one of the TOML value types");

using value_type = native_type_of<remove_cvref_t<T>>;
using value_type = native_type_of<remove_cvref<T>>;
if constexpr (is_wide_string<T>)
{
#if TOML_WINDOWS_COMPAT
Expand All @@ -51,9 +51,9 @@ TOML_IMPL_NAMESPACE_START

template <typename T>
TOML_NODISCARD
auto* make_node(T && val) noexcept
auto* make_node(T && val)
{
using type = unwrap_node<remove_cvref_t<T>>;
using type = unwrap_node<remove_cvref<T>>;
if constexpr (std::is_same_v<type, node> || is_node_view<type>)
{
if constexpr (is_node_view<type>)
Expand All @@ -63,7 +63,7 @@ TOML_IMPL_NAMESPACE_START
}

return static_cast<T&&>(val).visit(
[](auto&& concrete) noexcept {
[](auto&& concrete) {
return static_cast<toml::node*>(make_node_specialized(static_cast<decltype(concrete)&&>(concrete)));
});
}
Expand All @@ -73,7 +73,7 @@ TOML_IMPL_NAMESPACE_START

template <typename T>
TOML_NODISCARD
auto* make_node(inserter<T> && val) noexcept
auto* make_node(inserter<T> && val)
{
return make_node(static_cast<T&&>(val.value));
}
Expand Down Expand Up @@ -114,8 +114,7 @@ TOML_NAMESPACE_START
/// \note This will return toml::node for nodes and node_views, even though a more specific node subclass
/// would actually be inserted. There is no way around this in a compile-time metafunction.
template <typename T>
using inserted_type_of =
POXY_IMPLEMENTATION_DETAIL(typename impl::inserted_type_of_<impl::remove_cvref_t<T>>::type);
using inserted_type_of = POXY_IMPLEMENTATION_DETAIL(typename impl::inserted_type_of_<impl::remove_cvref<T>>::type);
}
TOML_NAMESPACE_END;

Expand Down
Loading

0 comments on commit bd9944a

Please sign in to comment.