boost/checked_delete.hpp
Posted on 2009-06-22 13:26 天邊藍(lán) 閱讀(586) 評(píng)論(0) 編輯 收藏 引用 所屬分類(lèi): boost學(xué)習(xí)

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25



26

27

28

29

30



31

32

33

34

35

36

37

38



39

40

41

42

43

44

45



46

47

48

49

50



51

52

53

54

55

56

57



58

59

60

61

62



63

64

65

66

67

68

69

------------------------------------
source:http://www.boost.org/doc/libs/1_39_0/libs/utility/checked_delete.html
The header <boost/checked_delete.hpp> defines two function templates, checked_delete and checked_array_delete, and two class templates, checked_deleter and checked_array_deleter.
The C++ Standard allows, in 5.3.5/5, pointers to incomplete class types to be deleted with a delete-expression. When the class has a non-trivial destructor, or a class-specific operator delete, the behavior is undefined. Some compilers issue a warning when an incomplete type is deleted, but unfortunately, not all do, and programmers sometimes ignore or disable warnings.
A particularly troublesome case is when a smart pointer's destructor, such as boost::scoped_ptr<T>::~scoped_ptr, is instantiated with an incomplete type. This can often lead to silent, hard to track failures.
The supplied function and class templates can be used to prevent these problems, as they require a complete type, and cause a compilation error otherwise.
Synopsis

2



3

4

5

6

7

8

9

10

11

12

13

14

Requires: T must be a complete type. The expression delete p must be well-formed.
Effects: delete p;

2

3

4

5

6

7

8

9



10

11

12

13

14

15

16

17

Requires: T must be a complete type. The expression delete p must be well-formed.
Effects: delete p;

2

3



4

5

6

7

8

9

10

Requires: T must be a complete type. The expression delete [] p must be well-formed.
Effects: delete [] p;
Acknowledgements
The function templates checked_delete and checked_array_delete were originally part of <boost/utility.hpp>, and the documentation acknowledged Beman Dawes, Dave Abrahams, Vladimir Prus, Rainer Deyke, John Maddock, and others as contributors.
Copyright © 2002 by Peter Dimov. Distributed under the Boost Software License, Version 1.0. See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.