On Nov 8, 1:16 pm, KaiUwe Bux <(EMail Removed)> wrote:
> abir wrote:
> > Hi,
> > i need to work on a certain types of sequences which has a specific
> > property.
> > some of the properties i can deduce based on a few typenames, but
> > others i can't
>
> > eg i want to know a class which supports insert.
> > so i have
> > template<typename T> struct can_insert : public std::false_type{};
> > and explicitly write
> > template<typename T> struct can_insert<std::vector<T>> : public
> > std::true_type{}; etc
>
> [snip]
>
> Maybe, the following helps. It deals with swap(), but it is straight forward
> to addapt the example to insert().
>
> template < typename T >
> class has_swap {
> /*
> stolen from Rani Sharoni, who attributes this to
> Richard Smith and also Artem Livshits
> */
>
> typedef char (&no) [1];
> typedef char (&yes) [2];
>
> template < typename S, void ( S::* ) ( S & ) >
> struct dummy {};
>
> template < typename S >
> static
> yes check ( dummy< S, &S::swap > * );
>
> template < typename S >
> static
> no check ( ... );
>
> public:
>
> static bool const value = sizeof( check<T>(0) ) == sizeof( yes );
>
> }; // has_swap
>
> Best
>
> KaiUwe Bux
Thanks for reply
It looks cool & I used it successfully for my purpose
However can I use it to detect availability of a particular
constructor in the class.
Something like the one below doesn't work
struct move_ctor{};
template<typename T>
class has_move{
typedef char (&no) [1];
typedef char (&yes) [2];
template<typename S, void ( S::* ) ( S & ,move_ctor)>
struct dummy {};
template<typename S>
static yes check ( dummy< S, &S::S> * );
template < typename S >
static no check ( ... );
public:
const static bool value = sizeof( check<T>(0) ) == sizeof( yes );
};
It complains that i cant take address of the constructor, which is
legitimate.
Any alternative for this?
Thanks again
abir
