---
title: llarp/util/compare_ptr.hpp

---

# llarp/util/compare_ptr.hpp



## Namespaces

| Name           |
| -------------- |
| **[llarp](Namespaces/namespacellarp.md)** <br>[crypto.hpp] |

## Classes

|                | Name           |
| -------------- | -------------- |
| struct | **[llarp::ComparePtr](Classes/structllarp_1_1ComparePtr.md)** <br>type for comparing smart pointer's managed values  |
| struct | **[llarp::CompareWeakPtr](Classes/structllarp_1_1CompareWeakPtr.md)** <br>type for comparing weak_ptr by value  |




## Source code

```cpp
#pragma once
#include <functional>
#include <memory>

namespace llarp
{
  template <typename Ptr_t, typename Compare = std::less<>>
  struct ComparePtr
  {
    bool
    operator()(const Ptr_t& left, const Ptr_t& right) const
    {
      if (left && right)
        return Compare()(*left, *right);

      return Compare()(left, right);
    }
  };

  template <typename Type_t, typename Compare = std::less<>>
  struct CompareWeakPtr
  {
    bool
    operator()(const std::weak_ptr<Type_t>& left, const std::weak_ptr<Type_t>& right) const
    {
      return ComparePtr<std::shared_ptr<Type_t>, Compare>{}(left.lock(), right.lock());
    }
  };

}  // namespace llarp
```


-------------------------------

Updated on 2023-01-20 at 23:19:39 +0000
