|
Boost : |
From: Jonathan Turkanis (technews_at_[hidden])
Date: 2004-01-21 11:14:17
"Bronek Kozicki" <brok_at_[hidden]> wrote in message
news:1x79aw0sah63m.6yyve29a55fz$.dlg_at_40tude.net...
> On Wed, 21 Jan 2004 16:20:36 +0100, Bronek Kozicki wrote:
> > not know how Howard wants to define both classes :/ (call me dumb)
>
> Or maybe don't call me dumb. Quick examination of "The Template
Guide"
> enlightened me.
>
> #include <iostream>
> template <typename T> struct move_ptr
> {
> const char* say() const {return "move_ptr<T>::say\n";};
> static const char* ptr() {return "move_ptr<T>::ptr\n";};
> };
>
> template <typename T> struct move_ptr<T[]>
> {
> const char* say() const {return "move_ptr<T[]>::say\n";};
> static const char* arr() {return "move_ptr<T[]>::arr\n";};
> };
>
I would do something like this
template<typename T>
struct is_incomplete_array { enum { value = false }; };
template<typename T>
struct is_incomplete_array<T[]> { enum { value = true }; };
template<typename T>
struct remove_incomplete_bounds { typedef T type; };
template<typename T>
struct remove_incomplete_bounds<T[]> { typedef T type; };
template<typename T>
struct move_ptr {
typedef remove_incomplete_bounds<T>::type element_type;
element_type& operator[] (size_t or ptrdiff_t?)
{
BOOST_STATIC_ASSERT(is_incomplete_array<T>::value)
}
// Etc.
};
Jonathan
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk