construct.h
Go to the documentation of this file.
/* construct.h
*/
#ifndef OSL_CONSTRUCT_H
#define OSL_CONSTRUCT_H
#include <boost/type_traits/has_trivial_destructor.hpp>
#include <boost/type_traits/is_pod.hpp>
#include <boost/utility/enable_if.hpp>
#include <iterator>
#include <memory>
#include <cassert>
namespace osl
{
class Piece;
class Move;
class Square;
namespace rating
{
class RatedMove;
}
namespace misc
{
namespace detail
{
template <typename T>
struct BitCopyTraits
{
static const bool value=boost::is_pod<T>::value;
};
template <> struct BitCopyTraits<Move> { static const bool value=true; };
template <> struct BitCopyTraits<Piece> { static const bool value=true; };
template <> struct BitCopyTraits<Square> { static const bool value=true; };
template <> struct BitCopyTraits<rating::RatedMove> { static const bool value=true; };
}
template <typename T1, typename T2>
inline
void construct(T1* ptr, const T2& value,
typename boost::enable_if<detail::BitCopyTraits<T1> >::type * =0)
{
assert(ptr);
*ptr = T1(value);
}
template <typename T1, typename T2>
inline
void construct(T1* ptr, const T2& value,
typename boost::disable_if<detail::BitCopyTraits<T1> >::type * =0)
{
assert(ptr);
::new(ptr) T1(value);
}
template <typename T>
inline void destroy(T *ptr)
{
ptr->~T();
}
template <typename ForwardIterator>
inline void destroy(ForwardIterator first, ForwardIterator last)
{
typedef typename std::iterator_traits<ForwardIterator>::value_type
value_type;
if (boost::has_trivial_destructor<value_type>::value)
return;
for (; first != last; ++first)
destroy(&*first);
}
}
}
#endif /* OSL_CONSTRUCT_H */
// ;;; Local Variables:
// ;;; mode:c++
// ;;; c-basic-offset:2
// ;;; End:
osl::Move
圧縮していない moveの表現 .
Definition basic_type.h:1052
osl::Piece
駒.
Definition basic_type.h:788
osl::Square
Definition basic_type.h:532
osl::rating::RatedMove
Definition ratedMove.h:14
osl::misc::detail
Definition construct.h:24
osl::misc
Definition basic_type.h:66
osl::misc::construct
void construct(T1 *ptr, const T2 &value, typename boost::enable_if< detail::BitCopyTraits< T1 > >::type *=0)
Definition construct.h:40
osl::misc::destroy
void destroy(T *ptr)
Definition construct.h:57
osl::rating
Definition construct.h:18
osl
Definition additionalEffect.h:6
osl::misc::detail::BitCopyTraits< Move >::value
static const bool value
Definition construct.h:32
osl::misc::detail::BitCopyTraits< Piece >::value
static const bool value
Definition construct.h:33
osl::misc::detail::BitCopyTraits< Square >::value
static const bool value
Definition construct.h:34
osl::misc::detail::BitCopyTraits< rating::RatedMove >::value
static const bool value
Definition construct.h:35
osl::misc::detail::BitCopyTraits
use raw memory copy instead of placement new not to test a given pointer is null
Definition construct.h:28
osl::misc::detail::BitCopyTraits::value
static const bool value
Definition construct.h:29