`
grantren
  • 浏览: 76537 次
  • 来自: ...
文章分类
社区版块
存档分类
最新评论

boost笔记2

 
阅读更多

看到boost中noncopyable,基本思想很简单,无非把拷贝构造和赋值运算符声明为private并且不加以实现。
比较特殊的是noncopyable的实现中定义了noncopyable_名字空间,然后再将noncopyable使用typedef定义。

 

#ifndef BOOST_NONCOPYABLE_HPP_INCLUDED
#define BOOST_NONCOPYABLE_HPP_INCLUDED

namespace boost {

//  Private copy constructor and copy assignment ensure classes derived from
//  class noncopyable cannot be copied.

//  Contributed by Dave Abrahams

namespace noncopyable_  // protection from unintended ADL
{
  class noncopyable
  {
   protected:
      noncopyable() {}
      ~noncopyable() {}
   private:  // emphasize the following members are private
      noncopyable( const noncopyable& );
      const noncopyable& operator=( const noncopyable& );
  };
}

typedef noncopyable_::noncopyable noncopyable;

} // namespace boost

 

ADL是Argument Dependent Lookup的缩写,其实就是Koenig Lookup。
namespace noncopyable_ {
//..................
}

typedef noncopyable_::noncopyable noncopyable,
这样写是把noncopyable的具体实现定一个一个单独的名字空间内,
起到了和boost名字空间隔离的作用。

1
1
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics