Skip to content

Commit

Permalink
reverted change to constexpr get_ref (does not work with GCC and MSVC)
Browse files Browse the repository at this point in the history
  • Loading branch information
nlohmann committed Jul 22, 2016
1 parent 4e7501e commit 51a3829
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
19 changes: 13 additions & 6 deletions src/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2806,16 +2806,23 @@ class basic_json
type of the current JSON
*/
template<typename ReferenceType, typename ThisType>
static constexpr ReferenceType get_ref_impl(ThisType& obj)
static ReferenceType get_ref_impl(ThisType& obj)
{
// helper type
using PointerType = typename std::add_pointer<ReferenceType>::type;

// delegate the call to get_ptr<>()
return obj.template get_ptr<PointerType>() != nullptr
? *obj.template get_ptr<PointerType>()
: throw std::domain_error("incompatible ReferenceType for get_ref, actual type is " +
obj.type_name());
auto ptr = obj.template get_ptr<PointerType>();

if (ptr != nullptr)
{
return *ptr;
}
else
{
throw std::domain_error("incompatible ReferenceType for get_ref, actual type is " +
obj.type_name());
}
}

public:
Expand Down Expand Up @@ -3043,7 +3050,7 @@ class basic_json
std::is_reference<ReferenceType>::value
and std::is_const<typename std::remove_reference<ReferenceType>::type>::value
, int>::type = 0>
constexpr ReferenceType get_ref() const
ReferenceType get_ref() const
{
// delegate call to get_ref_impl
return get_ref_impl<ReferenceType>(*this);
Expand Down
19 changes: 13 additions & 6 deletions src/json.hpp.re2c
Original file line number Diff line number Diff line change
Expand Up @@ -2806,16 +2806,23 @@ class basic_json
type of the current JSON
*/
template<typename ReferenceType, typename ThisType>
static constexpr ReferenceType get_ref_impl(ThisType& obj)
static ReferenceType get_ref_impl(ThisType& obj)
{
// helper type
using PointerType = typename std::add_pointer<ReferenceType>::type;

// delegate the call to get_ptr<>()
return obj.template get_ptr<PointerType>() != nullptr
? *obj.template get_ptr<PointerType>()
: throw std::domain_error("incompatible ReferenceType for get_ref, actual type is " +
obj.type_name());
auto ptr = obj.template get_ptr<PointerType>();

if (ptr != nullptr)
{
return *ptr;
}
else
{
throw std::domain_error("incompatible ReferenceType for get_ref, actual type is " +
obj.type_name());
}
}

public:
Expand Down Expand Up @@ -3043,7 +3050,7 @@ class basic_json
std::is_reference<ReferenceType>::value
and std::is_const<typename std::remove_reference<ReferenceType>::type>::value
, int>::type = 0>
constexpr ReferenceType get_ref() const
ReferenceType get_ref() const
{
// delegate call to get_ref_impl
return get_ref_impl<ReferenceType>(*this);
Expand Down

0 comments on commit 51a3829

Please sign in to comment.