Created
February 4, 2019 16:38
-
-
Save zoecarver/94092aabab2f07d090bbf95a3c78da5e to your computer and use it in GitHub Desktop.
Highlighting a question I have
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template<class _Tp> | |
struct __shared_if | |
{ | |
typedef shared_ptr<_Tp> __shared_single; | |
}; | |
template<class _Tp> | |
struct __shared_if<_Tp[]> | |
{ | |
typedef shared_ptr<typename remove_extent<_Tp>::type> __shared_array_unknown_bound; | |
}; | |
template<class _Tp, size_t _Np> | |
struct __shared_if<_Tp[_Np]> | |
{ | |
typedef shared_ptr<_Tp[_Np]> __shared_array_known_bound; | |
}; | |
template<class _Tp, class ..._Args> | |
inline _LIBCPP_INLINE_VISIBILITY | |
typename __shared_if<_Tp>::__shared_single | |
make_shared(_Args&& ...__args) | |
{ | |
return shared_ptr<_Tp>::make_shared(_VSTD::forward<_Args>(__args)...); | |
} | |
template<class _Tp> | |
inline _LIBCPP_INLINE_VISIBILITY | |
typename __shared_if<_Tp>::__shared_array_unknown_bound | |
make_shared(size_t __n) | |
{ | |
typedef typename remove_extent<_Tp>::type _Up; | |
// HERE: | |
// how should I fix the return statement? | |
// unlike unique_ptr, returning _Tp[] does not work. | |
// So if I send it an array type it has to be like this: | |
return shared_ptr<_Up[__n]>(); | |
// which doesnt work (beause of how templates work) so I tried this: | |
return shared_ptr<_Up>(new _Up[__n]()); | |
// which technecally compiles and seems most similar to the unique_ptr implementation but still doesnt produce the correct result. | |
} | |
template<class _Tp> | |
inline _LIBCPP_INLINE_VISIBILITY | |
typename __shared_if<_Tp>::__shared_array_known_bound | |
make_shared() | |
{ | |
return shared_ptr<_Tp>::make_shared(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment