Skip to content

Commit

Permalink
Merge pull request #2034 from ArtemSarmini/gh-1920-gcc-10-incomplete-…
Browse files Browse the repository at this point in the history
…types

Templatize basic_json constructor from json_ref
  • Loading branch information
nlohmann authored Apr 13, 2020
2 parents b0a3883 + 70be975 commit 84f19d6
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 8 deletions.
13 changes: 13 additions & 0 deletions include/nlohmann/detail/meta/type_traits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,19 @@ template<typename> struct is_basic_json : std::false_type {};
NLOHMANN_BASIC_JSON_TPL_DECLARATION
struct is_basic_json<NLOHMANN_BASIC_JSON_TPL> : std::true_type {};

//////////////////////
// json_ref helpers //
//////////////////////

template <typename>
class json_ref;

template<typename>
struct is_json_ref : std::false_type {};

template <typename T>
struct is_json_ref<json_ref<T>> : std::true_type {};

//////////////////////////
// aliases for detected //
//////////////////////////
Expand Down
8 changes: 4 additions & 4 deletions include/nlohmann/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1773,10 +1773,10 @@ class basic_json
// other constructors and destructor //
///////////////////////////////////////

/// @private
basic_json(const detail::json_ref<basic_json>& ref)
: basic_json(ref.moved_or_copied())
{}
template <typename JsonRef,
detail::enable_if_t<detail::conjunction<detail::is_json_ref<JsonRef>,
std::is_same<typename JsonRef::value_type, basic_json>>::value, int> = 0 >
basic_json(const JsonRef& ref) : basic_json(ref.moved_or_copied()) {}

/*!
@brief copy constructor
Expand Down
21 changes: 17 additions & 4 deletions single_include/nlohmann/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2794,6 +2794,19 @@ template<typename> struct is_basic_json : std::false_type {};
NLOHMANN_BASIC_JSON_TPL_DECLARATION
struct is_basic_json<NLOHMANN_BASIC_JSON_TPL> : std::true_type {};

//////////////////////
// json_ref helpers //
//////////////////////

template <typename>
class json_ref;

template<typename>
struct is_json_ref : std::false_type {};

template <typename T>
struct is_json_ref<json_ref<T>> : std::true_type {};

//////////////////////////
// aliases for detected //
//////////////////////////
Expand Down Expand Up @@ -16632,10 +16645,10 @@ class basic_json
// other constructors and destructor //
///////////////////////////////////////

/// @private
basic_json(const detail::json_ref<basic_json>& ref)
: basic_json(ref.moved_or_copied())
{}
template <typename JsonRef,
detail::enable_if_t<detail::conjunction<detail::is_json_ref<JsonRef>,
std::is_same<typename JsonRef::value_type, basic_json>>::value, int> = 0 >
basic_json(const JsonRef& ref) : basic_json(ref.moved_or_copied()) {}

/*!
@brief copy constructor
Expand Down

0 comments on commit 84f19d6

Please sign in to comment.