mirror of
https://github.com/ToruNiina/toml11.git
synced 2025-09-16 16:28:09 +08:00
feat: workaround __cplusplus problem on MSVC
This commit is contained in:
@@ -272,7 +272,7 @@ BOOST_AUTO_TEST_CASE(test_construct_value_with_comments)
|
|||||||
BOOST_TEST(v.is_string());
|
BOOST_TEST(v.is_string());
|
||||||
BOOST_TEST(v.as_string() == "str");
|
BOOST_TEST(v.as_string() == "str");
|
||||||
}
|
}
|
||||||
#if __cplusplus >= 201703L
|
#if TOML11_CPLUSPLUS_STANDARD_VERSION >= 201703L
|
||||||
{
|
{
|
||||||
using namespace std::literals::string_view_literals;
|
using namespace std::literals::string_view_literals;
|
||||||
const value_type v("str"sv, {"comment1", "comment2"});
|
const value_type v("str"sv, {"comment1", "comment2"});
|
||||||
|
@@ -13,7 +13,7 @@
|
|||||||
#include <list>
|
#include <list>
|
||||||
#include <deque>
|
#include <deque>
|
||||||
#include <array>
|
#include <array>
|
||||||
#if __cplusplus >= 201703L
|
#if TOML11_CPLUSPLUS_STANDARD_VERSION >= 201703L
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
#endif
|
#endif
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
@@ -477,7 +477,7 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(test_find_string_type, value_type, test_value_type
|
|||||||
BOOST_TEST("foo" == moved);
|
BOOST_TEST("foo" == moved);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if __cplusplus >= 201703L
|
#if TOML11_CPLUSPLUS_STANDARD_VERSION >= 201703L
|
||||||
{
|
{
|
||||||
value_type v{{"key", toml::string("foo", toml::string_t::basic)}};
|
value_type v{{"key", toml::string("foo", toml::string_t::basic)}};
|
||||||
BOOST_TEST("foo" == toml::find<std::string_view>(v, "key"));
|
BOOST_TEST("foo" == toml::find<std::string_view>(v, "key"));
|
||||||
|
@@ -12,7 +12,7 @@
|
|||||||
#include <deque>
|
#include <deque>
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
#if __cplusplus >= 201703L
|
#if TOML11_CPLUSPLUS_STANDARD_VERSION >= 201703L
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@@ -12,7 +12,7 @@
|
|||||||
#include <deque>
|
#include <deque>
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
#if __cplusplus >= 201703L
|
#if TOML11_CPLUSPLUS_STANDARD_VERSION >= 201703L
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@@ -12,7 +12,7 @@
|
|||||||
#include <deque>
|
#include <deque>
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
#if __cplusplus >= 201703L
|
#if TOML11_CPLUSPLUS_STANDARD_VERSION >= 201703L
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -224,7 +224,7 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(test_get_string_type, value_type, test_value_types
|
|||||||
BOOST_TEST("foobar" == x);
|
BOOST_TEST("foobar" == x);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if __cplusplus >= 201703L
|
#if TOML11_CPLUSPLUS_STANDARD_VERSION >= 201703L
|
||||||
{
|
{
|
||||||
value_type v("foo", toml::string_t::basic);
|
value_type v("foo", toml::string_t::basic);
|
||||||
BOOST_TEST("foo" == toml::get<std::string_view>(v));
|
BOOST_TEST("foo" == toml::get<std::string_view>(v));
|
||||||
|
@@ -12,7 +12,7 @@
|
|||||||
#include <deque>
|
#include <deque>
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
#if __cplusplus >= 201703L
|
#if TOML11_CPLUSPLUS_STANDARD_VERSION >= 201703L
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@@ -133,7 +133,7 @@ BOOST_AUTO_TEST_CASE(test_string_add_assign)
|
|||||||
str += str2;
|
str += str2;
|
||||||
BOOST_TEST(str.str == "foobar");
|
BOOST_TEST(str.str == "foobar");
|
||||||
}
|
}
|
||||||
#if __cplusplus >= 201703L
|
#if TOML11_CPLUSPLUS_STANDARD_VERSION >= 201703L
|
||||||
// std::string_view
|
// std::string_view
|
||||||
{
|
{
|
||||||
toml::string str("foo");
|
toml::string str("foo");
|
||||||
|
@@ -9,7 +9,7 @@
|
|||||||
#include <map>
|
#include <map>
|
||||||
#include <list>
|
#include <list>
|
||||||
|
|
||||||
#if __cplusplus >= 201703L
|
#if TOML11_CPLUSPLUS_STANDARD_VERSION >= 201703L
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -423,7 +423,7 @@ BOOST_AUTO_TEST_CASE(test_value_string)
|
|||||||
BOOST_TEST(v2.as_boolean() == true);
|
BOOST_TEST(v2.as_boolean() == true);
|
||||||
BOOST_TEST(v3.as_boolean() == true);
|
BOOST_TEST(v3.as_boolean() == true);
|
||||||
|
|
||||||
#if __cplusplus >= 201703L
|
#if TOML11_CPLUSPLUS_STANDARD_VERSION >= 201703L
|
||||||
std::string_view sv = "foo";
|
std::string_view sv = "foo";
|
||||||
|
|
||||||
toml::value v7(sv);
|
toml::value v7(sv);
|
||||||
|
8
toml.hpp
8
toml.hpp
@@ -25,14 +25,6 @@
|
|||||||
#ifndef TOML_FOR_MODERN_CPP
|
#ifndef TOML_FOR_MODERN_CPP
|
||||||
#define TOML_FOR_MODERN_CPP
|
#define TOML_FOR_MODERN_CPP
|
||||||
|
|
||||||
#ifndef __cplusplus
|
|
||||||
# error "__cplusplus is not defined"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if __cplusplus < 201103L && _MSC_VER < 1900
|
|
||||||
# error "toml11 requires C++11 or later."
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define TOML11_VERSION_MAJOR 3
|
#define TOML11_VERSION_MAJOR 3
|
||||||
#define TOML11_VERSION_MINOR 7
|
#define TOML11_VERSION_MINOR 7
|
||||||
#define TOML11_VERSION_PATCH 0
|
#define TOML11_VERSION_PATCH 0
|
||||||
|
@@ -2,12 +2,15 @@
|
|||||||
// Distributed under the MIT License.
|
// Distributed under the MIT License.
|
||||||
#ifndef TOML11_STRING_HPP
|
#ifndef TOML11_STRING_HPP
|
||||||
#define TOML11_STRING_HPP
|
#define TOML11_STRING_HPP
|
||||||
|
|
||||||
|
#include "version.hpp"
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#if __cplusplus >= 201703L
|
#if TOML11_CPLUSPLUS_STANDARD_VERSION >= 201703L
|
||||||
#if __has_include(<string_view>)
|
#if __has_include(<string_view>)
|
||||||
#define TOML11_USING_STRING_VIEW 1
|
#define TOML11_USING_STRING_VIEW 1
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
|
@@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
#include "from.hpp"
|
#include "from.hpp"
|
||||||
#include "into.hpp"
|
#include "into.hpp"
|
||||||
|
#include "version.hpp"
|
||||||
|
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <forward_list>
|
#include <forward_list>
|
||||||
@@ -13,7 +14,7 @@
|
|||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
#if __cplusplus >= 201703L
|
#if TOML11_CPLUSPLUS_STANDARD_VERSION >= 201703L
|
||||||
#if __has_include(<string_view>)
|
#if __has_include(<string_view>)
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
#endif // has_include(<string_view>)
|
#endif // has_include(<string_view>)
|
||||||
@@ -146,7 +147,7 @@ struct has_specialized_into : decltype(has_specialized_into_impl::check<T>(nullp
|
|||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
// C++17 and/or/not
|
// C++17 and/or/not
|
||||||
|
|
||||||
#if __cplusplus >= 201703L
|
#if TOML11_CPLUSPLUS_STANDARD_VERSION >= 201703L
|
||||||
|
|
||||||
using std::conjunction;
|
using std::conjunction;
|
||||||
using std::disjunction;
|
using std::disjunction;
|
||||||
@@ -208,7 +209,7 @@ template<typename T>
|
|||||||
struct is_container : conjunction<
|
struct is_container : conjunction<
|
||||||
negation<is_map<T>>, // not a map
|
negation<is_map<T>>, // not a map
|
||||||
negation<std::is_same<T, std::string>>, // not a std::string
|
negation<std::is_same<T, std::string>>, // not a std::string
|
||||||
#if __cplusplus >= 201703L
|
#if TOML11_CPLUSPLUS_STANDARD_VERSION >= 201703L
|
||||||
#if __has_include(<string_view>)
|
#if __has_include(<string_view>)
|
||||||
negation<std::is_same<T, std::string_view>>, // not a std::string_view
|
negation<std::is_same<T, std::string_view>>, // not a std::string_view
|
||||||
#endif // has_include(<string_view>)
|
#endif // has_include(<string_view>)
|
||||||
@@ -233,7 +234,7 @@ struct is_basic_value<::toml::basic_value<C, M, V>>: std::true_type{};
|
|||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
// C++14 index_sequence
|
// C++14 index_sequence
|
||||||
|
|
||||||
#if __cplusplus >= 201402L
|
#if TOML11_CPLUSPLUS_STANDARD_VERSION >= 201402L
|
||||||
|
|
||||||
using std::index_sequence;
|
using std::index_sequence;
|
||||||
using std::make_index_sequence;
|
using std::make_index_sequence;
|
||||||
@@ -263,12 +264,12 @@ struct index_sequence_maker<0>
|
|||||||
template<std::size_t N>
|
template<std::size_t N>
|
||||||
using make_index_sequence = typename index_sequence_maker<N-1>::type;
|
using make_index_sequence = typename index_sequence_maker<N-1>::type;
|
||||||
|
|
||||||
#endif // __cplusplus >= 2014
|
#endif // cplusplus >= 2014
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
// C++14 enable_if_t
|
// C++14 enable_if_t
|
||||||
|
|
||||||
#if __cplusplus >= 201402L
|
#if TOML11_CPLUSPLUS_STANDARD_VERSION >= 201402L
|
||||||
|
|
||||||
using std::enable_if_t;
|
using std::enable_if_t;
|
||||||
|
|
||||||
@@ -277,12 +278,12 @@ using std::enable_if_t;
|
|||||||
template<bool B, typename T>
|
template<bool B, typename T>
|
||||||
using enable_if_t = typename std::enable_if<B, T>::type;
|
using enable_if_t = typename std::enable_if<B, T>::type;
|
||||||
|
|
||||||
#endif // __cplusplus >= 2014
|
#endif // cplusplus >= 2014
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
// return_type_of_t
|
// return_type_of_t
|
||||||
|
|
||||||
#if __cplusplus >= 201703L && defined(__cpp_lib_is_invocable) && __cpp_lib_is_invocable>=201703
|
#if TOML11_CPLUSPLUS_STANDARD_VERSION >= 201703L && defined(__cpp_lib_is_invocable) && __cpp_lib_is_invocable>=201703
|
||||||
|
|
||||||
template<typename F, typename ... Args>
|
template<typename F, typename ... Args>
|
||||||
using return_type_of_t = std::invoke_result_t<F, Args...>;
|
using return_type_of_t = std::invoke_result_t<F, Args...>;
|
||||||
|
@@ -7,8 +7,9 @@
|
|||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
#include "traits.hpp"
|
#include "traits.hpp"
|
||||||
|
#include "version.hpp"
|
||||||
|
|
||||||
#if __cplusplus >= 201402L
|
#if TOML11_CPLUSPLUS_STANDARD_VERSION >= 201402L
|
||||||
# define TOML11_MARK_AS_DEPRECATED(msg) [[deprecated(msg)]]
|
# define TOML11_MARK_AS_DEPRECATED(msg) [[deprecated(msg)]]
|
||||||
#elif defined(__GNUC__)
|
#elif defined(__GNUC__)
|
||||||
# define TOML11_MARK_AS_DEPRECATED(msg) __attribute__((deprecated(msg)))
|
# define TOML11_MARK_AS_DEPRECATED(msg) __attribute__((deprecated(msg)))
|
||||||
@@ -21,7 +22,7 @@
|
|||||||
namespace toml
|
namespace toml
|
||||||
{
|
{
|
||||||
|
|
||||||
#if __cplusplus >= 201402L
|
#if TOML11_CPLUSPLUS_STANDARD_VERSION >= 201402L
|
||||||
|
|
||||||
using std::make_unique;
|
using std::make_unique;
|
||||||
|
|
||||||
@@ -33,7 +34,7 @@ inline std::unique_ptr<T> make_unique(Ts&& ... args)
|
|||||||
return std::unique_ptr<T>(new T(std::forward<Ts>(args)...));
|
return std::unique_ptr<T>(new T(std::forward<Ts>(args)...));
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // __cplusplus >= 2014
|
#endif // TOML11_CPLUSPLUS_STANDARD_VERSION >= 2014
|
||||||
|
|
||||||
namespace detail
|
namespace detail
|
||||||
{
|
{
|
||||||
@@ -91,7 +92,7 @@ T from_string(const std::string& str, T opt)
|
|||||||
|
|
||||||
namespace detail
|
namespace detail
|
||||||
{
|
{
|
||||||
#if __cplusplus >= 201402L
|
#if TOML11_CPLUSPLUS_STANDARD_VERSION >= 201402L
|
||||||
template<typename T>
|
template<typename T>
|
||||||
decltype(auto) last_one(T&& tail) noexcept
|
decltype(auto) last_one(T&& tail) noexcept
|
||||||
{
|
{
|
||||||
|
42
toml/version.hpp
Normal file
42
toml/version.hpp
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
#ifndef TOML11_VERSION_HPP
|
||||||
|
#define TOML11_VERSION_HPP
|
||||||
|
|
||||||
|
// This file checks C++ version.
|
||||||
|
|
||||||
|
#ifndef __cplusplus
|
||||||
|
# error "__cplusplus is not defined"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Since MSVC does not define `__cplusplus` correctly unless you pass
|
||||||
|
// `/Zc:__cplusplus` when compiling, the workaround macros are added.
|
||||||
|
// Those enables you to define version manually or to use MSVC specific
|
||||||
|
// version macro automatically.
|
||||||
|
//
|
||||||
|
// The value of `__cplusplus` macro is defined in the C++ standard spec, but
|
||||||
|
// MSVC ignores the value, maybe because of backward compatibility. Instead,
|
||||||
|
// MSVC defines _MSVC_LANG that has the same value as __cplusplus defined in
|
||||||
|
// the C++ standard. First we check the manual version definition, and then
|
||||||
|
// we check if _MSVC_LANG is defined. If neither, use normal `__cplusplus`.
|
||||||
|
//
|
||||||
|
// FYI: https://docs.microsoft.com/en-us/cpp/build/reference/zc-cplusplus?view=msvc-170
|
||||||
|
// https://docs.microsoft.com/en-us/cpp/preprocessor/predefined-macros?view=msvc-170
|
||||||
|
//
|
||||||
|
#if defined(TOML11_ENFORCE_CXX11)
|
||||||
|
# define TOML11_CPLUSPLUS_STANDARD_VERSION 201103L
|
||||||
|
#elif defined(TOML11_ENFORCE_CXX14)
|
||||||
|
# define TOML11_CPLUSPLUS_STANDARD_VERSION 201402L
|
||||||
|
#elif defined(TOML11_ENFORCE_CXX17)
|
||||||
|
# define TOML11_CPLUSPLUS_STANDARD_VERSION 201703L
|
||||||
|
#elif defined(TOML11_ENFORCE_CXX20)
|
||||||
|
# define TOML11_CPLUSPLUS_STANDARD_VERSION 202002L
|
||||||
|
#elif defined(_MSVC_LANG)
|
||||||
|
# define TOML11_CPLUSPLUS_STANDARD_VERSION _MSVC_LANG
|
||||||
|
#else
|
||||||
|
# define TOML11_CPLUSPLUS_STANDARD_VERSION __cplusplus
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if TOML11_CPLUSPLUS_STANDARD_VERSION < 201103L
|
||||||
|
# error "toml11 requires C++11 or later."
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif// TOML11_VERSION_HPP
|
Reference in New Issue
Block a user