Skip to content

Commit

Permalink
minor refactoring to make ICC happy
Browse files Browse the repository at this point in the history
  • Loading branch information
marzer committed Jan 11, 2021
1 parent 18c269b commit 3db1e4e
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 52 deletions.
28 changes: 17 additions & 11 deletions include/toml++/toml_array.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,11 @@ TOML_IMPL_NAMESPACE_START

if constexpr (is_one_of<type, array, table>)
{
return new type{ std::forward<T>(val) };
return new type{ static_cast<T&&>(val) };
}
else if constexpr (is_native<type> && !std::is_same_v<remove_cvref_t<T>, type>)
{
return new value<type>{ static_cast<T&&>(val) };
}
else
{
Expand All @@ -195,16 +199,18 @@ TOML_IMPL_NAMESPACE_START
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>>;
if constexpr (is_wide_string<T>)
{
#if TOML_WINDOWS_COMPAT
return new value{ narrow(std::forward<T>(val)) };
return new value<value_type>{ narrow(static_cast<T&&>(val)) };
#else
static_assert(dependent_false<T>, "Evaluated unreachable branch!");
#endif
}
else
return new value{ std::forward<T>(val) };
return new value<value_type>{ static_cast<T&&>(val) };
}
}

Expand All @@ -221,13 +227,13 @@ TOML_IMPL_NAMESPACE_START
return static_cast<toml::node*>(nullptr);
}

return std::forward<T>(val).visit([](auto&& concrete) noexcept
return static_cast<T&&>(val).visit([](auto&& concrete) noexcept
{
return static_cast<toml::node*>(make_node_specialized(std::forward<decltype(concrete)>(concrete)));
});
}
else
return make_node_specialized(std::forward<T>(val));
return make_node_specialized(static_cast<T&&>(val));
}

template <typename T>
Expand Down Expand Up @@ -310,7 +316,7 @@ TOML_NAMESPACE_START
template <typename T>
void emplace_back_if_not_empty_view(T&& val) noexcept
{
if constexpr (impl::is_node_view<T>)
if constexpr (is_node_view<T>)
{
if (!val)
return;
Expand Down Expand Up @@ -511,7 +517,7 @@ TOML_NAMESPACE_START
template <typename ElemType>
iterator insert(const_iterator pos, ElemType&& val) noexcept
{
if constexpr (impl::is_node_view<ElemType>)
if constexpr (is_node_view<ElemType>)
{
if (!val)
return end();
Expand Down Expand Up @@ -561,7 +567,7 @@ TOML_NAMESPACE_START
template <typename ElemType>
iterator insert(const_iterator pos, size_t count, ElemType&& val) noexcept
{
if constexpr (impl::is_node_view<ElemType>)
if constexpr (is_node_view<ElemType>)
{
if (!val)
return end();
Expand Down Expand Up @@ -610,7 +616,7 @@ TOML_NAMESPACE_START
{
auto count = distance;
using deref_type = decltype(*first);
if constexpr (impl::is_node_view<deref_type>)
if constexpr (is_node_view<deref_type>)
{
for (auto it = first; it != last; it++)
if (!(*it))
Expand All @@ -623,7 +629,7 @@ TOML_NAMESPACE_START
size_t i = start_idx;
for (auto it = first; it != last; it++)
{
if constexpr (impl::is_node_view<deref_type>)
if constexpr (is_node_view<deref_type>)
{
if (!(*it))
continue;
Expand Down Expand Up @@ -769,7 +775,7 @@ TOML_NAMESPACE_START
void resize(size_t new_size, ElemType&& default_init_val) noexcept
{
static_assert(
!impl::is_node_view<ElemType>,
!is_node_view<ElemType>,
"The default element type argument to toml::array::resize may not be toml::node_view."
);

Expand Down
4 changes: 2 additions & 2 deletions include/toml++/toml_array.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ TOML_NAMESPACE_START

TOML_EXTERNAL_LINKAGE
array::array(const array& other) noexcept
: node{ other }
: node( other )
{
elements.reserve(other.elements.size());
for (const auto& elem : other)
Expand All @@ -54,7 +54,7 @@ TOML_NAMESPACE_START

TOML_EXTERNAL_LINKAGE
array::array(array&& other) noexcept
: node{ std::move(other) },
: node( std::move(other) ),
elements{ std::move(other.elements) }
{
#if TOML_LIFETIME_HOOKS
Expand Down
7 changes: 4 additions & 3 deletions include/toml++/toml_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -528,9 +528,6 @@ TOML_IMPL_NAMESPACE_START
template <> struct node_type_getter<void> { 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;

template <typename T>
inline constexpr bool is_node_view = is_one_of<impl::remove_cvref_t<T>, node_view<node>, node_view<const node>>;
}
TOML_IMPL_NAMESPACE_END

Expand Down Expand Up @@ -575,6 +572,10 @@ TOML_NAMESPACE_START
/// \brief Metafunction for determining if a type is 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>>;

/// \brief Metafunction for determining if a type is 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>>;
}
TOML_NAMESPACE_END

Expand Down
6 changes: 4 additions & 2 deletions include/toml++/toml_date_time.h
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,8 @@ TOML_NAMESPACE_START
TOML_NODISCARD_CTOR
constexpr date_time() noexcept
: date{},
time{}
time{},
offset{} // TINAE - icc bugfix
{}

/// \brief Constructs a local date-time.
Expand All @@ -323,7 +324,8 @@ TOML_NAMESPACE_START
TOML_NODISCARD_CTOR
constexpr date_time(toml::date d, toml::time t) noexcept
: date{ d },
time{ t }
time{ t },
offset{} // TINAE - icc bugfix
{}

/// \brief Constructs an offset date-time.
Expand Down
5 changes: 3 additions & 2 deletions include/toml++/toml_preprocessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -319,8 +319,9 @@ is no longer necessary.
#define TOML_MAY_THROW noexcept
#endif

#if TOML_GCC || TOML_CLANG
// fp charconv not in supported any version of gcc or clang as of 26/11/2020
#if 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(__EMSCRIPTEN__) || defined(__APPLE__)
Expand Down
4 changes: 2 additions & 2 deletions include/toml++/toml_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ TOML_NAMESPACE_START
"Insertion using wide-character keys is only supported on Windows with TOML_WINDOWS_COMPAT enabled."
);

if constexpr (impl::is_node_view<ValueType>)
if constexpr (is_node_view<ValueType>)
{
if (!val)
return { end(), false };
Expand Down Expand Up @@ -644,7 +644,7 @@ TOML_NAMESPACE_START
"Insertion using wide-character keys is only supported on Windows with TOML_WINDOWS_COMPAT enabled."
);

if constexpr (impl::is_node_view<ValueType>)
if constexpr (is_node_view<ValueType>)
{
if (!val)
return { end(), false };
Expand Down
4 changes: 2 additions & 2 deletions include/toml++/toml_table.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ TOML_NAMESPACE_START

TOML_EXTERNAL_LINKAGE
table::table(const table& other) noexcept
: node{ std::move(other) },
: node( other ),
inline_{ other.inline_ }
{
for (auto&& [k, v] : other)
Expand All @@ -55,7 +55,7 @@ TOML_NAMESPACE_START

TOML_EXTERNAL_LINKAGE
table::table(table&& other) noexcept
: node{ std::move(other) },
: node( std::move(other) ),
map{ std::move(other.map) },
inline_{ other.inline_ }
{
Expand Down
4 changes: 2 additions & 2 deletions include/toml++/toml_value.h
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ TOML_NAMESPACE_START
/// \brief Copy constructor.
TOML_NODISCARD_CTOR
value(const value& other) noexcept
: node{ other },
: node( other ),
val_{ other.val_ },
flags_{ other.flags_ }
{
Expand All @@ -262,7 +262,7 @@ TOML_NAMESPACE_START
/// \brief Move constructor.
TOML_NODISCARD_CTOR
value(value&& other) noexcept
: node{ std::move(other) },
: node( std::move(other) ),
val_{ std::move(other.val_) },
flags_{ other.flags_ }
{
Expand Down
Loading

0 comments on commit 3db1e4e

Please sign in to comment.