What's your convention for typedef'ing shared_ptr?

后端 未结 16 1634
北恋
北恋 2020-12-13 00:10

I\'m flip-flopping between naming conventions for typedef\'ing the boost::shared_ptr template. For example:

typedef boost::shared_ptr FooPtr;


        
相关标签:
16条回答
  • 2020-12-13 00:41
    class foo;
    
    typedef boost::shared_ptr<foo> foo_p;
    typedef boost::weak_ptr<foo> foo_wp;
    
    0 讨论(0)
  • 2020-12-13 00:44

    typedef boost::shared_ptr&lt;MyClass> MyClass$;

    0 讨论(0)
  • 2020-12-13 00:45

    My preference:

    class Foo
    {
    public:
    
        typedef boost::shared_ptr<Foo> SharedPointer;
    };
    

    The problem with just FooPtr is that you may have different types of pointers (e.g., weak_ptrs). I also don't much care for abbreviations, but that's another matter altogether.

    0 讨论(0)
  • 2020-12-13 00:47

    I would get rid of the namespace instead of shortening the type.

    using boost::shared_ptr; // or using std::shared_ptr, 
    struct Foo
    {
        shared_ptr<Foo> impl;
    };
    

    Which has the bonus that you can change between implementations easily.

    If that is still too long (I think it is just right):

    using boost::shared_ptr;
    template<class T> using sptr = shared_ptr<T>;
    struct Foo
    {
        sptr<Foo> impl;
    };
    
    0 讨论(0)
提交回复
热议问题