Browse Source

Util: Move json/conversion.h -> meta/odr.h

master
Riyyi 2 years ago
parent
commit
dd209a2609
  1. 22
      src/util/json/conversion.h
  2. 4
      src/util/json/fromjson.h
  3. 4
      src/util/json/tojson.h
  4. 23
      src/util/meta/odr.h

22
src/util/json/conversion.h

@ -1,22 +0,0 @@
/*
* Copyright (C) 2022 Riyyi
*
* SPDX-License-Identifier: MIT
*/
#ifndef JSON_CONVERSION_H
#define JSON_CONVERSION_H
namespace Json {
namespace Detail {
// Avoid ODR (One Definition Rule) violations
template<typename T>
constexpr T staticConst {};
} // namespace Detail
} // namespace Json
#endif // JSON_CONVERSION_H

4
src/util/json/fromjson.h

@ -17,8 +17,8 @@
#include <vector>
#include "util/json/array.h"
#include "util/json/conversion.h"
#include "util/json/object.h"
#include "util/meta/odr.h"
namespace Json {
@ -113,7 +113,7 @@ struct fromJsonFunction {
// Anonymous namespace prevents multiple definition of the reference
namespace {
// Function object
constexpr const auto& fromJson = Detail::staticConst<Detail::fromJsonFunction>; // NOLINT (misc-definitions-in-headers)
constexpr const auto& fromJson = Util::Detail::staticConst<Detail::fromJsonFunction>; // NOLINT(misc-definitions-in-headers,clang-diagnostic-unused-variable)
} // namespace
} // namespace Json

4
src/util/json/tojson.h

@ -15,8 +15,8 @@
#include <utility> // forward
#include "util/json/array.h"
#include "util/json/conversion.h"
#include "util/json/object.h"
#include "util/meta/odr.h"
namespace Json {
@ -133,7 +133,7 @@ struct toJsonFunction {
// Anonymous namespace prevents multiple definition of the reference
namespace {
// Function object
constexpr const auto& toJson = Detail::staticConst<Detail::toJsonFunction>; // NOLINT (misc-definitions-in-headers)
constexpr const auto& toJson = Util::Detail::staticConst<Detail::toJsonFunction>; // NOLINT(misc-definitions-in-headers,clang-diagnostic-unused-variable)
} // namespace
} // namespace Json

23
src/util/meta/odr.h

@ -0,0 +1,23 @@
/*
* Copyright (C) 2022 Riyyi
*
* SPDX-License-Identifier: MIT
*/
#ifndef META_ODR_H
#define META_ODR_H
namespace Util {
namespace Detail {
// Avoid ODR (One Definition Rule) violations,
// variable templates are required to have external linkage
template<typename T>
constexpr T staticConst {};
} // namespace Detail
} // namespace Util
#endif // META_ODR_H
Loading…
Cancel
Save