## For instruction on writing tutorials ## http://www.ros.org/wiki/WritingTutorials #################################### ##FILL ME IN #################################### ## for a custom note with links: ## note = ## for the canned note of "This tutorial assumes that you have completed the previous tutorials:" just add the links ## note.0= ## descriptive title for the tutorial ## title = Enable If ## multi-line description to be displayed in search ## description = An if operator for template type arguments. ## the next tutorial description (optional) ## next = ## links to next tutorial (optional) ## next.0.link= ## next.1.link= ## what level user is this tutorial for ## level= IntermediateCategory ## keywords = ecl mpl #################################### <> <> == Usage == These allow you to various compile tricks with SFINAE (Substitution Failure Is Not An Error). One usage case is to eliminate template instantiations for any type you do not wish to explicitly support. {{{ #!cplusplus // This will instantiate if it is anything except float or double. template class TestObject { public: bool isFloatSpecialisation() { return false; } }; // This specialisation will instantiate it T is float or double. template class TestObject< T, typename enable_if< is_float >::type > { public: bool isFloatSpecialisation() { return true; } }; }}} == Reporting Errors at Compile Time == `FailedObject` is a simple class that guarantees a compile time failure if an attempt to instantiate it is made (private constructor). This is useful in tandem with the if function to report bad instantiations. For example, the parent template definition above could be instead: {{{ #!cplusplus #include template class TestObject : public ecl::FailedObject {}; }}} ## AUTOGENERATED DO NOT DELETE ## TutorialCategory ## FILL IN THE STACK TUTORIAL CATEGORY HERE