| 509 | |
| 510 | template <class T, class Ops> |
| 511 | class TIntrusivePtr: public TPointerBase<TIntrusivePtr<T, Ops>, T> { |
| 512 | template <class U, class O> |
| 513 | friend class TIntrusivePtr; |
| 514 | |
| 515 | template <class U, class O> |
| 516 | friend class TIntrusiveConstPtr; |
| 517 | |
| 518 | public: |
| 519 | struct TNoIncrement { |
| 520 | }; |
| 521 | |
| 522 | inline TIntrusivePtr(T* t = nullptr) noexcept |
| 523 | : T_(t) |
| 524 | { |
| 525 | Ops(); |
| 526 | Ref(); |
| 527 | } |
| 528 | |
| 529 | inline TIntrusivePtr(T* t, TNoIncrement) noexcept |
| 530 | : T_(t) |
| 531 | { |
| 532 | Ops(); |
| 533 | } |
| 534 | |
| 535 | inline ~TIntrusivePtr() { |
| 536 | UnRef(); |
| 537 | } |
| 538 | |
| 539 | inline TIntrusivePtr(const TIntrusivePtr& p) noexcept |
| 540 | : T_(p.T_) |
| 541 | { |
| 542 | Ref(); |
| 543 | } |
| 544 | |
| 545 | // NOTE: |
| 546 | // without std::enable_if_t compiler sometimes tries to use this constructor inappropriately |
| 547 | // e.g. |
| 548 | // struct A {}; |
| 549 | // struct B {}; |
| 550 | // void Func(TIntrusivePtr<A>); |
| 551 | // void Func(TIntrusivePtr<B>); |
| 552 | // ... |
| 553 | // Func(TIntrusivePtr<A>(new A)); // <--- compiler can't decide which version of Func to use |
| 554 | template <class U, class = TGuardConversion<T, U>> |
| 555 | inline TIntrusivePtr(const TIntrusivePtr<U>& p) noexcept |
| 556 | : T_(p.Get()) |
| 557 | { |
| 558 | Ref(); |
| 559 | } |
| 560 | |
| 561 | template <class U, class = TGuardConversion<T, U>> |
| 562 | inline TIntrusivePtr(TIntrusivePtr<U>&& p) noexcept |
| 563 | : T_(p.T_) |
| 564 | { |
| 565 | p.T_ = nullptr; |
| 566 | } |
| 567 | |
| 568 | inline TIntrusivePtr(TIntrusivePtr&& p) noexcept |