From 75495a44dc228432ec7563b9ada0353ab80b4bd3 Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Fri, 16 Jul 2021 12:49:52 -0400 Subject: [PATCH] Fix BUILD: add src/lib/support/TypeTraits.h from main branch since cherrypicks depend on it --- src/lib/support/TypeTraits.h | 41 ++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/lib/support/TypeTraits.h diff --git a/src/lib/support/TypeTraits.h b/src/lib/support/TypeTraits.h new file mode 100644 index 00000000000000..4eb344b2ce9fc7 --- /dev/null +++ b/src/lib/support/TypeTraits.h @@ -0,0 +1,41 @@ +/* + * + * Copyright (c) 2021 Project CHIP Authors + * + * 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. + */ + +/** + * @file + * This file defines and implements a number of miscellaneous + * templates for simplify code with handling types. + * + */ + +#pragma once + +#include + +namespace chip { + +/** + * @brief Implemented std::to_underlying introduced in C++23. + */ +template +constexpr std::underlying_type_t to_underlying(T e) +{ + static_assert(std::is_enum::value, "to_underlying called to non-enum values."); + return static_cast>(e); +} + +} // namespace chip