• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 BASE_ALLOCATOR_PARTITION_ALLOCATOR_PARTITION_ALLOC_BASE_CXX20_IS_CONSTANT_EVALUATED_H_
6 #define BASE_ALLOCATOR_PARTITION_ALLOCATOR_PARTITION_ALLOC_BASE_CXX20_IS_CONSTANT_EVALUATED_H_
7 
8 namespace partition_alloc::internal::base {
9 
10 // std::is_constant_evaluated was introduced in C++20. PartitionAlloc's minimum
11 // supported C++ version is C++17.
12 #if defined(__cpp_lib_is_constant_evaluated) && \
13     __cpp_lib_is_constant_evaluated >= 201811L
14 
15 #include <type_traits>
16 using std::is_constant_evaluated;
17 
18 #else
19 
20 // Implementation of C++20's std::is_constant_evaluated.
21 //
22 // References:
23 // - https://en.cppreference.com/w/cpp/types/is_constant_evaluated
24 // - https://wg21.link/meta.const.eval
25 constexpr bool is_constant_evaluated() noexcept {
26   return __builtin_is_constant_evaluated();
27 }
28 
29 #endif
30 
31 }  // namespace partition_alloc::internal::base
32 
33 #endif  // BASE_ALLOCATOR_PARTITION_ALLOCATOR_PARTITION_ALLOC_BASE_CXX20_IS_CONSTANT_EVALUATED_H_
34