plastimatch
Loading...
Searching...
No Matches
smart_pointer.h
Go to the documentation of this file.
1/* -----------------------------------------------------------------------
2 See COPYRIGHT.TXT and LICENSE.TXT for copyright and license information
3 ----------------------------------------------------------------------- */
4#ifndef _smart_pointer_h_
5#define _smart_pointer_h_
6
7#include "plm_config.h"
8
9#if PLM_CUDA_COMPILE
10/* There is a bug in Linux CUDA 4.x nvcc compiler which causes it to
11 barf with either dlib::shared_ptr or std::shared_ptr */
12# define SMART_POINTER_SUPPORT(T) \
13 typedef void* Pointer
14#else
15
16# include <memory>
17# define plm_shared_ptr std::shared_ptr
18
19# define SMART_POINTER_SUPPORT(T) \
20 public: \
21 typedef T Self; \
22 typedef plm_shared_ptr<Self> Pointer; \
23 static typename T::Pointer New () { \
24 return T::Pointer (new T); \
25 } \
26 static typename T::Pointer New (T* t) { \
27 return T::Pointer (t); \
28 } \
29 template<class U1 \
30 > static typename T::Pointer New ( \
31 const U1& u1) { \
32 return T::Pointer ( \
33 new T(u1)); \
34 } \
35 template<class U1, class U2 \
36 > static typename T::Pointer New ( \
37 const U1& u1, const U2& u2) { \
38 return T::Pointer ( \
39 new T(u1, u2)); \
40 } \
41 template<class U1, class U2, class U3 \
42 > static typename T::Pointer New ( \
43 const U1& u1, const U2& u2, const U3& u3) { \
44 return T::Pointer ( \
45 new T(u1, u2, u3)); \
46 } \
47 template<class U1, class U2, class U3, \
48 class U4, class U5, class U6 \
49 > static typename T::Pointer New ( \
50 const U1& u1, const U2& u2, const U3& u3, \
51 const U4& u4, const U5& u5, const U6& u6) { \
52 return T::Pointer ( \
53 new T(u1, u2, u3, u4, u5, u6)); \
54 }
55
56/* A warning for the future.
57 (1) Template parameter assignment produces types, and therefore
58 arguments to New() are pass-by value
59 (2a) Therefore, classes without copy constructors require
60 explicit reference in signature; for example:
61 template <class U> foo (U& u);
62 (2b) In principle, using a reference should be faster, because
63 a copy constructor is not needed.
64 (3) However, you cannot overload based on reference. The gcc
65 compiler (probably others too) can't resolve:
66 template <class U> foo (U u);
67 template <class U> foo (const U& u);
68*/
69
70#endif
71
72#endif