Boost logo

Boost Users :

From: Abhishek Padmanabh (abhishek_padmanabh_at_[hidden])
Date: 2008-02-29 10:59:34

I am not sure if it is possible to get the return type of a function so as
to use it as a template type parameter or atleast I don't know how to do
that. So, I have a work-around wherein the ContractType's define typedef's
for the return types of the two functions st1() and st2(). What I have is
something like this:

struct Contract1{
        enum myenum {myenum_1, myenum_2};
        typedef myenum st1_return_type;
        typedef myenum st2_return_type;
        static myenum st1(){return myenum_1;};
        static myenum st2(){return myenum_2;};

struct Contract2{
        typedef int st1_return_type;
        typedef int st2_return_type;
        enum myenum {myenum_1, myenum_2};
        static int st1(){return myenum_1;};
        static int st2(){return myenum_2;};

template <typename ContractType>
class Test {
ContractType::st1_return_type>::value && boost::is_enum<typename
        void otherMembers(){}

int main(){
        Test<Contract1> obj1;
        //uncomment to get the assert
        //Test<Contract2> obj2;

You should get the error even if some ContractType doesn't defined those
typedefs. But the valid classes (for which st1() and st2() don't return
enums) should strictly define them. The above works for me with VC++ 2005.
(include boost/type_traits/is_enum.hpp)

Thanks and regards,
Abhishek Padmanabh

-----Original Message-----
From: boost-users-bounces_at_[hidden]
[mailto:boost-users-bounces_at_[hidden]] On Behalf Of Hicham Mouline
Sent: 29 February 2008 18:54
To: boost-users_at_[hidden]
Subject: [Boost-users] static assert


I would like to avoid template instantiations with ContractType whose static
functions st1 and st2 return an enum...

template <typename ContractType>
class C {
BOOST_STATIC_ASSERT( !(ContractType::st1()==A && ContractType::st2()==P) );

Is there a way to make this work?
Boost-users mailing list

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at