mirror of
https://github.com/facebook/sapling.git
synced 2024-10-10 00:45:18 +03:00
3d82713027
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
26 lines
587 B
C++
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
|