Skip to content

Commit

Permalink
🎨 use Clang-Format
Browse files Browse the repository at this point in the history
  • Loading branch information
nlohmann committed Nov 29, 2023
1 parent 286f0c7 commit af3f87e
Show file tree
Hide file tree
Showing 77 changed files with 4,299 additions and 4,402 deletions.
5 changes: 4 additions & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ BreakStringLiterals: false
ColumnLimit: 160
CompactNamespaces: false
ConstructorInitializerIndentWidth: 2
Cpp11BracedListStyle: true
Cpp11BracedListStyle: false
PointerAlignment: Left
FixNamespaceComments: true
#IndentCaseBlocks: false
Expand Down Expand Up @@ -92,3 +92,6 @@ IncludeCategories:
Priority: 3
- Regex: '.*'
Priority: 4

Macros:
- JSON_PRIVATE_UNLESS_TESTED=private
16 changes: 13 additions & 3 deletions .github/workflows/ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,28 @@ jobs:

ci_static_analysis:
runs-on: ubuntu-latest
container: silkeh/clang:dev
container: ghcr.io/nlohmann/json-ci:v2.4.0
strategy:
matrix:
target: [ci_cppcheck, ci_test_valgrind, ci_test_amalgamation, ci_test_single_header, ci_single_binaries, ci_infer]
target: [ci_cppcheck, ci_test_valgrind, ci_test_single_header, ci_single_binaries, ci_infer]
steps:
- uses: actions/checkout@v3
- name: Run CMake
run: cmake -S . -B build -DJSON_CI=On
- name: Build
run: cmake --build build --target ${{ matrix.target }}

ci_test_amalgamation:
runs-on: ubuntu-latest
container: silkeh/clang:dev
steps:
- uses: actions/checkout@v3
- name: Get latest CMake and ninja
uses: lukka/get-cmake@v3.27.7
- name: Run CMake
run: cmake -S . -B build -DJSON_CI=On
- name: Build
run: cmake --build build --target ${{ matrix.target }}
run: cmake --build build --target ci_test_amalgamation

ci_static_analysis_ubuntu:
runs-on: ubuntu-latest
Expand Down
4 changes: 2 additions & 2 deletions include/nlohmann/detail/conversions/from_json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ template<typename BasicJsonType, typename T, std::size_t... Idx>
std::array<T, sizeof...(Idx)>
from_json_inplace_array_impl(BasicJsonType&& j, identity_tag<std::array<T, sizeof...(Idx)>> /*unused*/, index_sequence<Idx...> /*unused*/)
{
return {{std::forward<BasicJsonType>(j).at(Idx).template get<T>()...}};
return { { std::forward<BasicJsonType>(j).at(Idx).template get<T>()... } };
}

template<typename BasicJsonType, typename T, std::size_t N>
Expand Down Expand Up @@ -353,7 +353,7 @@ std::tuple<Args...> from_json_tuple_impl_base(BasicJsonType&& j, index_sequence<
template<typename BasicJsonType, class A1, class A2>
std::pair<A1, A2> from_json_tuple_impl(BasicJsonType&& j, identity_tag<std::pair<A1, A2>> /*unused*/, priority_tag<0> /*unused*/)
{
return {std::forward<BasicJsonType>(j).at(0).template get<A1>(), std::forward<BasicJsonType>(j).at(1).template get<A2>()};
return { std::forward<BasicJsonType>(j).at(0).template get<A1>(), std::forward<BasicJsonType>(j).at(1).template get<A2>() };
}

template<typename BasicJsonType, typename A1, typename A2>
Expand Down
62 changes: 31 additions & 31 deletions include/nlohmann/detail/conversions/to_chars.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ struct diyfp // f * 2^e
JSON_ASSERT(x.e == y.e);
JSON_ASSERT(x.f >= y.f);

return {x.f - y.f, x.e};
return { x.f - y.f, x.e };
}

/*!
Expand Down Expand Up @@ -136,11 +136,11 @@ struct diyfp // f * 2^e
// Effectively we only need to add the highest bit in p_lo to p_hi (and
// Q_hi + 1 does not overflow).

Q += std::uint64_t{1} << (64u - 32u - 1u); // round, ties up
Q += std::uint64_t{ 1 } << (64u - 32u - 1u); // round, ties up

const std::uint64_t h = p3 + p2_hi + p1_hi + (Q >> 32u);

return {h, x.e + y.e + 64};
return { h, x.e + y.e + 64 };
}

/*!
Expand Down Expand Up @@ -171,7 +171,7 @@ struct diyfp // f * 2^e
JSON_ASSERT(delta >= 0);
JSON_ASSERT(((x.f << delta) >> delta) == x.f);

return {x.f << delta, target_exponent};
return { x.f << delta, target_exponent };
}
};

Expand Down Expand Up @@ -206,7 +206,7 @@ boundaries compute_boundaries(FloatType value)
constexpr int kPrecision = std::numeric_limits<FloatType>::digits; // = p (includes the hidden bit)
constexpr int kBias = std::numeric_limits<FloatType>::max_exponent - 1 + (kPrecision - 1);
constexpr int kMinExp = 1 - kBias;
constexpr std::uint64_t kHiddenBit = std::uint64_t{1} << (kPrecision - 1); // = 2^(p-1)
constexpr std::uint64_t kHiddenBit = std::uint64_t{ 1 } << (kPrecision - 1); // = 2^(p-1)

using bits_type = typename std::conditional<kPrecision == 24, std::uint32_t, std::uint64_t>::type;

Expand Down Expand Up @@ -249,7 +249,7 @@ boundaries compute_boundaries(FloatType value)
// Determine w- = m- such that e_(w-) = e_(w+).
const diyfp w_minus = diyfp::normalize_to(m_minus, w_plus.e);

return {diyfp::normalize(v), w_minus, w_plus};
return { diyfp::normalize(v), w_minus, w_plus };
}

// Given normalized diyfp w, Grisu needs to find a (normalized) cached
Expand Down Expand Up @@ -379,28 +379,28 @@ inline cached_power get_cached_power_for_binary_exponent(int e)
constexpr int kCachedPowersMinDecExp = -300;
constexpr int kCachedPowersDecStep = 8;

static constexpr std::array<cached_power, 79> kCachedPowers = {{
{0xAB70FE17C79AC6CA, -1060, -300}, {0xFF77B1FCBEBCDC4F, -1034, -292}, {0xBE5691EF416BD60C, -1007, -284}, {0x8DD01FAD907FFC3C, -980, -276},
{0xD3515C2831559A83, -954, -268}, {0x9D71AC8FADA6C9B5, -927, -260}, {0xEA9C227723EE8BCB, -901, -252}, {0xAECC49914078536D, -874, -244},
{0x823C12795DB6CE57, -847, -236}, {0xC21094364DFB5637, -821, -228}, {0x9096EA6F3848984F, -794, -220}, {0xD77485CB25823AC7, -768, -212},
{0xA086CFCD97BF97F4, -741, -204}, {0xEF340A98172AACE5, -715, -196}, {0xB23867FB2A35B28E, -688, -188}, {0x84C8D4DFD2C63F3B, -661, -180},
{0xC5DD44271AD3CDBA, -635, -172}, {0x936B9FCEBB25C996, -608, -164}, {0xDBAC6C247D62A584, -582, -156}, {0xA3AB66580D5FDAF6, -555, -148},
{0xF3E2F893DEC3F126, -529, -140}, {0xB5B5ADA8AAFF80B8, -502, -132}, {0x87625F056C7C4A8B, -475, -124}, {0xC9BCFF6034C13053, -449, -116},
{0x964E858C91BA2655, -422, -108}, {0xDFF9772470297EBD, -396, -100}, {0xA6DFBD9FB8E5B88F, -369, -92}, {0xF8A95FCF88747D94, -343, -84},
{0xB94470938FA89BCF, -316, -76}, {0x8A08F0F8BF0F156B, -289, -68}, {0xCDB02555653131B6, -263, -60}, {0x993FE2C6D07B7FAC, -236, -52},
{0xE45C10C42A2B3B06, -210, -44}, {0xAA242499697392D3, -183, -36}, {0xFD87B5F28300CA0E, -157, -28}, {0xBCE5086492111AEB, -130, -20},
{0x8CBCCC096F5088CC, -103, -12}, {0xD1B71758E219652C, -77, -4}, {0x9C40000000000000, -50, 4}, {0xE8D4A51000000000, -24, 12},
{0xAD78EBC5AC620000, 3, 20}, {0x813F3978F8940984, 30, 28}, {0xC097CE7BC90715B3, 56, 36}, {0x8F7E32CE7BEA5C70, 83, 44},
{0xD5D238A4ABE98068, 109, 52}, {0x9F4F2726179A2245, 136, 60}, {0xED63A231D4C4FB27, 162, 68}, {0xB0DE65388CC8ADA8, 189, 76},
{0x83C7088E1AAB65DB, 216, 84}, {0xC45D1DF942711D9A, 242, 92}, {0x924D692CA61BE758, 269, 100}, {0xDA01EE641A708DEA, 295, 108},
{0xA26DA3999AEF774A, 322, 116}, {0xF209787BB47D6B85, 348, 124}, {0xB454E4A179DD1877, 375, 132}, {0x865B86925B9BC5C2, 402, 140},
{0xC83553C5C8965D3D, 428, 148}, {0x952AB45CFA97A0B3, 455, 156}, {0xDE469FBD99A05FE3, 481, 164}, {0xA59BC234DB398C25, 508, 172},
{0xF6C69A72A3989F5C, 534, 180}, {0xB7DCBF5354E9BECE, 561, 188}, {0x88FCF317F22241E2, 588, 196}, {0xCC20CE9BD35C78A5, 614, 204},
{0x98165AF37B2153DF, 641, 212}, {0xE2A0B5DC971F303A, 667, 220}, {0xA8D9D1535CE3B396, 694, 228}, {0xFB9B7CD9A4A7443C, 720, 236},
{0xBB764C4CA7A44410, 747, 244}, {0x8BAB8EEFB6409C1A, 774, 252}, {0xD01FEF10A657842C, 800, 260}, {0x9B10A4E5E9913129, 827, 268},
{0xE7109BFBA19C0C9D, 853, 276}, {0xAC2820D9623BF429, 880, 284}, {0x80444B5E7AA7CF85, 907, 292}, {0xBF21E44003ACDD2D, 933, 300},
{0x8E679C2F5E44FF8F, 960, 308}, {0xD433179D9C8CB841, 986, 316}, {0x9E19DB92B4E31BA9, 1013, 324},
}};
static constexpr std::array<cached_power, 79> kCachedPowers = { {
{ 0xAB70FE17C79AC6CA, -1060, -300 }, { 0xFF77B1FCBEBCDC4F, -1034, -292 }, { 0xBE5691EF416BD60C, -1007, -284 }, { 0x8DD01FAD907FFC3C, -980, -276 },
{ 0xD3515C2831559A83, -954, -268 }, { 0x9D71AC8FADA6C9B5, -927, -260 }, { 0xEA9C227723EE8BCB, -901, -252 }, { 0xAECC49914078536D, -874, -244 },
{ 0x823C12795DB6CE57, -847, -236 }, { 0xC21094364DFB5637, -821, -228 }, { 0x9096EA6F3848984F, -794, -220 }, { 0xD77485CB25823AC7, -768, -212 },
{ 0xA086CFCD97BF97F4, -741, -204 }, { 0xEF340A98172AACE5, -715, -196 }, { 0xB23867FB2A35B28E, -688, -188 }, { 0x84C8D4DFD2C63F3B, -661, -180 },
{ 0xC5DD44271AD3CDBA, -635, -172 }, { 0x936B9FCEBB25C996, -608, -164 }, { 0xDBAC6C247D62A584, -582, -156 }, { 0xA3AB66580D5FDAF6, -555, -148 },
{ 0xF3E2F893DEC3F126, -529, -140 }, { 0xB5B5ADA8AAFF80B8, -502, -132 }, { 0x87625F056C7C4A8B, -475, -124 }, { 0xC9BCFF6034C13053, -449, -116 },
{ 0x964E858C91BA2655, -422, -108 }, { 0xDFF9772470297EBD, -396, -100 }, { 0xA6DFBD9FB8E5B88F, -369, -92 }, { 0xF8A95FCF88747D94, -343, -84 },
{ 0xB94470938FA89BCF, -316, -76 }, { 0x8A08F0F8BF0F156B, -289, -68 }, { 0xCDB02555653131B6, -263, -60 }, { 0x993FE2C6D07B7FAC, -236, -52 },
{ 0xE45C10C42A2B3B06, -210, -44 }, { 0xAA242499697392D3, -183, -36 }, { 0xFD87B5F28300CA0E, -157, -28 }, { 0xBCE5086492111AEB, -130, -20 },
{ 0x8CBCCC096F5088CC, -103, -12 }, { 0xD1B71758E219652C, -77, -4 }, { 0x9C40000000000000, -50, 4 }, { 0xE8D4A51000000000, -24, 12 },
{ 0xAD78EBC5AC620000, 3, 20 }, { 0x813F3978F8940984, 30, 28 }, { 0xC097CE7BC90715B3, 56, 36 }, { 0x8F7E32CE7BEA5C70, 83, 44 },
{ 0xD5D238A4ABE98068, 109, 52 }, { 0x9F4F2726179A2245, 136, 60 }, { 0xED63A231D4C4FB27, 162, 68 }, { 0xB0DE65388CC8ADA8, 189, 76 },
{ 0x83C7088E1AAB65DB, 216, 84 }, { 0xC45D1DF942711D9A, 242, 92 }, { 0x924D692CA61BE758, 269, 100 }, { 0xDA01EE641A708DEA, 295, 108 },
{ 0xA26DA3999AEF774A, 322, 116 }, { 0xF209787BB47D6B85, 348, 124 }, { 0xB454E4A179DD1877, 375, 132 }, { 0x865B86925B9BC5C2, 402, 140 },
{ 0xC83553C5C8965D3D, 428, 148 }, { 0x952AB45CFA97A0B3, 455, 156 }, { 0xDE469FBD99A05FE3, 481, 164 }, { 0xA59BC234DB398C25, 508, 172 },
{ 0xF6C69A72A3989F5C, 534, 180 }, { 0xB7DCBF5354E9BECE, 561, 188 }, { 0x88FCF317F22241E2, 588, 196 }, { 0xCC20CE9BD35C78A5, 614, 204 },
{ 0x98165AF37B2153DF, 641, 212 }, { 0xE2A0B5DC971F303A, 667, 220 }, { 0xA8D9D1535CE3B396, 694, 228 }, { 0xFB9B7CD9A4A7443C, 720, 236 },
{ 0xBB764C4CA7A44410, 747, 244 }, { 0x8BAB8EEFB6409C1A, 774, 252 }, { 0xD01FEF10A657842C, 800, 260 }, { 0x9B10A4E5E9913129, 827, 268 },
{ 0xE7109BFBA19C0C9D, 853, 276 }, { 0xAC2820D9623BF429, 880, 284 }, { 0x80444B5E7AA7CF85, 907, 292 }, { 0xBF21E44003ACDD2D, 933, 300 },
{ 0x8E679C2F5E44FF8F, 960, 308 }, { 0xD433179D9C8CB841, 986, 316 }, { 0x9E19DB92B4E31BA9, 1013, 324 },
} };

// This computation gives exactly the same results for k as
// k = ceil((kAlpha - e - 1) * 0.30102999566398114)
Expand Down Expand Up @@ -548,7 +548,7 @@ inline void grisu2_digit_gen(char* buffer, int& length, int& decimal_exponent, d
// = ((p1 ) * 2^-e + (p2 )) * 2^e
// = p1 + p2 * 2^e

const diyfp one(std::uint64_t{1} << -M_plus.e, M_plus.e);
const diyfp one(std::uint64_t{ 1 } << -M_plus.e, M_plus.e);

auto p1 = static_cast<std::uint32_t>(M_plus.f >> -one.e); // p1 = f div 2^-e (Since -e >= 32, p1 fits into a 32-bit int.)
std::uint64_t p2 = M_plus.f & (one.f - 1); // p2 = f mod 2^-e
Expand Down Expand Up @@ -613,7 +613,7 @@ inline void grisu2_digit_gen(char* buffer, int& length, int& decimal_exponent, d
// Note:
// Since rest and delta share the same exponent e, it suffices to
// compare the significands.
const std::uint64_t rest = (std::uint64_t{p1} << -one.e) + p2;
const std::uint64_t rest = (std::uint64_t{ p1 } << -one.e) + p2;
if (rest <= delta)
{
// V = buffer * 10^n, with M- <= V <= M+.
Expand All @@ -629,7 +629,7 @@ inline void grisu2_digit_gen(char* buffer, int& length, int& decimal_exponent, d
//
// 10^n = (10^n * 2^-e) * 2^e = ulp * 2^e
//
const std::uint64_t ten_n = std::uint64_t{pow10} << -one.e;
const std::uint64_t ten_n = std::uint64_t{ pow10 } << -one.e;
grisu2_round(buffer, length, dist, delta, rest, ten_n);

return;
Expand Down
6 changes: 3 additions & 3 deletions include/nlohmann/detail/conversions/to_json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -392,20 +392,20 @@ template<typename BasicJsonType,
enable_if_t<std::is_constructible<BasicJsonType, T1>::value && std::is_constructible<BasicJsonType, T2>::value, int> = 0>
inline void to_json(BasicJsonType& j, const std::pair<T1, T2>& p)
{
j = {p.first, p.second};
j = { p.first, p.second };
}

// for https://github.com/nlohmann/json/pull/1134
template<typename BasicJsonType, typename T, enable_if_t<std::is_same<T, iteration_proxy_value<typename BasicJsonType::iterator>>::value, int> = 0>
inline void to_json(BasicJsonType& j, const T& b)
{
j = {{b.key(), b.value()}};
j = { { b.key(), b.value() } };
}

template<typename BasicJsonType, typename Tuple, std::size_t... Idx>
inline void to_json_tuple_impl(BasicJsonType& j, const Tuple& t, index_sequence<Idx...> /*unused*/)
{
j = {std::get<Idx>(t)...};
j = { std::get<Idx>(t)... };
}

template<typename BasicJsonType, typename T, enable_if_t<is_constructible_tuple<BasicJsonType, T>::value, int> = 0>
Expand Down
16 changes: 8 additions & 8 deletions include/nlohmann/detail/exceptions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ class exception : public std::exception
JSON_HEDLEY_NON_NULL(3)
exception(int id_, const char* what_arg)
: id(id_)
, m(what_arg)
{} // NOLINT(bugprone-throw-keyword-missing)
, m(what_arg) // NOLINT(bugprone-throw-keyword-missing)
{}

static std::string name(const std::string& ename, int id_)
{
Expand Down Expand Up @@ -150,7 +150,7 @@ class parse_error : public exception
static parse_error create(int id_, const position_t& pos, const std::string& what_arg, BasicJsonContext context)
{
const std::string w = concat(exception::name("parse_error", id_), "parse error", position_string(pos), ": ", exception::diagnostics(context), what_arg);
return {id_, pos.chars_read_total, w.c_str()};
return { id_, pos.chars_read_total, w.c_str() };
}

template<typename BasicJsonContext, enable_if_t<is_basic_json_context<BasicJsonContext>::value, int> = 0>
Expand All @@ -162,7 +162,7 @@ class parse_error : public exception
": ",
exception::diagnostics(context),
what_arg);
return {id_, byte_, w.c_str()};
return { id_, byte_, w.c_str() };
}

/*!
Expand Down Expand Up @@ -197,7 +197,7 @@ class invalid_iterator : public exception
static invalid_iterator create(int id_, const std::string& what_arg, BasicJsonContext context)
{
const std::string w = concat(exception::name("invalid_iterator", id_), exception::diagnostics(context), what_arg);
return {id_, w.c_str()};
return { id_, w.c_str() };
}

private:
Expand All @@ -216,7 +216,7 @@ class type_error : public exception
static type_error create(int id_, const std::string& what_arg, BasicJsonContext context)
{
const std::string w = concat(exception::name("type_error", id_), exception::diagnostics(context), what_arg);
return {id_, w.c_str()};
return { id_, w.c_str() };
}

private:
Expand All @@ -235,7 +235,7 @@ class out_of_range : public exception
static out_of_range create(int id_, const std::string& what_arg, BasicJsonContext context)
{
const std::string w = concat(exception::name("out_of_range", id_), exception::diagnostics(context), what_arg);
return {id_, w.c_str()};
return { id_, w.c_str() };
}

private:
Expand All @@ -254,7 +254,7 @@ class other_error : public exception
static other_error create(int id_, const std::string& what_arg, BasicJsonContext context)
{
const std::string w = concat(exception::name("other_error", id_), exception::diagnostics(context), what_arg);
return {id_, w.c_str()};
return { id_, w.c_str() };
}

private:
Expand Down
Loading

0 comments on commit af3f87e

Please sign in to comment.