欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

boost笔记2

程序员文章站 2022-07-03 20:27:29
...

看到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名字空间隔离的作用。