Skip to content

Commit

Permalink
Merge pull request nlohmann#30 from nlohmann/develop
Browse files Browse the repository at this point in the history
Sync Fork from Upstream Repo
  • Loading branch information
sthagen authored Dec 17, 2020
2 parents a8f51bb + af8c6e7 commit 8c79dd6
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 37 deletions.
18 changes: 13 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ cmake_minimum_required(VERSION 3.1)
##
project(nlohmann_json VERSION 3.9.1 LANGUAGES CXX)

##
## MAIN_PROJECT CHECK
## determine if nlohmann_json is built as a subproject (using add_subdirectory) or if it is the main project
##
set(MAIN_PROJECT OFF)
if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
set(MAIN_PROJECT ON)
endif()

##
## INCLUDE
##
Expand All @@ -21,8 +30,8 @@ if (POLICY CMP0077)
cmake_policy(SET CMP0077 NEW)
endif ()

option(JSON_BuildTests "Build the unit tests when BUILD_TESTING is enabled." ON)
option(JSON_Install "Install CMake targets during install step." ON)
option(JSON_BuildTests "Build the unit tests when BUILD_TESTING is enabled." ${MAIN_PROJECT})
option(JSON_Install "Install CMake targets during install step." ${MAIN_PROJECT})
option(JSON_MultipleHeaders "Use non-amalgamated version of the library." OFF)
option(JSON_ImplicitConversions "Enable implicit conversions." ON)

Expand Down Expand Up @@ -101,9 +110,8 @@ CONFIGURE_FILE(
## TESTS
## create and configure the unit test target
##
include(CTest) #adds option BUILD_TESTING (default ON)

if(BUILD_TESTING AND JSON_BuildTests)
if (JSON_BuildTests)
include(CTest)
enable_testing()
add_subdirectory(test)
endif()
Expand Down
2 changes: 1 addition & 1 deletion include/nlohmann/detail/json_ref.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class json_ref

value_type const* operator->() const
{
return &**this;
return &** this;
}

private:
Expand Down
24 changes: 20 additions & 4 deletions include/nlohmann/detail/meta/cpp_future.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,32 @@

#include <cstddef> // size_t
#include <type_traits> // conditional, enable_if, false_type, integral_constant, is_constructible, is_integral, is_same, remove_cv, remove_reference, true_type
#include <utility> // index_sequence, make_index_sequence, index_sequence_for

#include <nlohmann/detail/macro_scope.hpp>

namespace nlohmann
{
namespace detail
{
// alias templates to reduce boilerplate
template<bool B, typename T = void>
using enable_if_t = typename std::enable_if<B, T>::type;

template<typename T>
using uncvref_t = typename std::remove_cv<typename std::remove_reference<T>::type>::type;

// implementation of C++14 index_sequence and affiliates
#ifdef JSON_HAS_CPP_14

// the following utilities are natively available in C++14
using std::enable_if_t;
using std::index_sequence;
using std::make_index_sequence;
using std::index_sequence_for;

#else

// alias templates to reduce boilerplate
template<bool B, typename T = void>
using enable_if_t = typename std::enable_if<B, T>::type;

// source: https://stackoverflow.com/a/32223343
template<std::size_t... Ints>
struct index_sequence
Expand Down Expand Up @@ -45,6 +58,8 @@ template<> struct make_index_sequence<1> : index_sequence<0> {};
template<typename... Ts>
using index_sequence_for = make_index_sequence<sizeof...(Ts)>;

#endif

// dispatch utility (taken from ranges-v3)
template<unsigned N> struct priority_tag : priority_tag < N - 1 > {};
template<> struct priority_tag<0> {};
Expand All @@ -58,5 +73,6 @@ struct static_const

template<typename T>
constexpr T static_const<T>::value;

} // namespace detail
} // namespace nlohmann
5 changes: 3 additions & 2 deletions include/nlohmann/detail/meta/type_traits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,9 @@ struct is_iterator_traits<iterator_traits<T>>
is_detected<reference_t, traits>::value;
};

// source: https://stackoverflow.com/a/37193089/4116453
// The following implementation of is_complete_type is taken from
// https://blogs.msdn.microsoft.com/vcblog/2015/12/02/partial-support-for-expression-sfinae-in-vs-2015-update-1/
// and is written by Xiang Fan who agreed to using it in this library.

template<typename T, typename = void>
struct is_complete_type : std::false_type {};
Expand All @@ -186,7 +188,6 @@ struct is_compatible_object_type_impl <
enable_if_t < is_detected<mapped_type_t, CompatibleObjectType>::value&&
is_detected<key_type_t, CompatibleObjectType>::value >>
{

using object_t = typename BasicJsonType::object_t;

// macOS's is_constructible does not play well with nonesuch...
Expand Down
12 changes: 6 additions & 6 deletions include/nlohmann/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -923,14 +923,14 @@ class basic_json
AllocatorType<T> alloc;
using AllocatorTraits = std::allocator_traits<AllocatorType<T>>;

auto deleter = [&](T * object)
auto deleter = [&](T * obj)
{
AllocatorTraits::deallocate(alloc, object, 1);
AllocatorTraits::deallocate(alloc, obj, 1);
};
std::unique_ptr<T, decltype(deleter)> object(AllocatorTraits::allocate(alloc, 1), deleter);
AllocatorTraits::construct(alloc, object.get(), std::forward<Args>(args)...);
JSON_ASSERT(object != nullptr);
return object.release();
std::unique_ptr<T, decltype(deleter)> obj(AllocatorTraits::allocate(alloc, 1), deleter);
AllocatorTraits::construct(alloc, obj.get(), std::forward<Args>(args)...);
JSON_ASSERT(obj != nullptr);
return obj.release();
}

////////////////////////
Expand Down
56 changes: 37 additions & 19 deletions single_include/nlohmann/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2736,19 +2736,33 @@ class other_error : public exception

#include <cstddef> // size_t
#include <type_traits> // conditional, enable_if, false_type, integral_constant, is_constructible, is_integral, is_same, remove_cv, remove_reference, true_type
#include <utility> // index_sequence, make_index_sequence, index_sequence_for

// #include <nlohmann/detail/macro_scope.hpp>


namespace nlohmann
{
namespace detail
{
// alias templates to reduce boilerplate
template<bool B, typename T = void>
using enable_if_t = typename std::enable_if<B, T>::type;

template<typename T>
using uncvref_t = typename std::remove_cv<typename std::remove_reference<T>::type>::type;

// implementation of C++14 index_sequence and affiliates
#ifdef JSON_HAS_CPP_14

// the following utilities are natively available in C++14
using std::enable_if_t;
using std::index_sequence;
using std::make_index_sequence;
using std::index_sequence_for;

#else

// alias templates to reduce boilerplate
template<bool B, typename T = void>
using enable_if_t = typename std::enable_if<B, T>::type;

// source: https://stackoverflow.com/a/32223343
template<std::size_t... Ints>
struct index_sequence
Expand Down Expand Up @@ -2779,6 +2793,8 @@ template<> struct make_index_sequence<1> : index_sequence<0> {};
template<typename... Ts>
using index_sequence_for = make_index_sequence<sizeof...(Ts)>;

#endif

// dispatch utility (taken from ranges-v3)
template<unsigned N> struct priority_tag : priority_tag < N - 1 > {};
template<> struct priority_tag<0> {};
Expand All @@ -2792,6 +2808,7 @@ struct static_const

template<typename T>
constexpr T static_const<T>::value;

} // namespace detail
} // namespace nlohmann

Expand Down Expand Up @@ -3174,7 +3191,9 @@ struct is_iterator_traits<iterator_traits<T>>
is_detected<reference_t, traits>::value;
};

// source: https://stackoverflow.com/a/37193089/4116453
// The following implementation of is_complete_type is taken from
// https://blogs.msdn.microsoft.com/vcblog/2015/12/02/partial-support-for-expression-sfinae-in-vs-2015-update-1/
// and is written by Xiang Fan who agreed to using it in this library.

template<typename T, typename = void>
struct is_complete_type : std::false_type {};
Expand All @@ -3192,7 +3211,6 @@ struct is_compatible_object_type_impl <
enable_if_t < is_detected<mapped_type_t, CompatibleObjectType>::value&&
is_detected<key_type_t, CompatibleObjectType>::value >>
{

using object_t = typename BasicJsonType::object_t;

// macOS's is_constructible does not play well with nonesuch...
Expand Down Expand Up @@ -4515,15 +4533,15 @@ class byte_container_with_subtype : public BinaryType
: container_type(std::move(b))
{}

byte_container_with_subtype(const container_type& b, std::uint8_t subtype) noexcept(noexcept(container_type(b)))
byte_container_with_subtype(const container_type& b, std::uint8_t subtype_) noexcept(noexcept(container_type(b)))
: container_type(b)
, m_subtype(subtype)
, m_subtype(subtype_)
, m_has_subtype(true)
{}

byte_container_with_subtype(container_type&& b, std::uint8_t subtype) noexcept(noexcept(container_type(std::move(b))))
byte_container_with_subtype(container_type&& b, std::uint8_t subtype_) noexcept(noexcept(container_type(std::move(b))))
: container_type(std::move(b))
, m_subtype(subtype)
, m_subtype(subtype_)
, m_has_subtype(true)
{}

Expand Down Expand Up @@ -4556,9 +4574,9 @@ class byte_container_with_subtype : public BinaryType

@since version 3.8.0
*/
void set_subtype(std::uint8_t subtype) noexcept
void set_subtype(std::uint8_t subtype_) noexcept
{
m_subtype = subtype;
m_subtype = subtype_;
m_has_subtype = true;
}

Expand Down Expand Up @@ -12645,7 +12663,7 @@ class json_ref

value_type const* operator->() const
{
return &**this;
return &** this;
}

private:
Expand Down Expand Up @@ -17495,14 +17513,14 @@ class basic_json
AllocatorType<T> alloc;
using AllocatorTraits = std::allocator_traits<AllocatorType<T>>;

auto deleter = [&](T * object)
auto deleter = [&](T * obj)
{
AllocatorTraits::deallocate(alloc, object, 1);
AllocatorTraits::deallocate(alloc, obj, 1);
};
std::unique_ptr<T, decltype(deleter)> object(AllocatorTraits::allocate(alloc, 1), deleter);
AllocatorTraits::construct(alloc, object.get(), std::forward<Args>(args)...);
JSON_ASSERT(object != nullptr);
return object.release();
std::unique_ptr<T, decltype(deleter)> obj(AllocatorTraits::allocate(alloc, 1), deleter);
AllocatorTraits::construct(alloc, obj.get(), std::forward<Args>(args)...);
JSON_ASSERT(obj != nullptr);
return obj.release();
}

////////////////////////
Expand Down

0 comments on commit 8c79dd6

Please sign in to comment.