KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
A basic C++ 03 enumerated type is just an integral value with a fancy name, therefore I would expect to pass it by value.... For this reason I would also expect boost::call_traits<T>::param_type with T=SomeEnum to determine that the most efficient way of pass T is by value. From boost documentation see Call Traits : Defines a type that represents the "best" way to pass a parameter of type T to a function. When I use boost::call_traits<T>::param_type with T=SomeEnum it determines that SomeEnum should be passed by reference. I would also expect C++11 class enums to also be passed by value. Test Code: #include <string> #include <typeinfo> #include <boost/call_traits.hpp> #include <boost/type_traits/is_reference.hpp> enum SomeEnum { EN1_ZERO = 0, EN1_ONE, EN1_TWO, EN1_THREE }; struct SomeStruct {}; template<typename T> void DisplayCallTraits( const std::string& desc ) { typedef typename boost::call_traits<T>::param_type param_type; std::cout << "-----------------------------------------------------\n"; std::cout << "Call traits for: " << desc << "\n"; std::cout << "\ttypeof T : " << typeid(T).name() << "\n"; std::cout << "\ttypeof param_type : " << typeid(param_type).name() << "\n"; std::cout << "\tis_reference<param_type> : " << std::boolalpha << boost::is_reference<param_type>::value << "\n"; } int main( int, char** ) { DisplayCallTraits< unsigned >( "unsigned" ); // pass by value, as expected DisplayCallTraits< SomeStruct >( "struct" ); // pass by reference, as expected
Tags (comma-separated)
Save Edits
Cancel