as_const_unittest.cc 859 B

12345678910111213141516171819202122232425262728
  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. #include "base/as_const.h"
  5. #include <type_traits>
  6. #include "testing/gtest/include/gtest/gtest.h"
  7. namespace base {
  8. namespace {
  9. TEST(AsConstTest, AsConst) {
  10. int i = 123;
  11. EXPECT_EQ(&i, &base::as_const(i));
  12. static_assert(std::is_same<const int&, decltype(base::as_const(i))>::value,
  13. "Error: base::as_const() returns an unexpected type");
  14. const int ci = 456;
  15. static_assert(&ci == &base::as_const(ci),
  16. "Error: base::as_const() returns an unexpected reference");
  17. static_assert(std::is_same<const int&, decltype(base::as_const(ci))>::value,
  18. "Error: base::as_const() returns an unexpected type");
  19. }
  20. } // namespace
  21. } // namespace base