//# This file is a part of toml++ and is subject to the the terms of the MIT license. //# Copyright (c) Mark Gillard //# See https://github.com/marzer/tomlplusplus/blob/master/LICENSE for the full license text. // SPDX-License-Identifier: MIT #pragma once #include "forward_declarations.h" #include "header_start.h" /// \cond TOML_IMPL_NAMESPACE_START { template TOML_NODISCARD TOML_ATTR(returns_nonnull) auto* make_node_specialized(T && val) noexcept { using type = unwrap_node>; static_assert(!std::is_same_v); static_assert(!is_node_view); if constexpr (is_one_of) { return new type{ static_cast(val) }; } else if constexpr (is_native && !std::is_same_v, type>) { return new value{ static_cast(val) }; } else { static_assert(!is_wide_string || TOML_WINDOWS_COMPAT, "Instantiating values from wide-character strings is only " "supported on Windows with TOML_WINDOWS_COMPAT enabled."); static_assert(is_native || is_losslessly_convertible_to_native, "Value initializers must be (or be promotable to) one of the TOML value types"); using value_type = native_type_of>; if constexpr (is_wide_string) { #if TOML_WINDOWS_COMPAT return new value{ narrow(static_cast(val)) }; #else static_assert(dependent_false, "Evaluated unreachable branch!"); #endif } else return new value{ static_cast(val) }; } } template TOML_NODISCARD auto* make_node(T && val) noexcept { using type = unwrap_node>; if constexpr (std::is_same_v || is_node_view) { if constexpr (is_node_view) { if (!val) return static_cast(nullptr); } return static_cast(val).visit( [](auto&& concrete) noexcept { return static_cast(make_node_specialized(static_cast(concrete))); }); } else return make_node_specialized(static_cast(val)); } template TOML_NODISCARD auto* make_node(inserter && val) noexcept { return make_node(static_cast(val.value)); } template || is_node_view || is_value || can_partially_represent_native)> struct inserted_type_of_ { using type = std::remove_pointer_t()))>; }; template struct inserted_type_of_, false> { using type = typename inserted_type_of_::type; }; template struct inserted_type_of_ { using type = void; }; } TOML_IMPL_NAMESPACE_END; /// \endcond TOML_NAMESPACE_START { /// \brief Metafunction for determining which node type would be constructed /// if an object of this type was inserted into a toml::table or toml::array. /// /// \detail \cpp /// static_assert(std::is_same_v, toml::value); /// static_assert(std::is_same_v, toml::value); /// static_assert(std::is_same_v, toml::value); /// static_assert(std::is_same_v, toml::value); /// \ecpp /// /// \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 using inserted_type_of = POXY_IMPLEMENTATION_DETAIL(typename impl::inserted_type_of_>::type); } TOML_NAMESPACE_END; #include "header_end.h"