[M108 Migration][VD] Support set time and time zone offset
[platform/framework/web/chromium-efl.git] / base / cxx20_to_address.h
1 // Copyright 2021 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_TO_ADDRESS_H_
6 #define BASE_CXX20_TO_ADDRESS_H_
7
8 #include <type_traits>
9
10 namespace base {
11
12 // Implementation of C++20's std::to_address.
13 // Note: This does consider specializations of pointer_traits<>::to_address,
14 // even though it's a C++20 member function, because CheckedContiguousIterator
15 // specializes pointer_traits<> with a to_address() member.
16 //
17 // Reference: https://wg21.link/pointer.conversion#lib:to_address
18 template <typename T>
19 constexpr T* to_address(T* p) noexcept {
20   static_assert(!std::is_function<T>::value,
21                 "Error: T must not be a function type.");
22   return p;
23 }
24
25 template <typename Ptr>
26 constexpr auto to_address(const Ptr& p) noexcept
27     -> decltype(std::pointer_traits<Ptr>::to_address(p)) {
28   return std::pointer_traits<Ptr>::to_address(p);
29 }
30
31 template <typename Ptr, typename... None>
32 constexpr auto to_address(const Ptr& p, None...) noexcept {
33   return base::to_address(p.operator->());
34 }
35
36 }  // namespace base
37
38 #endif  // BASE_CXX20_TO_ADDRESS_H_