sapling/eden/fs/utils/EnumValue.h
Chad Austin 3d82713027 add enumValue utility function
Summary:
Previously, for logging the value of unexpected enum values, we wrote
`static_cast<int>`. Given enumerations can have any integral type
backing them, this was somewhat inaccurate. Instead, introduce an
explicit enumValue function which returns a value of the appropriate
underlying type.

Reviewed By: genevievehelsel

Differential Revision: D20975176

fbshipit-source-id: 0bb5b0d2f68f8fe9d68e4c6a847d59ae0997d0df
2020-04-28 17:41:24 -07:00

26 lines
587 B
C++

/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This software may be used and distributed according to the terms of the
* GNU General Public License version 2.
*/
#pragma once
#include <folly/Utility.h>
namespace facebook {
namespace eden {
/**
* It's common in error messages to log the underlying value of an enumeration.
* Bring a short function into the eden namespace to retrieve that value.
*/
template <typename E>
constexpr std::underlying_type_t<E> enumValue(E e) noexcept {
return folly::to_underlying(e);
}
} // namespace eden
} // namespace facebook