1

Topic: How to receive type under the pointer on it?

That it would be desirable: somehow automatically to deduce type in which specifies the pointer, having only type of the pointer. An example: template <class T> class a C {public: a C (T* t) {};}; struct S {int _internal;}; S* CreateS () {return new S ();} typedef S* PS; int main () {PS p = CreateS ();//As the C <S> c1 (p) turns out;//As it would be desirable, but it is impossible: a C <*PS> c2 (p);//Or something similar.} what for: happens so that the pointer is described in API, and that, on what he specifies, no. Whence young growth feet: Wanted HKEY from Win32 to envelop in unique_ptr with RegCloseKey in quality deleter'a. All is good, only as type in the designer unique_ptr it is necessary to transfer HKEY __, instead of *HKEY or something similar.

2

Re: How to receive type under the pointer on it?

Hello, LazyKarlson, you wrote: LK> automatically to deduce type in which specifies the pointer, having only type of the pointer. std:: remove_pointer_t

3

Re: How to receive type under the pointer on it?

Hello, LazyKarlson, you wrote: LK> Whence young growth feet: Wanted HKEY from Win32 to envelop in unique_ptr with RegCloseKey in quality deleter'a. All is good, only as type in the designer unique_ptr it is necessary to transfer HKEY __, instead of *HKEY or something similar. Was specific for std:: unique_ptr there is an alternative - certain type pointer at class Deleter' struct RegKeyDeleter {using pointer = HKEY; void operator () (pointer p) const {RegCloseKey (p);}}; using unique_reg_key = std:: unique_ptr <HKEY, RegKeyDeleter>;

4

Re: How to receive type under the pointer on it?

Hello, Gaia, you wrote: G> It is is specific for std:: unique_ptr there is an alternative - certain type pointer at class Deleter' G> G> struct RegKeyDeleter G> {G> using pointer = HKEY; G> void operator () (pointer p) const G> {G> RegCloseKey (p); G>} G>}; G> using unique_reg_key = std:: unique_ptr <HKEY, RegKeyDeleter>; G> Too works, yes, though introduction of additional structure. Well. . But I not about it. I can not understand, why here so struct RegKeyDeleter {//using pointer = HKEY; void operator () (HKEY p) const {RegCloseKey (p);}}; using unique_reg_key = std:: unique_ptr <HKEY, RegKeyDeleter>; does not work? I only removed type redefinition...

5

Re: How to receive type under the pointer on it?

Hello, watchmaker, you wrote: LK>> automatically to deduce type in which specifies the pointer, having only type of the pointer. W> std:: remove_pointer_t yes, but it is not necessary to forget only that std:: remove_pointer it is applicable not only to pointers, and generally to any types. Meanwhile, the HARDWARE is going to apply it to  types for which it is not known, whether is the given type the pointer, or something to another. Probably, it was meaningful to define own metafunction, in order to avoid "surprises". Well at least so: template <typename, typename = void> struct MySpecialRemovePointer; template <typename T> struct MySpecialRemovePointer <T, std::enable_if_t<std::is_pointer<T>::value>>: std:: remove_pointer <T> {};

6

Re: How to receive type under the pointer on it?

By the way! If to write on pluses under WinAPI it would be very natural to take library ATL in which is clever . Was specific, here - CRegKey. Well or if ATL it would not be desirable to drag,  the - the same business of pair minutes. There not  , only - to write a heap of standard methods. It yes, but there it is necessary to steam of keys to consider. For this purpose ATL to connect, it would not be desirable to create additional structure. And here the output of the pointer from Deleter:: pointer was for me revelation. Thanks!

7

Re: How to receive type under the pointer on it?

Hello, rg45, you wrote: R> Yes, but it is not necessary to forget only that std:: remove_pointer it is applicable not only to pointers, and generally to any types. Meanwhile, the HARDWARE is going to apply it to  types for which it is not known, whether is the given type the pointer, or something to another. Probably, it was meaningful to define own metafunction, in order to avoid "surprises". Well at least so: It is possible is easier: template <typename T> using MySpecialRemovePointer = std:: enable_if <std:: is_pointer <T>:: value, std:: remove_pointer_t <T>>;