---
title: "boost笔记2"
author: "grantren"
date: "2008-07-28T09:44:13Z"
tags: []
categories: ["编程语言"]
slug: "boost-2"
draft: false
lastmod: "2008-07-28T09:44:13Z"
id: 220329
url: "https://grantren.iteye.com/blog/220329"
---

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