brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.2 KiB · e4c62f3 Raw
55 lines · cpp
1//===----------------------------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9// <memory>10 11// template <class Ptr>12// struct pointer_traits13// {14//     static pointer pointer_to(<details>);15//     ...16// };17 18#include <memory>19#include <cassert>20#include <type_traits>21 22#include "test_macros.h"23 24template <class T>25struct A {26private:27  struct nat {};28 29public:30  typedef T element_type;31  element_type* t_;32 33  A(element_type* t) : t_(t) {}34 35  static A pointer_to(typename std::conditional<std::is_void<element_type>::value, nat, element_type>::type& et) {36    return A(&et);37  }38};39 40template <class Pointer>41void test() {42  typename Pointer::element_type obj;43  static_assert(std::is_same<Pointer, decltype(std::pointer_traits<Pointer>::pointer_to(obj))>::value, "");44  Pointer p = std::pointer_traits<Pointer>::pointer_to(obj);45  assert(p.t_ == &obj);46}47 48int main(int, char**) {49  test<A<int> >();50  test<A<long> >();51  { (std::pointer_traits<A<void> >::element_type)0; }52 53  return 0;54}55