Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add MSVC coverage for Constant and UnitSymbol #363

Merged
merged 2 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/single-file-build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:

- name: Build single-file package
shell: cmd
run: python tools/bin/make-single-file --units meters seconds --version-id NA > au.hh
run: python tools/bin/make-single-file --units meters seconds --constants speed_of_light --version-id NA > au.hh

- name: Build and run test
shell: cmd
Expand Down
6 changes: 4 additions & 2 deletions au/code/au/constant.hh
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ struct Constant : detail::MakesQuantityFromNumber<Constant, Unit>,
// Convert this constant to a Quantity of the given unit and rep.
template <typename T, typename OtherUnit>
constexpr auto as(OtherUnit u) const {
static_assert(can_store_value_in<T>(u), "Cannot represent constant in this unit/rep");
static_assert(can_store_value_in<T>(OtherUnit{}),
"Cannot represent constant in this unit/rep");
return coerce_as<T>(u);
}

Expand All @@ -69,7 +70,8 @@ struct Constant : detail::MakesQuantityFromNumber<Constant, Unit>,
// Get the value of this constant in the given unit and rep.
template <typename T, typename OtherUnit>
constexpr auto in(OtherUnit u) const {
static_assert(can_store_value_in<T>(u), "Cannot represent constant in this unit/rep");
static_assert(can_store_value_in<T>(OtherUnit{}),
"Cannot represent constant in this unit/rep");
return coerce_in<T>(u);
}

Expand Down
3 changes: 3 additions & 0 deletions single-file-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
// dependencies outside of the C++14 standard library, and the single-file package of Au itself.

using namespace au;
using ::au::symbols::m;
using ::au::symbols::s;

// This ad hoc utility is a stand-in for GTEST, which we can't use here.
template <typename ExpectedT, typename ActualT>
Expand All @@ -42,6 +44,7 @@ int main(int argc, char **argv) {
const std::vector<bool> results{
{
expect_equal((meters / second)(5) * seconds(6), meters(30)),
expect_equal(SPEED_OF_LIGHT.as<int>(m / s), 299'792'458 * m / s),
},
};
return std::all_of(std::begin(results), std::end(results), [](auto x) { return x; }) ? 0 : 1;
Expand Down
Loading