cxx20_is_constant_evaluated.h (713B)
1 // Copyright 2022 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_CXX20_IS_CONSTANT_EVALUATED_H_ 6 #define BASE_CXX20_IS_CONSTANT_EVALUATED_H_ 7 8 #include "base/compiler_specific.h" 9 10 namespace base { 11 12 // Implementation of C++20's std::is_constant_evaluated. 13 // 14 // References: 15 // - https://en.cppreference.com/w/cpp/types/is_constant_evaluated 16 // - https://wg21.link/meta.const.eval 17 constexpr bool is_constant_evaluated() noexcept { 18 #if HAS_BUILTIN(__builtin_is_constant_evaluated) 19 return __builtin_is_constant_evaluated(); 20 #else 21 return false; 22 #endif 23 } 24 25 } // namespace base 26 27 #endif // BASE_CXX20_IS_CONSTANT_EVALUATED_H_