Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > compile time type check

Reply
Thread Tools

compile time type check

 
 
er
Guest
Posts: n/a
 
      01-30-2008
Hi All,

how can i enforce the requirement below ?

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

/* body of the function */
};
 
Reply With Quote
 
 
 
 
Alf P. Steinbach
Guest
Posts: n/a
 
      01-30-2008
* er:
>
> how can i enforce the requirement below ?
>
> template<class RANDOM>//template member function
> double A<RANDOM>: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?
 
Reply With Quote
 
 
 
 
er
Guest
Posts: n/a
 
      01-30-2008
On Jan 29, 10:12 pm, "Alf P. Steinbach" <(E-Mail Removed)> wrote:
> * er:
>
>
>
> > how can i enforce the requirement below ?

>
> > template<class RANDOM>//template member function
> > double A<RANDOM>: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>: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?


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
computation at compile time i.e. compile time functions usingtemplates Carter C++ 2 03-04-2009 06:43 PM
cant compile on linux system.cant compile on cant compile onlinux system. Nagaraj C++ 1 03-01-2007 11:18 AM
Compile time type check in C# n.net ASP .Net 2 01-15-2007 07:39 AM
Compile time check for virtual destructor Kai-Uwe Bux C++ 5 08-16-2004 01:23 PM
Compile-time check of "static interface" Ian Pilcher Java 4 01-28-2004 01:08 AM



Advertisments