compile time type check

Discussion in 'C++' started by er, Jan 30, 2008.

  1. er

    er Guest

    Hi All,

    how can i enforce the requirement below ?

    template<class RANDOM>//template member function
    double A<RANDOM>::eek:perator()(RANDOM& u){
    /* requirement: RANDOM::result_type is double */

    /* body of the function */
    };
     
    er, Jan 30, 2008
    #1
    1. Advertising

  2. * er:
    >
    > how can i enforce the requirement below ?
    >
    > template<class RANDOM>//template member function
    > double A<RANDOM>::eek:perator()(RANDOM& u){
    > /* requirement: RANDOM::result_type is double */
    >
    > /* body of the function */
    > };


    The Boost library provides facilities for compile time assertions and
    compile time checking of whether two types are the same. Compile time
    assertions will become part of the language in C++0x, but with slightly
    different syntax than the Boost macro. There is however a good chance
    that it would be better to rethink the design rather than enforce.

    Btw., don't use all uppercase for non-macro names.

    Reserve all uppercase for macro names, to reduce possibility of name
    collisions.


    Cheers, & hth.,

    - Alf


    --
    A: Because it messes up the order in which people normally read text.
    Q: Why is it such a bad thing?
    A: Top-posting.
    Q: What is the most annoying thing on usenet and in e-mail?
     
    Alf P. Steinbach, Jan 30, 2008
    #2
    1. Advertising

  3. er

    er Guest

    On Jan 29, 10:12 pm, "Alf P. Steinbach" <> wrote:
    > * er:
    >
    >
    >
    > > how can i enforce the requirement below ?

    >
    > > template<class RANDOM>//template member function
    > > double A<RANDOM>::eek:perator()(RANDOM& u){
    > > /* requirement: RANDOM::result_type is double */

    >
    > > /* body of the function */
    > > };

    >
    > The Boost library provides facilities for compile time assertions and
    > compile time checking of whether two types are the same. Compile time


    Do you mean BOOST_STATIC_ASSERT? If so, specifically how do I define
    the predicate in my case?

    > assertions will become part of the language in C++0x, but with slightly
    > different syntax than the Boost macro. There is however a good chance
    > that it would be better to rethink the design rather than enforce.


    Basically in my example A<Random>::eek:perator()(Random&) returns a
    random value derived from Random(), that's all. Any suggestion on how
    to rethink the design then?


    >
    > Btw., don't use all uppercase for non-macro names.


    OK

    >
    > Reserve all uppercase for macro names, to reduce possibility of name
    > collisions.
    >
    > Cheers, & hth.,


    Thanks.

    >
    > - Alf
    >
    > --
    > A: Because it messes up the order in which people normally read text.
    > Q: Why is it such a bad thing?
    > A: Top-posting.
    > Q: What is the most annoying thing on usenet and in e-mail?
     
    er, Jan 30, 2008
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ian Pilcher
    Replies:
    4
    Views:
    437
    Ian Pilcher
    Jan 28, 2004
  2. n.net

    Compile time type check in C#

    n.net, Jan 13, 2007, in forum: ASP .Net
    Replies:
    2
    Views:
    2,831
    n.net
    Jan 15, 2007
  3. flamesrock
    Replies:
    8
    Views:
    548
    Hendrik van Rooyen
    Nov 24, 2006
  4. Nagaraj
    Replies:
    1
    Views:
    914
    Lionel B
    Mar 1, 2007
  5. Carter
    Replies:
    2
    Views:
    528
    Carter
    Mar 4, 2009
Loading...

Share This Page