1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2017 Red Hat, Inc.
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
15 #ifndef CEPH_ALLOC_PTR_H
16 #define CEPH_ALLOC_PTR_H
24 typedef typename std::pointer_traits< std::unique_ptr<T> >::pointer pointer;
25 typedef typename std::pointer_traits< std::unique_ptr<T> >::element_type element_type;
27 alloc_ptr() : ptr() {}
30 alloc_ptr(U&& u) : ptr(std::forward<U>(u)) {}
32 alloc_ptr(alloc_ptr<pointer>&& rhs) : ptr(std::move(rhs.ptr)) {}
33 alloc_ptr(const alloc_ptr<pointer>& rhs) = delete;
34 alloc_ptr& operator=(const alloc_ptr<pointer>&& rhs) {
37 alloc_ptr& operator=(const alloc_ptr<pointer>& rhs) {
41 void swap (alloc_ptr<pointer>& rhs) {
44 element_type* release() {
47 void reset(element_type *p = nullptr) {
50 element_type* get() const {
52 ptr.reset(new element_type);
55 element_type& operator*() const {
57 ptr.reset(new element_type);
60 element_type* operator->() const {
62 ptr.reset(new element_type);
65 operator bool() const {
69 friend bool operator< (const alloc_ptr& lhs, const alloc_ptr& rhs) {
70 return std::less<element_type>(*lhs, *rhs);
72 friend bool operator<=(const alloc_ptr& lhs, const alloc_ptr& rhs) {
73 return std::less_equal<element_type>(*lhs, *rhs);
75 friend bool operator> (const alloc_ptr& lhs, const alloc_ptr& rhs) {
76 return std::greater<element_type>(*lhs, *rhs);
78 friend bool operator>=(const alloc_ptr& lhs, const alloc_ptr& rhs) {
79 return std::greater_equal<element_type>(*lhs, *rhs);
81 friend bool operator==(const alloc_ptr& lhs, const alloc_ptr& rhs) {
84 friend bool operator!=(const alloc_ptr& lhs, const alloc_ptr& rhs) {
88 mutable std::unique_ptr<element_type> ptr;