Compartilhar via


get_deleter Function

Get deleter from shared_ptr.

template<class D, class Ty>
    D *get_deleter(const shared_ptr<Ty>& sp);

Parameters

  • D
    The type of the deleter.

  • Ty
    The type controlled by the shared pointer.

  • Other
    The shared pointer.

Remarks

The template function returns a pointer to the deleter of type D that belongs to the shared_ptr Class object sp. If sp has no deleter or if its deleter is not of type D the function returns 0.

Example

 

// std_tr1__memory__get_deleter.cpp 
// compile with: /EHsc 
#include <memory> 
#include <iostream> 
 
struct base 
    { 
    int val; 
    }; 
 
struct deleter 
    { 
    void operator()(base *p) 
        { 
        delete p; 
        } 
    }; 
 
int main() 
    { 
    std::shared_ptr<base> sp0(new base); 
 
    sp0->val = 3; 
    std::cout << "get_deleter(sp0) != 0 == " << std::boolalpha 
        << (std::get_deleter<deleter>(sp0) != 0) << std::endl; 
 
    std::shared_ptr<base> sp1(new base, deleter()); 
 
    sp0->val = 3; 
    std::cout << "get_deleter(sp1) != 0 == " << std::boolalpha 
        << (std::get_deleter<deleter>(sp1) != 0) << std::endl; 
 
    return (0); 
    } 
 
get_deleter(sp0) != 0 == false
get_deleter(sp1) != 0 == true

Requirements

Header: <memory>

Namespace: std

See Also

Reference

shared_ptr Class

Other Resources

<memory> Members