How to fix error refactoring decltype inside template

后端 未结 3 1720
萌比男神i
萌比男神i 2021-01-19 07:00

edit Possibly can\'t be done, see Clean implementation of function template taking function pointer although answer 1 there has a C macro work-around https://stacko

3条回答
  •  囚心锁ツ
    2021-01-19 07:25

    You cannot use decltype with a type as the goal is to obtain the type of a variable. But in decltype(&D), D is a type.

    I would rather pass throught a template function:

    template
    class unique_gptr : public std::unique_ptr {
        public: unique_gptr(T* t) : std::unique_ptr(t, F) { };
    };
    
    template 
    unique_gptr make_unique_gptr(T pointer, D deleter)
    {
        return unique_gptr(pointer);
    }
    
    auto ptr = make_unique(new int(2), ::free_int);
    

提交回复
热议问题