Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/nlohmann/json into featu…
Browse files Browse the repository at this point in the history
…re/optional

� Conflicts:
�	test/src/unit-conversions.cpp
  • Loading branch information
nlohmann committed Dec 30, 2020
2 parents 5e55158 + a8398a7 commit ebb63bd
Show file tree
Hide file tree
Showing 20 changed files with 243 additions and 68 deletions.
50 changes: 49 additions & 1 deletion .github/workflows/ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,61 @@ name: Ubuntu
on: [push, pull_request]

jobs:
build:
gcc_build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1
- name: install_gcc
run: |
sudo apt update
sudo apt install gcc-10 g++-10
shell: bash
- name: cmake
run: cmake -S . -B build -D CMAKE_BUILD_TYPE=Debug -DJSON_BuildTests=On
env:
CC: gcc-10
CXX: g++-10
- name: build
run: cmake --build build --parallel 10
- name: test
run: cd build ; ctest -j 10 --output-on-failure

clang_build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1
- name: install_gcc
run: |
sudo apt update
sudo apt install clang-10
shell: bash
- name: cmake
run: cmake -S . -B build -D CMAKE_BUILD_TYPE=Debug -DJSON_BuildTests=On
env:
CC: clang-10
CXX: clang++-10
- name: build
run: cmake --build build --parallel 10
- name: test
run: cd build ; ctest -j 10 --output-on-failure

clang_build_cxx20:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1
- name: install_gcc
run: |
sudo apt update
sudo apt install clang-10
shell: bash
- name: cmake
run: cmake -S . -B build -D CMAKE_BUILD_TYPE=Debug -DJSON_BuildTests=On -DCMAKE_CXX_STANDARD=20 -DCMAKE_CXX_STANDARD_REQUIRED=ON
env:
CC: clang-10
CXX: clang++-10
- name: build
run: cmake --build build --parallel 10
- name: test
Expand Down
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ doctest:
# -Wno-missing-prototypes: for NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE
# -Wno-padded: padding is nothing to warn about
# -Wno-range-loop-analysis: items tests "for(const auto i...)"
# -Wno-extra-semi-stmt: spurious warnings for semicolons after JSON_ASSERT()
# -Wno-switch-enum -Wno-covered-switch-default: pedantic/contradicting warnings about switches
# -Wno-weak-vtables: exception class is defined inline, but has virtual method
pedantic_clang:
Expand All @@ -100,6 +101,7 @@ pedantic_clang:
-Wno-missing-prototypes \
-Wno-padded \
-Wno-range-loop-analysis \
-Wno-extra-semi-stmt \
-Wno-switch-enum -Wno-covered-switch-default \
-Wno-weak-vtables" cmake -S . -B cmake-build-pedantic -GNinja -DCMAKE_BUILD_TYPE=Debug -DJSON_MultipleHeaders=ON -DJSON_BuildTests=On
cmake --build cmake-build-pedantic
Expand Down
2 changes: 2 additions & 0 deletions include/nlohmann/detail/hash.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include <cstddef> // size_t, uint8_t
#include <functional> // hash

#include <nlohmann/detail/macro_scope.hpp>

namespace nlohmann
{
namespace detail
Expand Down
3 changes: 2 additions & 1 deletion include/nlohmann/detail/input/binary_reader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <limits> // numeric_limits
#include <string> // char_traits, string
#include <utility> // make_pair, move
#include <vector> // vector

#include <nlohmann/detail/exceptions.hpp>
#include <nlohmann/detail/input/input_adapters.hpp>
Expand Down Expand Up @@ -2340,7 +2341,7 @@ class binary_reader
break;
}
result.push_back(static_cast<typename string_t::value_type>(current));
};
}
return success;
}

Expand Down
32 changes: 27 additions & 5 deletions include/nlohmann/detail/input/input_adapters.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -371,15 +371,37 @@ typename iterator_input_adapter_factory<IteratorType>::adapter_type input_adapte
}

// Convenience shorthand from container to iterator
template<typename ContainerType>
auto input_adapter(const ContainerType& container) -> decltype(input_adapter(begin(container), end(container)))
// Enables ADL on begin(container) and end(container)
// Encloses the using declarations in namespace for not to leak them to outside scope

namespace container_input_adapter_factory_impl
{
// Enable ADL
using std::begin;
using std::end;

using std::begin;
using std::end;

template<typename ContainerType, typename Enable = void>
struct container_input_adapter_factory {};

template<typename ContainerType>
struct container_input_adapter_factory< ContainerType,
void_t<decltype(begin(std::declval<ContainerType>()), end(std::declval<ContainerType>()))>>
{
using adapter_type = decltype(input_adapter(begin(std::declval<ContainerType>()), end(std::declval<ContainerType>())));

static adapter_type create(const ContainerType& container)
{
return input_adapter(begin(container), end(container));
}
};

}

template<typename ContainerType>
typename container_input_adapter_factory_impl::container_input_adapter_factory<ContainerType>::adapter_type input_adapter(const ContainerType& container)
{
return container_input_adapter_factory_impl::container_input_adapter_factory<ContainerType>::create(container);
}

// Special cases with fast paths
inline file_input_adapter input_adapter(std::FILE* file)
Expand Down
6 changes: 3 additions & 3 deletions include/nlohmann/detail/input/lexer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1541,17 +1541,17 @@ class lexer : public lexer_base<BasicJsonType>
// literals
case 't':
{
std::array<char_type, 4> true_literal = {{'t', 'r', 'u', 'e'}};
std::array<char_type, 4> true_literal = {{char_type('t'), char_type('r'), char_type('u'), char_type('e')}};
return scan_literal(true_literal.data(), true_literal.size(), token_type::literal_true);
}
case 'f':
{
std::array<char_type, 5> false_literal = {{'f', 'a', 'l', 's', 'e'}};
std::array<char_type, 5> false_literal = {{char_type('f'), char_type('a'), char_type('l'), char_type('s'), char_type('e')}};
return scan_literal(false_literal.data(), false_literal.size(), token_type::literal_false);
}
case 'n':
{
std::array<char_type, 4> null_literal = {{'n', 'u', 'l', 'l'}};
std::array<char_type, 4> null_literal = {{char_type('n'), char_type('u'), char_type('l'), char_type('l')}};
return scan_literal(null_literal.data(), null_literal.size(), token_type::literal_null);
}

Expand Down
40 changes: 22 additions & 18 deletions include/nlohmann/detail/iterators/iter_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ This class implements a both iterators (iterator and const_iterator) for the
template<typename BasicJsonType>
class iter_impl
{
/// the iterator with BasicJsonType of different const-ness
using other_iter_impl = iter_impl<typename std::conditional<std::is_const<BasicJsonType>::value, typename std::remove_const<BasicJsonType>::type, const BasicJsonType>::type>;
/// allow basic_json to access private members
friend iter_impl<typename std::conditional<std::is_const<BasicJsonType>::value, typename std::remove_const<BasicJsonType>::type, const BasicJsonType>::type>;
friend other_iter_impl;
friend BasicJsonType;
friend iteration_proxy<iter_impl>;
friend iteration_proxy_value<iter_impl>;
Expand Down Expand Up @@ -390,10 +392,11 @@ class iter_impl
}

/*!
@brief comparison: equal
@brief comparison: equal
@pre The iterator is initialized; i.e. `m_object != nullptr`.
*/
bool operator==(const iter_impl& other) const
template < typename IterImpl, detail::enable_if_t < (std::is_same<IterImpl, iter_impl>::value || std::is_same<IterImpl, other_iter_impl>::value), std::nullptr_t > = nullptr >
bool operator==(const IterImpl& other) const
{
// if objects are not the same, the comparison is undefined
if (JSON_HEDLEY_UNLIKELY(m_object != other.m_object))
Expand All @@ -417,16 +420,17 @@ class iter_impl
}

/*!
@brief comparison: not equal
@brief comparison: not equal
@pre The iterator is initialized; i.e. `m_object != nullptr`.
*/
bool operator!=(const iter_impl& other) const
template < typename IterImpl, detail::enable_if_t < (std::is_same<IterImpl, iter_impl>::value || std::is_same<IterImpl, other_iter_impl>::value), std::nullptr_t > = nullptr >
bool operator!=(const IterImpl& other) const
{
return !operator==(other);
}

/*!
@brief comparison: smaller
@brief comparison: smaller
@pre The iterator is initialized; i.e. `m_object != nullptr`.
*/
bool operator<(const iter_impl& other) const
Expand All @@ -453,7 +457,7 @@ class iter_impl
}

/*!
@brief comparison: less than or equal
@brief comparison: less than or equal
@pre The iterator is initialized; i.e. `m_object != nullptr`.
*/
bool operator<=(const iter_impl& other) const
Expand All @@ -462,7 +466,7 @@ class iter_impl
}

/*!
@brief comparison: greater than
@brief comparison: greater than
@pre The iterator is initialized; i.e. `m_object != nullptr`.
*/
bool operator>(const iter_impl& other) const
Expand All @@ -471,7 +475,7 @@ class iter_impl
}

/*!
@brief comparison: greater than or equal
@brief comparison: greater than or equal
@pre The iterator is initialized; i.e. `m_object != nullptr`.
*/
bool operator>=(const iter_impl& other) const
Expand All @@ -480,7 +484,7 @@ class iter_impl
}

/*!
@brief add to iterator
@brief add to iterator
@pre The iterator is initialized; i.e. `m_object != nullptr`.
*/
iter_impl& operator+=(difference_type i)
Expand Down Expand Up @@ -509,7 +513,7 @@ class iter_impl
}

/*!
@brief subtract from iterator
@brief subtract from iterator
@pre The iterator is initialized; i.e. `m_object != nullptr`.
*/
iter_impl& operator-=(difference_type i)
Expand All @@ -518,7 +522,7 @@ class iter_impl
}

/*!
@brief add to iterator
@brief add to iterator
@pre The iterator is initialized; i.e. `m_object != nullptr`.
*/
iter_impl operator+(difference_type i) const
Expand All @@ -529,7 +533,7 @@ class iter_impl
}

/*!
@brief addition of distance and iterator
@brief addition of distance and iterator
@pre The iterator is initialized; i.e. `m_object != nullptr`.
*/
friend iter_impl operator+(difference_type i, const iter_impl& it)
Expand All @@ -540,7 +544,7 @@ class iter_impl
}

/*!
@brief subtract from iterator
@brief subtract from iterator
@pre The iterator is initialized; i.e. `m_object != nullptr`.
*/
iter_impl operator-(difference_type i) const
Expand All @@ -551,7 +555,7 @@ class iter_impl
}

/*!
@brief return difference
@brief return difference
@pre The iterator is initialized; i.e. `m_object != nullptr`.
*/
difference_type operator-(const iter_impl& other) const
Expand All @@ -572,7 +576,7 @@ class iter_impl
}

/*!
@brief access to successor
@brief access to successor
@pre The iterator is initialized; i.e. `m_object != nullptr`.
*/
reference operator[](difference_type n) const
Expand Down Expand Up @@ -603,7 +607,7 @@ class iter_impl
}

/*!
@brief return the key of an object iterator
@brief return the key of an object iterator
@pre The iterator is initialized; i.e. `m_object != nullptr`.
*/
const typename object_t::key_type& key() const
Expand All @@ -619,7 +623,7 @@ class iter_impl
}

/*!
@brief return the value of an iterator
@brief return the value of an iterator
@pre The iterator is initialized; i.e. `m_object != nullptr`.
*/
reference value() const
Expand Down
2 changes: 2 additions & 0 deletions include/nlohmann/detail/iterators/primitive_iterator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include <cstddef> // ptrdiff_t
#include <limits> // numeric_limits

#include <nlohmann/detail/macro_scope.hpp>

namespace nlohmann
{
namespace detail
Expand Down
1 change: 1 addition & 0 deletions include/nlohmann/detail/meta/type_traits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <limits> // numeric_limits
#include <type_traits> // false_type, is_constructible, is_integral, is_same, true_type
#include <utility> // declval
#include <tuple> // tuple

#include <nlohmann/detail/iterators/iterator_traits.hpp>
#include <nlohmann/detail/macro_scope.hpp>
Expand Down
2 changes: 2 additions & 0 deletions include/nlohmann/thirdparty/hedley/hedley_undef.hpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#pragma once

#undef JSON_HEDLEY_ALWAYS_INLINE
#undef JSON_HEDLEY_ARM_VERSION
#undef JSON_HEDLEY_ARM_VERSION_CHECK
Expand Down

0 comments on commit ebb63bd

Please sign in to comment.