My Project
construct.h
Go to the documentation of this file.
1/* construct.h
2 */
3#ifndef OSL_CONSTRUCT_H
4#define OSL_CONSTRUCT_H
5
6#include <boost/type_traits/has_trivial_destructor.hpp>
7#include <boost/type_traits/is_pod.hpp>
8#include <boost/utility/enable_if.hpp>
9#include <iterator>
10#include <memory>
11#include <cassert>
12namespace osl
13{
14 class Piece;
15 class Move;
16 class Square;
17 namespace rating
18 {
19 class RatedMove;
20 }
21 namespace misc
22 {
23 namespace detail
24 {
26 template <typename T>
28 {
29 static const bool value=boost::is_pod<T>::value;
30 };
31
32 template <> struct BitCopyTraits<Move> { static const bool value=true; };
33 template <> struct BitCopyTraits<Piece> { static const bool value=true; };
34 template <> struct BitCopyTraits<Square> { static const bool value=true; };
35 template <> struct BitCopyTraits<rating::RatedMove> { static const bool value=true; };
36 }
37
38 template <typename T1, typename T2>
39 inline
40 void construct(T1* ptr, const T2& value,
41 typename boost::enable_if<detail::BitCopyTraits<T1> >::type * =0)
42 {
43 assert(ptr);
44 *ptr = T1(value);
45 }
46
47 template <typename T1, typename T2>
48 inline
49 void construct(T1* ptr, const T2& value,
50 typename boost::disable_if<detail::BitCopyTraits<T1> >::type * =0)
51 {
52 assert(ptr);
53 ::new(ptr) T1(value);
54 }
55
56 template <typename T>
57 inline void destroy(T *ptr)
58 {
59 ptr->~T();
60 }
61
62 template <typename ForwardIterator>
63 inline void destroy(ForwardIterator first, ForwardIterator last)
64 {
65 typedef typename std::iterator_traits<ForwardIterator>::value_type
66 value_type;
67 if (boost::has_trivial_destructor<value_type>::value)
68 return;
69 for (; first != last; ++first)
70 destroy(&*first);
71 }
72 }
73}
74
75
76#endif /* OSL_CONSTRUCT_H */
77// ;;; Local Variables:
78// ;;; mode:c++
79// ;;; c-basic-offset:2
80// ;;; End:
圧縮していない moveの表現 .
void construct(T1 *ptr, const T2 &value, typename boost::enable_if< detail::BitCopyTraits< T1 > >::type *=0)
Definition construct.h:40
void destroy(T *ptr)
Definition construct.h:57
use raw memory copy instead of placement new not to test a given pointer is null
Definition construct.h:28