summaryrefslogtreecommitdiff
path: root/cpp/src/Ice/VirtualShared.h
blob: 9b8f4a48929227f86c97a2279fd515f402a54a97 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
//
// Copyright (c) ZeroC, Inc. All rights reserved.
//

#ifndef ICE_VIRTUAL_SHARED_H
#define ICE_VIRTUAL_SHARED_H

#ifdef ICE_CPP11_MAPPING

namespace IceInternal
{

class VirtualEnableSharedFromThisBase : public std::enable_shared_from_this<VirtualEnableSharedFromThisBase>
{
public:

    virtual ~VirtualEnableSharedFromThisBase() = default;
};

template<typename T>
class EnableSharedFromThis : public virtual VirtualEnableSharedFromThisBase
{
public:

    std::shared_ptr<T> shared_from_this()
    {
        return std::dynamic_pointer_cast<T>(VirtualEnableSharedFromThisBase::shared_from_this());
    }

    std::shared_ptr<T const> shared_from_this() const
    {
        return std::dynamic_pointer_cast<T const>(VirtualEnableSharedFromThisBase::shared_from_this());
    }
};

}
#endif
#endif