1 // Copyright 2023 The Chromium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef PARTITION_ALLOC_PARTITION_ALLOC_BASE_CXX20_IS_CONSTANT_EVALUATED_H_ 6 #define PARTITION_ALLOC_PARTITION_ALLOC_BASE_CXX20_IS_CONSTANT_EVALUATED_H_ 7 8 #include <type_traits> 9 10 namespace partition_alloc::internal::base { 11 12 // std::is_constant_evaluated was introduced in C++20. PartitionAlloc's minimum 13 // supported C++ version is C++17. 14 #if defined(__cpp_lib_is_constant_evaluated) && \ 15 __cpp_lib_is_constant_evaluated >= 201811L 16 17 using std::is_constant_evaluated; 18 19 #else 20 21 // Implementation of C++20's std::is_constant_evaluated. 22 // 23 // References: 24 // - https://en.cppreference.com/w/cpp/types/is_constant_evaluated 25 // - https://wg21.link/meta.const.eval 26 constexpr bool is_constant_evaluated() noexcept { 27 return __builtin_is_constant_evaluated(); 28 } 29 30 #endif 31 32 } // namespace partition_alloc::internal::base 33 34 #endif // PARTITION_ALLOC_PARTITION_ALLOC_BASE_CXX20_IS_CONSTANT_EVALUATED_H_ 35