Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

get_deleter Function

Get deleter from shared_ptr.

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

The type of the deleter.

Ty

The type controlled by the shared pointer.

Other

The shared pointer.

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.

 

// 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

Header: <memory>

Namespace: std

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.