From 654f1d98f2374f9cf5d6e076998858f7d373df56 Mon Sep 17 00:00:00 2001 From: Chip Hogg Date: Mon, 28 Oct 2024 11:33:26 -0400 Subject: [PATCH] Authoritatively forward declare core types (#312) From now on, anyone can just include `"au/fwd.hh"`, and get authoritatively correct forward declarations. These will be implicitly tested automatically by adding an `#include` of this new file at the top of every file that has a definition for which we now provide a forward declaration: if we get a forward declaration wrong, we'll get a compiler warning. We also include `fwd.hh` in a few places where it lets us get rid of some manual forward declarations. The rep-named aliases move upstream into `fwd.hh`, because they'll be directly useful for forward declaration use cases, and because you can't "forward declare" an alias: you just have to move the definition upstream. Helps #232. To resolve it completely, we will need to provide a forward declaration file for each individual unit file. --- au/BUILD.bazel | 24 ++++- au/code/au/CMakeLists.txt | 1 + au/code/au/constant.hh | 1 + au/code/au/dimension.hh | 1 + au/code/au/fwd.hh | 168 +++++++++++++++++++++++++++++++++++ au/code/au/magnitude.hh | 1 + au/code/au/prefix.hh | 1 + au/code/au/quantity.hh | 34 +------ au/code/au/quantity_point.hh | 28 +----- au/code/au/rep.hh | 9 +- au/code/au/unit_symbol.hh | 1 + au/code/au/zero.hh | 2 + 12 files changed, 201 insertions(+), 70 deletions(-) create mode 100644 au/code/au/fwd.hh diff --git a/au/BUILD.bazel b/au/BUILD.bazel index a4d18db0..6f5ac26f 100644 --- a/au/BUILD.bazel +++ b/au/BUILD.bazel @@ -40,6 +40,13 @@ cc_test( ], ) +cc_library( + name = "fwd", + hdrs = ["code/au/fwd.hh"], + includes = ["code"], + visibility = ["//visibility:public"], +) + cc_library( name = "io", hdrs = ["code/au/io.hh"], @@ -208,6 +215,7 @@ cc_library( hdrs = ["code/au/constant.hh"], includes = ["code"], deps = [ + ":fwd", ":quantity", ":unit_of_measure", ":wrapper_operations", @@ -254,6 +262,7 @@ cc_library( hdrs = ["code/au/dimension.hh"], includes = ["code"], deps = [ + ":fwd", ":packs", ":power_aliases", ], @@ -276,6 +285,7 @@ cc_library( hdrs = ["code/au/magnitude.hh"], includes = ["code"], deps = [ + ":fwd", ":packs", ":power_aliases", ":stdx", @@ -389,6 +399,7 @@ cc_library( hdrs = ["code/au/prefix.hh"], includes = ["code"], deps = [ + ":fwd", ":quantity", ":quantity_point", ":unit_of_measure", @@ -414,6 +425,7 @@ cc_library( deps = [ ":apply_magnitude", ":conversion_policy", + ":fwd", ":operators", ":rep", ":unit_of_measure", @@ -443,6 +455,7 @@ cc_library( hdrs = ["code/au/quantity_point.hh"], includes = ["code"], deps = [ + ":fwd", ":quantity", ":stdx", ":utility", @@ -465,7 +478,10 @@ cc_library( name = "rep", hdrs = ["code/au/rep.hh"], includes = ["code"], - deps = [":stdx"], + deps = [ + ":fwd", + ":stdx", + ], ) cc_test( @@ -540,7 +556,10 @@ cc_library( name = "unit_symbol", hdrs = ["code/au/unit_symbol.hh"], includes = ["code"], - deps = [":wrapper_operations"], + deps = [ + ":fwd", + ":wrapper_operations", + ], ) cc_test( @@ -598,6 +617,7 @@ cc_library( name = "zero", hdrs = ["code/au/zero.hh"], includes = ["code"], + deps = [":fwd"], ) cc_test( diff --git a/au/code/au/CMakeLists.txt b/au/code/au/CMakeLists.txt index be1de57d..860d89e7 100644 --- a/au/code/au/CMakeLists.txt +++ b/au/code/au/CMakeLists.txt @@ -28,6 +28,7 @@ header_only_library( constant.hh conversion_policy.hh dimension.hh + fwd.hh io.hh magnitude.hh math.hh diff --git a/au/code/au/constant.hh b/au/code/au/constant.hh index 4f4b03ac..b41b5155 100644 --- a/au/code/au/constant.hh +++ b/au/code/au/constant.hh @@ -14,6 +14,7 @@ #pragma once +#include "au/fwd.hh" #include "au/quantity.hh" #include "au/quantity_point.hh" #include "au/stdx/type_traits.hh" diff --git a/au/code/au/dimension.hh b/au/code/au/dimension.hh index ff308d6f..d6dfdedf 100644 --- a/au/code/au/dimension.hh +++ b/au/code/au/dimension.hh @@ -14,6 +14,7 @@ #pragma once +#include "au/fwd.hh" #include "au/packs.hh" #include "au/power_aliases.hh" diff --git a/au/code/au/fwd.hh b/au/code/au/fwd.hh new file mode 100644 index 00000000..cb173822 --- /dev/null +++ b/au/code/au/fwd.hh @@ -0,0 +1,168 @@ +// Copyright 2024 Aurora Operations, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#pragma once + +#include + +namespace au { + +struct Zero; + +template +struct Dimension; + +template +struct Magnitude; + +template +struct QuantityMaker; + +template +struct SingularNameFor; + +template +struct QuantityPointMaker; + +template +class Quantity; + +// +// Quantity aliases to set a particular Rep. +// +// This presents a less cumbersome interface for end users. +// +template +using QuantityD = Quantity; +template +using QuantityF = Quantity; +template +using QuantityI = Quantity; +template +using QuantityU = Quantity; +template +using QuantityI32 = Quantity; +template +using QuantityU32 = Quantity; +template +using QuantityI64 = Quantity; +template +using QuantityU64 = Quantity; + +template +struct CorrespondingQuantity; + +template +class QuantityPoint; + +// +// QuantityPoint aliases to set a particular Rep. +// +// This presents a less cumbersome interface for end users. +// +template +using QuantityPointD = QuantityPoint; +template +using QuantityPointF = QuantityPoint; +template +using QuantityPointI = QuantityPoint; +template +using QuantityPointU = QuantityPoint; +template +using QuantityPointI32 = QuantityPoint; +template +using QuantityPointU32 = QuantityPoint; +template +using QuantityPointI64 = QuantityPoint; +template +using QuantityPointU64 = QuantityPoint; + +template +struct Constant; + +template +struct SymbolFor; + +template