|
Boost : |
From: jsiek_at_[hidden]
Date: 1999-12-14 13:16:54
Here's a specialization for pointers that should probably
go in the property_accessor.hpp file.
(at some pointer the ptrdiff_t should be replaced with
iterator_traits<T*>::difference_type, but ptrdiff_t is more portable
for now)
#ifndef BOOST_PROPERTY_ACCESSOR_HPP
#define BOOST_PROPERTY_ACCESSOR_HPP
namespace boost {
struct readable_property_accessor_tag {};
struct writable_property_accessor_tag {};
struct read_write_property_accessor_tag:
readable_property_accessor_tag,
writable_property_accessor_tag {};
struct lvalue_property_accessor_tag:
read_write_property_accessor_tag {};
template <typename PA>
struct property_traits {
typedef typename PA::value_type value_type;
typedef typename PA::category category;
};
// The property accessor specialization for pointers
template <class T>
struct property_traits<T*> {
typedef T value_type;
typedef lvalue_property_accessor_tag category;
};
template <class T>
void set(T* pa, ptrdiff_t it, const T& val)
{
pa[it] = val;
}
template <class T>
T get(T* pa, ptrdiff_t it)
{
return pa[it];
}
template <class T>
T& at(T* pa, ptrdiff_t it)
{
return pa[it];
}
} /* namespace boost */
#endif /* BOOST_PROPERTY_ACCESSOR_HPP */
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk