1 // Created on: 2015-06-26
2 // Created by: Andrey Betenev
3 // Copyright (c) 2015 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #ifndef NCollection_Shared_HeaderFile
17 #define NCollection_Shared_HeaderFile
19 #include <NCollection_DefineAlloc.hxx>
21 //! Template defining a class derived from the specified base class and
22 //! Standard_Transient, and supporting OCCT RTTI.
24 //! This provides possibility to use Handes for types not initially intended
25 //! to be dynamically allocated.
27 //! Current limitation is that only copy and constructors with 1-3 arguments are defined,
28 //! calling those of the argument class (default constructor must be available).
29 //! It can be improved when perfect forwarding of template arguments is supported
30 //! by all compilers used for OCCT.
32 //! The intent is similar to std::make_shared<> in STL, except that this
33 //! implementation defines a separate type.
35 template <class T, typename = typename opencascade::std::enable_if<! opencascade::std::is_base_of<Standard_Transient, T>::value>::type>
36 class NCollection_Shared : public Standard_Transient, public T
40 DEFINE_NCOLLECTION_ALLOC
42 //! Default constructor
43 NCollection_Shared () {}
45 //! Constructor with single argument
46 template<typename T1> NCollection_Shared (const T1& arg1) : T(arg1) {}
48 //! Constructor with single argument
49 template<typename T1> NCollection_Shared (T1& arg1) : T(arg1) {}
51 //! Constructor with two arguments
52 template<typename T1, typename T2> NCollection_Shared (const T1& arg1, const T2& arg2) : T(arg1, arg2) {}
54 //! Constructor with two arguments
55 template<typename T1, typename T2> NCollection_Shared (T1& arg1, const T2& arg2) : T(arg1, arg2) {}
57 //! Constructor with two arguments
58 template<typename T1, typename T2> NCollection_Shared (const T1& arg1, T2& arg2) : T(arg1, arg2) {}
60 //! Constructor with two arguments
61 template<typename T1, typename T2> NCollection_Shared (T1& arg1, T2& arg2) : T(arg1, arg2) {}
64 //! Forwarding constructor
65 template<typename... Args>
66 NCollection_Shared (Args&&... args)
67 : T (std::forward<Args>(args)...)