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 {
        BOOST_STATIC_ASSERT(boost::is_enum<typename
ContractType::st1_return_type>::value && boost::is_enum<typename
ContractType::st2_return_type>::value);
        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

hi,

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_at_[hidden]
http://lists.boost.org/mailman/listinfo.cgi/boost-users


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net