Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Message from discussion is_enum<T> ATTN: Andrei Alexandrescu and ilk
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Richard Smith  
View profile  
 More options Mar 19 2002, 4:36 am
Newsgroups: comp.lang.c++.moderated
From: "Richard Smith" <rich...@ex-parrot.com>
Date: 19 Mar 2002 04:37:45 -0500
Local: Tues, Mar 19 2002 4:37 am
Subject: Re: is_enum<T> ATTN: Andrei Alexandrescu and ilk

"Rani Sharoni" <rani_shar...@hotmail.com> wrote in message

news:df893da6.0203170237.3760f3c4@posting.google.com...

> I looked at 14.8.2/2 (indicated by Peter) and wondered if it is
> possible to use Paul technique in order to detect whether some type T
> contains some type member.
> This is known challenge by Andrei Alexandrescu (look for post named
> "Reiterated question").

I wonder whether this might also useful in writting a default_constructible
traits class:

  template <typename T>
  struct default_constructible
  {
  private:
    typedef char (&yes)[1];
    typedef char (&no)[2];

    template <unsigned> struct size_type_wrapper { typedef T type; };

    template <class U> static yes check( typename size_type_wrapper<
sizeof( new T ) >::type * );
    template <class U> static no  check( ... );

  public:
    static const bool result =
      sizeof( check<T>(0) ) == sizeof(yes);
  };

  template <bool Val> struct static_assert;
  template <> struct static_assert<true> {};

  struct A { };
  struct B { B(int) {} };

  int main()
  {
    static_assert<  default_constructible< A >::result >();
    static_assert< !default_constructible< B >::result >();
  }

Comeau 4.3 BETA#2 refuses to compile it saying,

"6478.c", line 10: error: no default constructor exists for class "B"
    template <class U> static yes check( typename size_type_wrapper<
sizeof( new U ) >::type * );

Is this correct?  I would have thought that as new B is illegal, sizeof( new
B ) would be, and so typename size_type_wrapper< sizeof( new T ) >::type
ought to be illegal too.

--
Richard Smith

      [ Send an empty e-mail to c++-h...@netlab.cs.rpi.edu for info ]
      [ about comp.lang.c++.moderated. First time posters: do this! ]


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2010 Google