From dd209a2609ae753ef92cd49dc4e0fdb24ac30275 Mon Sep 17 00:00:00 2001 From: Riyyi Date: Thu, 21 Jul 2022 01:50:15 +0200 Subject: [PATCH] Util: Move json/conversion.h -> meta/odr.h --- src/util/json/conversion.h | 22 ---------------------- src/util/json/fromjson.h | 4 ++-- src/util/json/tojson.h | 4 ++-- src/util/meta/odr.h | 23 +++++++++++++++++++++++ 4 files changed, 27 insertions(+), 26 deletions(-) delete mode 100644 src/util/json/conversion.h create mode 100644 src/util/meta/odr.h diff --git a/src/util/json/conversion.h b/src/util/json/conversion.h deleted file mode 100644 index 7f27cd8..0000000 --- a/src/util/json/conversion.h +++ /dev/null @@ -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 -constexpr T staticConst {}; - -} // namespace Detail - -} // namespace Json - -#endif // JSON_CONVERSION_H diff --git a/src/util/json/fromjson.h b/src/util/json/fromjson.h index f2d5285..3a28298 100644 --- a/src/util/json/fromjson.h +++ b/src/util/json/fromjson.h @@ -17,8 +17,8 @@ #include #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; // NOLINT (misc-definitions-in-headers) +constexpr const auto& fromJson = Util::Detail::staticConst; // NOLINT(misc-definitions-in-headers,clang-diagnostic-unused-variable) } // namespace } // namespace Json diff --git a/src/util/json/tojson.h b/src/util/json/tojson.h index d2045bb..f47c493 100644 --- a/src/util/json/tojson.h +++ b/src/util/json/tojson.h @@ -15,8 +15,8 @@ #include // 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; // NOLINT (misc-definitions-in-headers) +constexpr const auto& toJson = Util::Detail::staticConst; // NOLINT(misc-definitions-in-headers,clang-diagnostic-unused-variable) } // namespace } // namespace Json diff --git a/src/util/meta/odr.h b/src/util/meta/odr.h new file mode 100644 index 0000000..f6c0685 --- /dev/null +++ b/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 +constexpr T staticConst {}; + +} // namespace Detail + +} // namespace Util + +#endif // META_ODR_H