Skip to content

Commit c2d50d6

Browse files
committed
Merge remote-tracking branch 'origin/develop' into feature/templated_define_type_macroses
# Conflicts: # test/src/unit-udt_macro.cpp
2 parents ee88c8c + a8398a7 commit c2d50d6

22 files changed

+258
-75
lines changed

.github/workflows/ubuntu.yml

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,61 @@ name: Ubuntu
33
on: [push, pull_request]
44

55
jobs:
6-
build:
6+
gcc_build:
77
runs-on: ubuntu-latest
88

99
steps:
1010
- uses: actions/checkout@v1
11+
- name: install_gcc
12+
run: |
13+
sudo apt update
14+
sudo apt install gcc-10 g++-10
15+
shell: bash
1116
- name: cmake
1217
run: cmake -S . -B build -D CMAKE_BUILD_TYPE=Debug -DJSON_BuildTests=On
18+
env:
19+
CC: gcc-10
20+
CXX: g++-10
21+
- name: build
22+
run: cmake --build build --parallel 10
23+
- name: test
24+
run: cd build ; ctest -j 10 --output-on-failure
25+
26+
clang_build:
27+
runs-on: ubuntu-latest
28+
29+
steps:
30+
- uses: actions/checkout@v1
31+
- name: install_gcc
32+
run: |
33+
sudo apt update
34+
sudo apt install clang-10
35+
shell: bash
36+
- name: cmake
37+
run: cmake -S . -B build -D CMAKE_BUILD_TYPE=Debug -DJSON_BuildTests=On
38+
env:
39+
CC: clang-10
40+
CXX: clang++-10
41+
- name: build
42+
run: cmake --build build --parallel 10
43+
- name: test
44+
run: cd build ; ctest -j 10 --output-on-failure
45+
46+
clang_build_cxx20:
47+
runs-on: ubuntu-latest
48+
49+
steps:
50+
- uses: actions/checkout@v1
51+
- name: install_gcc
52+
run: |
53+
sudo apt update
54+
sudo apt install clang-10
55+
shell: bash
56+
- name: cmake
57+
run: cmake -S . -B build -D CMAKE_BUILD_TYPE=Debug -DJSON_BuildTests=On -DCMAKE_CXX_STANDARD=20 -DCMAKE_CXX_STANDARD_REQUIRED=ON
58+
env:
59+
CC: clang-10
60+
CXX: clang++-10
1361
- name: build
1462
run: cmake --build build --parallel 10
1563
- name: test

.travis.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ matrix:
210210
compiler: gcc
211211
env:
212212
- COMPILER=g++-9
213-
- CXXFLAGS=-std=c++2a
213+
- CXX_STANDARD=17
214214
addons:
215215
apt:
216216
sources: ['ubuntu-toolchain-r-test']
@@ -294,11 +294,11 @@ matrix:
294294
compiler: clang
295295
env:
296296
- COMPILER=clang++-7
297-
- CXXFLAGS=-std=c++1z
297+
- CXX_STANDARD=17
298298
addons:
299299
apt:
300300
sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-trusty-7']
301-
packages: ['g++-6', 'clang-7', 'ninja-build']
301+
packages: ['g++-7', 'clang-7', 'ninja-build']
302302

303303
################
304304
# build script #
@@ -321,6 +321,9 @@ script:
321321
# by default, use implicit conversions
322322
- if [[ "${IMPLICIT_CONVERSIONS}" == "" ]]; then export IMPLICIT_CONVERSIONS=ON; fi
323323

324+
# append CXX_STANDARD to CMAKE_OPTIONS if required
325+
- CMAKE_OPTIONS+=${CXX_STANDARD:+ -DCMAKE_CXX_STANDARD=$CXX_STANDARD -DCMAKE_CXX_STANDARD_REQUIRED=ON}
326+
324327
# compile and execute unit tests
325328
- mkdir -p build && cd build
326329
- cmake .. ${CMAKE_OPTIONS} -DJSON_MultipleHeaders=${MULTIPLE_HEADERS} -DJSON_ImplicitConversions=${IMPLICIT_CONVERSIONS} -DJSON_BuildTests=On -GNinja && cmake --build . --config Release

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ doctest:
8484
# -Wno-missing-prototypes: for NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE
8585
# -Wno-padded: padding is nothing to warn about
8686
# -Wno-range-loop-analysis: items tests "for(const auto i...)"
87+
# -Wno-extra-semi-stmt: spurious warnings for semicolons after JSON_ASSERT()
8788
# -Wno-switch-enum -Wno-covered-switch-default: pedantic/contradicting warnings about switches
8889
# -Wno-weak-vtables: exception class is defined inline, but has virtual method
8990
pedantic_clang:
@@ -100,6 +101,7 @@ pedantic_clang:
100101
-Wno-missing-prototypes \
101102
-Wno-padded \
102103
-Wno-range-loop-analysis \
104+
-Wno-extra-semi-stmt \
103105
-Wno-switch-enum -Wno-covered-switch-default \
104106
-Wno-weak-vtables" cmake -S . -B cmake-build-pedantic -GNinja -DCMAKE_BUILD_TYPE=Debug -DJSON_MultipleHeaders=ON -DJSON_BuildTests=On
105107
cmake --build cmake-build-pedantic

include/nlohmann/detail/hash.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
#include <cstddef> // size_t, uint8_t
44
#include <functional> // hash
55

6+
#include <nlohmann/detail/macro_scope.hpp>
7+
68
namespace nlohmann
79
{
810
namespace detail

include/nlohmann/detail/input/binary_reader.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <limits> // numeric_limits
1212
#include <string> // char_traits, string
1313
#include <utility> // make_pair, move
14+
#include <vector> // vector
1415

1516
#include <nlohmann/detail/exceptions.hpp>
1617
#include <nlohmann/detail/input/input_adapters.hpp>
@@ -2340,7 +2341,7 @@ class binary_reader
23402341
break;
23412342
}
23422343
result.push_back(static_cast<typename string_t::value_type>(current));
2343-
};
2344+
}
23442345
return success;
23452346
}
23462347

include/nlohmann/detail/input/input_adapters.hpp

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -371,15 +371,37 @@ typename iterator_input_adapter_factory<IteratorType>::adapter_type input_adapte
371371
}
372372

373373
// Convenience shorthand from container to iterator
374-
template<typename ContainerType>
375-
auto input_adapter(const ContainerType& container) -> decltype(input_adapter(begin(container), end(container)))
374+
// Enables ADL on begin(container) and end(container)
375+
// Encloses the using declarations in namespace for not to leak them to outside scope
376+
377+
namespace container_input_adapter_factory_impl
376378
{
377-
// Enable ADL
378-
using std::begin;
379-
using std::end;
380379

380+
using std::begin;
381+
using std::end;
382+
383+
template<typename ContainerType, typename Enable = void>
384+
struct container_input_adapter_factory {};
385+
386+
template<typename ContainerType>
387+
struct container_input_adapter_factory< ContainerType,
388+
void_t<decltype(begin(std::declval<ContainerType>()), end(std::declval<ContainerType>()))>>
389+
{
390+
using adapter_type = decltype(input_adapter(begin(std::declval<ContainerType>()), end(std::declval<ContainerType>())));
391+
392+
static adapter_type create(const ContainerType& container)
393+
{
381394
return input_adapter(begin(container), end(container));
382395
}
396+
};
397+
398+
}
399+
400+
template<typename ContainerType>
401+
typename container_input_adapter_factory_impl::container_input_adapter_factory<ContainerType>::adapter_type input_adapter(const ContainerType& container)
402+
{
403+
return container_input_adapter_factory_impl::container_input_adapter_factory<ContainerType>::create(container);
404+
}
383405

384406
// Special cases with fast paths
385407
inline file_input_adapter input_adapter(std::FILE* file)

include/nlohmann/detail/input/lexer.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1541,17 +1541,17 @@ class lexer : public lexer_base<BasicJsonType>
15411541
// literals
15421542
case 't':
15431543
{
1544-
std::array<char_type, 4> true_literal = {{'t', 'r', 'u', 'e'}};
1544+
std::array<char_type, 4> true_literal = {{char_type('t'), char_type('r'), char_type('u'), char_type('e')}};
15451545
return scan_literal(true_literal.data(), true_literal.size(), token_type::literal_true);
15461546
}
15471547
case 'f':
15481548
{
1549-
std::array<char_type, 5> false_literal = {{'f', 'a', 'l', 's', 'e'}};
1549+
std::array<char_type, 5> false_literal = {{char_type('f'), char_type('a'), char_type('l'), char_type('s'), char_type('e')}};
15501550
return scan_literal(false_literal.data(), false_literal.size(), token_type::literal_false);
15511551
}
15521552
case 'n':
15531553
{
1554-
std::array<char_type, 4> null_literal = {{'n', 'u', 'l', 'l'}};
1554+
std::array<char_type, 4> null_literal = {{char_type('n'), char_type('u'), char_type('l'), char_type('l')}};
15551555
return scan_literal(null_literal.data(), null_literal.size(), token_type::literal_null);
15561556
}
15571557

include/nlohmann/detail/iterators/iter_impl.hpp

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,10 @@ This class implements a both iterators (iterator and const_iterator) for the
3838
template<typename BasicJsonType>
3939
class iter_impl
4040
{
41+
/// the iterator with BasicJsonType of different const-ness
42+
using other_iter_impl = iter_impl<typename std::conditional<std::is_const<BasicJsonType>::value, typename std::remove_const<BasicJsonType>::type, const BasicJsonType>::type>;
4143
/// allow basic_json to access private members
42-
friend iter_impl<typename std::conditional<std::is_const<BasicJsonType>::value, typename std::remove_const<BasicJsonType>::type, const BasicJsonType>::type>;
44+
friend other_iter_impl;
4345
friend BasicJsonType;
4446
friend iteration_proxy<iter_impl>;
4547
friend iteration_proxy_value<iter_impl>;
@@ -390,10 +392,11 @@ class iter_impl
390392
}
391393

392394
/*!
393-
@brief comparison: equal
395+
@brief comparison: equal
394396
@pre The iterator is initialized; i.e. `m_object != nullptr`.
395397
*/
396-
bool operator==(const iter_impl& other) const
398+
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 >
399+
bool operator==(const IterImpl& other) const
397400
{
398401
// if objects are not the same, the comparison is undefined
399402
if (JSON_HEDLEY_UNLIKELY(m_object != other.m_object))
@@ -417,16 +420,17 @@ class iter_impl
417420
}
418421

419422
/*!
420-
@brief comparison: not equal
423+
@brief comparison: not equal
421424
@pre The iterator is initialized; i.e. `m_object != nullptr`.
422425
*/
423-
bool operator!=(const iter_impl& other) const
426+
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 >
427+
bool operator!=(const IterImpl& other) const
424428
{
425429
return !operator==(other);
426430
}
427431

428432
/*!
429-
@brief comparison: smaller
433+
@brief comparison: smaller
430434
@pre The iterator is initialized; i.e. `m_object != nullptr`.
431435
*/
432436
bool operator<(const iter_impl& other) const
@@ -453,7 +457,7 @@ class iter_impl
453457
}
454458

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

464468
/*!
465-
@brief comparison: greater than
469+
@brief comparison: greater than
466470
@pre The iterator is initialized; i.e. `m_object != nullptr`.
467471
*/
468472
bool operator>(const iter_impl& other) const
@@ -471,7 +475,7 @@ class iter_impl
471475
}
472476

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

482486
/*!
483-
@brief add to iterator
487+
@brief add to iterator
484488
@pre The iterator is initialized; i.e. `m_object != nullptr`.
485489
*/
486490
iter_impl& operator+=(difference_type i)
@@ -509,7 +513,7 @@ class iter_impl
509513
}
510514

511515
/*!
512-
@brief subtract from iterator
516+
@brief subtract from iterator
513517
@pre The iterator is initialized; i.e. `m_object != nullptr`.
514518
*/
515519
iter_impl& operator-=(difference_type i)
@@ -518,7 +522,7 @@ class iter_impl
518522
}
519523

520524
/*!
521-
@brief add to iterator
525+
@brief add to iterator
522526
@pre The iterator is initialized; i.e. `m_object != nullptr`.
523527
*/
524528
iter_impl operator+(difference_type i) const
@@ -529,7 +533,7 @@ class iter_impl
529533
}
530534

531535
/*!
532-
@brief addition of distance and iterator
536+
@brief addition of distance and iterator
533537
@pre The iterator is initialized; i.e. `m_object != nullptr`.
534538
*/
535539
friend iter_impl operator+(difference_type i, const iter_impl& it)
@@ -540,7 +544,7 @@ class iter_impl
540544
}
541545

542546
/*!
543-
@brief subtract from iterator
547+
@brief subtract from iterator
544548
@pre The iterator is initialized; i.e. `m_object != nullptr`.
545549
*/
546550
iter_impl operator-(difference_type i) const
@@ -551,7 +555,7 @@ class iter_impl
551555
}
552556

553557
/*!
554-
@brief return difference
558+
@brief return difference
555559
@pre The iterator is initialized; i.e. `m_object != nullptr`.
556560
*/
557561
difference_type operator-(const iter_impl& other) const
@@ -572,7 +576,7 @@ class iter_impl
572576
}
573577

574578
/*!
575-
@brief access to successor
579+
@brief access to successor
576580
@pre The iterator is initialized; i.e. `m_object != nullptr`.
577581
*/
578582
reference operator[](difference_type n) const
@@ -603,7 +607,7 @@ class iter_impl
603607
}
604608

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

621625
/*!
622-
@brief return the value of an iterator
626+
@brief return the value of an iterator
623627
@pre The iterator is initialized; i.e. `m_object != nullptr`.
624628
*/
625629
reference value() const

include/nlohmann/detail/iterators/primitive_iterator.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
#include <cstddef> // ptrdiff_t
44
#include <limits> // numeric_limits
55

6+
#include <nlohmann/detail/macro_scope.hpp>
7+
68
namespace nlohmann
79
{
810
namespace detail

include/nlohmann/detail/meta/type_traits.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <limits> // numeric_limits
44
#include <type_traits> // false_type, is_constructible, is_integral, is_same, true_type
55
#include <utility> // declval
6+
#include <tuple> // tuple
67

78
#include <nlohmann/detail/iterators/iterator_traits.hpp>
89
#include <nlohmann/detail/macro_scope.hpp>

0 commit comments

Comments
 (0)