as_const.h 569 B

123456789101112131415161718192021222324
  1. // Copyright 2021 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef BASE_AS_CONST_H_
  5. #define BASE_AS_CONST_H_
  6. #include <type_traits>
  7. namespace base {
  8. // C++14 implementation of C++17's std::as_const():
  9. // https://en.cppreference.com/w/cpp/utility/as_const
  10. template <typename T>
  11. constexpr std::add_const_t<T>& as_const(T& t) noexcept {
  12. return t;
  13. }
  14. template <typename T>
  15. void as_const(const T&& t) = delete;
  16. } // namespace base
  17. #endif // BASE_AS_CONST_H_